-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLegibTestExperiments.py
More file actions
1724 lines (1268 loc) · 68.2 KB
/
LegibTestExperiments.py
File metadata and controls
1724 lines (1268 loc) · 68.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
purpose = "60_nova_yay_defense_rgb_nextbest4_back" #with_boost" #locked_denom" #sig_lite" #_sec" #5t_10s_l10_weighted_both" force_
# purpose = "53_sec_diff"
# purpose = "exp_52_solo_maxp5_2xval" #local_revert" #og_more_dense" #
# purpose = "exp_48_legnew_novisl_raw_wthd_e-4" #_10x"
# purpose = "42_sec_falloff_none_have_2x" #sum_exp_of_lin_sqr" #multi_alts_sum"
# purpose = "pilot_exp_24_pd_lam25_discount5_max2"
# purpose = "test_dist_k"n-t
import os
import sys
import copy
import time
from pathlib import Path
module_path = os.path.abspath(os.path.join('../ilqr'))
if module_path not in sys.path:
sys.path.append(module_path)
import numpy as np
import LegibSolver as solver
import matplotlib.pyplot as plt
from datetime import timedelta, datetime
import pandas as pd
import markupsafe
from random import randint
from matplotlib import colors
import utility_environ_descrip as resto
import PathingExperiment as ex
from LegiblePathQRCost import LegiblePathQRCost
import LegibTestScenarios as test_scenarios
import utility_environ_descrip as resto
import shutil
FLAG_DO_SCENARIO_TESTS = False
test_log = []
np.set_printoptions(suppress=True)
def run_all_tests():
dashboard_folder = get_dashboard_folder()
# SET UP OPTIONS FOR THIS RUN
# MAINLY IS IT'S A FULL RUN OR A QUICK ONE TO VERIFY CODE
scenario_filters = {}
scenario_filters[test_scenarios.SCENARIO_FILTER_MINI] = True
scenario_filters[test_scenarios.SCENARIO_FILTER_FAST_SOLVE] = False
scenario_filters[test_scenarios.DASHBOARD_FOLDER] = dashboard_folder
# test_understanding_set(dashboard_folder, scenario_filters)
# test_locality_set(dashboard_folder, scenario_filters)
test_study_set(dashboard_folder, scenario_filters)
def get_file_id_for_exp(dash_folder, label):
# Create a new folder for this experiment, along with sending debug output there
file_id = label #+ "-" + datetime.now().strftime("%Y_%m_%d-%I_%M_%S_%p")
n = 5
rand_id = ''.join(["{}".format(randint(0, 9)) for num in range(0, n)])
# sys.stdout = open(dash_folder + file_id + "_" + str(rand_id) + '_output.txt','a')
return dash_folder + file_id
def get_dashboard_folder():
# purpose is a note field set at the top of this doc
purpose_fn = purpose.replace(" ", "_")[:30]
dashboard_file_id = datetime.now().strftime("%Y_%m_%d-%I_%M_%S_%p") + "-" + "exp-" + purpose_fn
try:
os.mkdir(Path(LegiblePathQRCost.PREFIX_EXPORT + dashboard_file_id))
with open(Path(LegiblePathQRCost.PREFIX_EXPORT + dashboard_file_id + '/readme.txt'), 'w') as f:
f.write(purpose)
except:
print("FILE ALREADY EXISTS " + file_id)
dash_folder = LegiblePathQRCost.PREFIX_EXPORT + dashboard_file_id + "/"
# sys.stdout = open(dash_folder + '/output.txt','a')
shutil.copy("RelevantPathQRCost.py", dash_folder + "QRCost.py")
shutil.copy("PathingExperiment.py", dash_folder + "PathingEx.py")
return dash_folder
def collate_and_report_on_results(dash_folder):
df_cols = ['scenario', 'goal', 'test', 'condition', 'status_summary', 'converged', 'num_iterations', 'info', 'J_opt']
df = pd.DataFrame(test_log, columns=df_cols)
def _colorize(val):
color = 'white'
color = 'pink' if "INC" in str(val) else color
color = 'lightgreen' if "CONV" in str(val) else color
color = 'lightcyan' if "OK" in str(val) else color
color = 'lightgrey' if "TODO" in str(val) else color
return 'background-color: %s' % color
save_location = dash_folder + "/status_overview" #get_file_id_for_exp(dash_folder, "status_overview.csv")
df.to_csv(save_location + ".csv")
df_shiny = df.style.applymap(_colorize)
df_shiny.to_html(save_location + "-flat.html")
# pandas.pivot(index, columns, values)
df_dashboard = df.pivot_table(index=[df_cols[0], df_cols[1]], columns=[df_cols[2], df_cols[3]], values='status_summary', fill_value="TODO", aggfunc=lambda x: ' '.join(x))
df_dashboard = df_dashboard.style.applymap(_colorize)
save_location = dash_folder + "/dashboard" #get_file_id_for_exp(dash_folder, "status_overview.csv")
df_dashboard.to_html(save_location + ".html") #sparse_index=True, sparse_columns=True
return
save_location = dash_folder + "/dashboard" #get_file_id_for_exp(dash_folder, "status_overview.csv")
df_dashboard.to_html(save_location + ".html") #sparse_index=True, sparse_columns=True
df_dashboard.to_latex(save_location + ".latex") #sparse_index=True, sparse_columns=True
df_dashboard.to_excel(save_location + ".xls", merge_cells=True, engine='openpyxl')
def test_understanding_set(dash_folder, scenario_filters):
scenarios = test_scenarios.get_scenarios(scenario_filters)
test_group = "understanding"
test_setups_og = []
new_test = {'label':"u=gn", 'title':'Understanding Global None', 'und_target': 'global', 'und_secondary': None}
test_setups_og.append(new_test)
new_test = {'label':"u=gg", 'title':'Understanding Global Global', 'und_target': 'global', 'und_secondary': 'global'}
test_setups_og.append(new_test)
new_test = {'label':"u=gl", 'title':'Understanding Global Local', 'und_target': 'global', 'und_secondary': 'local'}
test_setups_og.append(new_test)
new_test = {'label':"u=nn", 'title':'Understanding None None', 'und_target': None, 'und_secondary': None}
test_setups_og.append(new_test)
new_test = {'label':"u=ng", 'title':'Understanding None Global', 'und_target': None, 'und_secondary': 'global'}
test_setups_og.append(new_test)
new_test = {'label':"u=nl", 'title':'Understanding None Local', 'und_target': None, 'und_secondary': 'local'}
test_setups_og.append(new_test)
new_test = {'label':"u=ln", 'title':'Understanding Local None', 'und_target': 'local', 'und_secondary': None}
test_setups_og.append(new_test)
new_test = {'label':"u=lg", 'title':'Understanding Local Global', 'und_target': 'local', 'und_secondary': 'global'}
test_setups_og.append(new_test)
new_test = {'label':"u=ll", 'title':'Understanding Local Local', 'und_target': 'local', 'und_secondary': 'local'}
test_setups_og.append(new_test)
for key in scenarios.keys():
scenario = scenarios[key]
scenario.set_run_filters(scenario_filters)
outputs = {}
label_dict = {}
for ti in range(len(test_setups_og)):
for g_index in range(len(scenario.get_goals())):
test = test_setups_og[ti]
# RUN THE SOLVER WITH CONSTRAINTS ON EACH
n_scenario = copy.copy(scenario)
mega_scenario = copy.copy(scenario)
mega_scenario.set_fn_note(test['label'])
mega_scenario.set_test_options(test)
mega_scenario.set_target_goal_index(g_index)
save_location = get_file_id_for_exp(dash_folder, "und-" + mega_scenario.get_exp_label() + "_g" + str(g_index))
verts_with_n, us_with_n, cost_with_n, info_packet = solver.run_solver(mega_scenario)
outputs[(ti, g_index)] = verts_with_n, us_with_n, cost_with_n, test['label']
test_log.append(mega_scenario.get_solve_quality_status(test_group))
collate_and_report_on_results(dash_folder)
# This placement of the figure statement is actually really important
# numpy only likes to have one plot open at a time,
# so this is a fresh one not dependent on the graphing within the solver for each
# EXPORT PATHS FOR EACH GOAL
print("Exporting paths pic for each goal")
goal_indexes = range(len(mega_scenario.get_goals()))
for gi in goal_indexes:
fig, axes, ax_mappings = setup_axes_for_test_setups(test_setups_og)
# EXPORT GRAPH ACROSS ALL GOALS
for key in outputs.keys():
ax_key, goal_key = key
if goal_key == gi:
ax = ax_mappings[ax_key]
verts, us, cost, label = outputs[key]
cost.get_overview_pic(verts, us, ax=ax, info_packet=info_packet, dash_folder=dash_folder, multilayer_draw=True)
_ = ax.set_title(label, fontweight='bold')
ax.set_aspect('equal')
ax.get_legend().remove()
max_key = key
for ax_index in range(len(test_setups_og), len(ax_mappings)):
ax_mappings[ax_index].axis('off')
mega_scenario.set_target_goal_index(gi)
save_location = get_file_id_for_exp(dash_folder, "cross-" + mega_scenario.get_exp_label() + "_g" + str(gi))
fig.suptitle("=g" + str(gi)) # + " " + mega_scenario.get_goal_label())
plt.subplots_adjust(top=0.9)
# plt.tight_layout()
plt.savefig(Path(save_location + ".png"))
plt.close()
plt.clf()
print("Exporting paths pic for all goals")
fig, axes, ax_mappings = setup_axes_for_test_setups(test_setups_og)
# EXPORT GRAPH ACROSS ALL GOALS
for key in outputs.keys():
ax_key, goal_key = key
ax = ax_mappings[ax_key]
verts, us, cost, label = outputs[key]
cost.get_overview_pic(verts, us, ax=ax, info_packet=info_packet, dash_folder=dash_folder, multilayer_draw=True)
_ = ax.set_title(label, fontweight='bold')
ax.get_legend().remove()
max_key = key
for ax_index in range(len(test_setups_og), len(ax_mappings)):
ax_mappings[ax_index].axis('off')
save_location = get_file_id_for_exp(dash_folder, "cross-" + "-" + mega_scenario.get_exp_label() + "-all")
save_location = get_file_id_for_exp(dash_folder, "all-cross-" + "-" + mega_scenario.get_exp_label() + "-all")
fig.suptitle("cross=all") # + " " + mega_scenario.get_goal_label())
plt.subplots_adjust(top=0.9)
# plt.tight_layout()
plt.savefig(Path(save_location + ".png"))
plt.close()
plt.clf()
def do_scenario_tests(scenario):
# goals at x_input = [-3.0, 0.0]
# x_input = [3.0, 0.0]
x_input = [91.0, 10.0]
print(x_input)
print(scenario.get_vislocal_status_of_point(x_input))
print(x_input)
print("QUE SERA")
print()
x_input = [101, 10.0]
print(x_input)
print(scenario.get_vislocal_status_of_point(x_input))
print(x_input)
print("QUE SERA")
print()
x_input = [110.0, 10.0]
print(x_input)
print(scenario.get_vislocal_status_of_point(x_input))
print(x_input)
print("QUE SERA")
print()
x_input = [91.0, 5.0]
print(x_input)
print(scenario.get_vislocal_status_of_point(x_input))
print(x_input)
print("QUE SERA")
print()
if False:
x_input = [-3.0, 0.0]
print(x_input)
print(scenario.get_vislocal_status_of_point(x_input))
print(x_input)
print("QUE SERA")
print()
x_input = [3.0, 0.0]
print(x_input)
print(scenario.get_vislocal_status_of_point(x_input))
print(x_input)
print("QUE SERA")
print()
x_input = [-2.5, 0.0]
print(x_input)
print(scenario.get_vislocal_status_of_point(x_input))
print(x_input)
print("QUE SERA")
print()
x_input = [2.5, 0.0]
print(x_input)
print(scenario.get_vislocal_status_of_point(x_input))
print(x_input)
print("QUE SERA")
print()
x_input = [-3, 1.0]
print(x_input)
print(scenario.get_vislocal_status_of_point(x_input))
print(x_input)
print("QUE SERA")
print()
x_input = [3, 1.0]
print(x_input)
print(scenario.get_vislocal_status_of_point(x_input))
print(x_input)
print("QUE SERA")
print()
x_input = [-4.5, 0.0]
print(x_input)
print(scenario.get_vislocal_status_of_point(x_input))
print(x_input)
print("QUE SERA")
print()
x_input = [4.5, 0.0]
print(x_input)
print(scenario.get_vislocal_status_of_point(x_input))
print(x_input)
print("QUE SERA")
print()
print("~~~~~")
# exit()
def test_study_set(dash_folder, scenario_filters):
scenarios = test_scenarios.get_scenarios(scenario_filters)
test_group = "study"
test_template = {'label':"", 'title':'', 'und_target': '', 'und_secondary': ''}
# scale_set = [.5, 0.625, .75, 0.875, 1, 1.125, 1.25, 1.375, 1.5]
scale_set = [1, 2, 4, 8, 16, 32, 64, 128][::-1]
# scale_set = [1, 3/2.0, 3/1.0][::-1]
scale_set = [14.0/3, 14.0/2.0, 14.0/1.0][::-1]
# scale_set = [1, 5/4.0, 5/3.0, 5/2.0, 5.0][::-1]
# scale_set = [1, 5/4.0, 5/2.0][::-1]
scale_set = [1]
# scale_exp = [8, 4, 2, 0]
# observer_gap = 1 #1.5
# scale_exp = [2, 1, .5, 0][::-1]
# scale_exp = [4, 2, 1] #[::-1]
# scale_exp = [.5, 1.5, 10][::-1]
# Tuples contain local_dist, secondary_dist
# scale_exp = [(10, 0), (10, .5), (10, .25)]
# scale_exp = [(1.5, 0), (1.5, .5), (1.5, .25)]
scale_exp = [10, 1.5, .75]
target_buffer_dist = [0, 0, 0]
lam_values = [8.0, 8.0, 8.0]
num_itr_list = [5, 5, 5] # [1, 1, 1]
scale_exp = [10, 10, 10]
target_buffer_dist = [0, .5, 1.0]
lam_values = [8.0, 8.0, 8.0]
num_itr_list = [5, 5, 5] # [1, 1, 1]
scale_exp = [10, 1.5, .75, 10, 10, 10]
target_buffer_dist = [0, 0, 0, 0, .5, 1.0]
lam_values = [5.0, 5.0, 5.0, 5.0, 5.0, 5.0]
num_itr_list = [50, 50, 50, 50, 50, 50] # [1, 1, 1]
scale_exp = [.25, .5, .75, .25, .5, .75]
target_buffer_dist = [0, 0, 0, 0, .5, 1.0]
lam_values = [5.0, 5.0, 5.0, 5.0, 5.0, 5.0]
num_itr_list = [50, 50, 50, 50, 50, 50] # [1, 1, 1]
# scale_exp = [-.5, .5, 0, -.5, .5, 0] #[-.5, .5, 0, -.5, .5, 0]
# target_buffer_dist = [0, 0, 0, .25, .25, .25] #[.5, .5, .5, .95, .95, .95] #, .5, 1.0]
# lam_values = [lam, lam, lam, lam, lam, lam] #, lam, lam, lam, lam, lam, lam] #, 5.0, 5.0]
# num_itr_list = [numit, numit, numit, numit, numit, numit] #, numit, numit, numit, numit, numit, numit] #[25, 25, 25, 25, 25, 25] # [1, 1, 1]
# scale_exp = [-.4, .4, 0, -.4, .4, 0] #[-.5, .5, 0, -.5, .5, 0]
# target_buffer_dist = [0, 0, 0, .25, .25, .25] #[.5, .5, .5, .95, .95, .95] #, .5, 1.0]
# lam_values = [lam, lam, lam, lam, lam, lam] #, lam, lam, lam, lam, lam, lam] #, 5.0, 5.0]
# num_itr_list = [numit, numit, numit, numit, numit, numit] #, numit, numit, numit, numit, numit, numit] #[25, 25, 25, 25, 25, 25] # [1, 1, 1]
lam = 1.5
numit = 50
scale_exp = [-.5, .5, 0]
target_buffer_dist = [0, 0, 0]
lam_values = [lam, lam, lam]
num_itr_list = [numit, numit, numit] # [1, 1, 1]
scale_exp = [-.95, .95, .90, -.90]
target_buffer_dist = [0, 0, 0, 0]
lam_values = [lam, lam, lam, lam]
num_itr_list = [numit, numit, numit, numit] # [1, 1, 1]
# scale_exp = [0]
# target_buffer_dist = [0]
# lam_values = [lam]
# num_itr_list = [numit] # [1, 1, 1]
scale_exp = [-.6, .6, .75, -.75, .85, -.85]
# target_buffer_dist = [0, .5, 0, .5, 0, 0.5]
# target_buffer_dist = [.5, 0, .5, 0, .5, 0]
target_buffer_dist = [0, 0, 0, 0, 0, 0]
lam_values = [lam, lam, lam, lam, lam, lam]
num_itr_list = [numit, numit, numit, numit, numit, numit] # [1, 1, 1]
# scale_exp = [-.6, .6, .75, -.75, .85, -.85]
# target_buffer_dist = [.75, 1.0, .75, 1.0, .75, 1.0]
lam = 1.3 #.75
numit = 100
obs_size = 0 #.5 #.95 #.5
scale_exp = [.6, -.6, .65, -.65, .7, -.7]
scale_exp = [.75, -.75, .8, -.8, .85, -.85]
scale_exp = [.55, -.55, .9, -.9, .95, -.95]
# scale_exp = [.85, .9, .95, .5, -.5, -.6]
scale_exp = [-.8, -.85, -.75, -.7, -.65, -.6]
# scale_exp = [.55, .6, .65, .7, .75, .8]
# lam = 1.3 #.75
# numit = 100
# obs_size = 0 #.5 #.95 #.5
# scale_exp = [-.66, .66, 0]
# target_buffer_dist = [obs_size, obs_size, obs_size]
# lam_values = [lam, lam, lam]
# num_itr_list = [numit, numit, numit] # [1, 1, 1]
# scale_exp = [0, 0, 0, 0, 0, 0]
# lam_values = [1.1, 1.2, 1.3, 1.4, 1.5, 1.6]
# lam_values = [.1, .2, .3, .4, .5, .6]
# lam_values = [.7, .8, .9, 1., 1.7, 1.8]
# Ic_ -0.8_s0.5_Im1.3
# target_buffer_dist = [obs_size, obs_size, obs_size, obs_size, obs_size, obs_size]
# lam_values = [lam, lam, lam, lam, lam, lam]
# num_itr_list = [numit, numit, numit, numit, numit, numit] # [1, 1, 1]
# scale_exp = [-.6, .6, .75, -.75, .85, -.85]
# scale_exp = [-.85, .85, .75, -.75, .6, -.6]
# locality = -.2
# scale_exp = [locality, locality, locality]
# target_buffer_dist = [0, .5, .95]
# lam_values = [lam, lam, lam]
# num_itr_list = [numit, numit, numit] # [1, 1, 1]
# scale_exp = [.25, .5, .75, 1, -.25, -.5, -.75, -1]
# target_buffer_dist = [0, 0, 0, 0, 0, 0, 0, 0]
# lam_values = [lam, lam, lam, lam, lam, lam, lam, lam]
# num_itr_list = [numit, numit, numit, numit, numit, numit, numit, numit] # [1, 1, 1]
# scale_exp = [-.25, -.5, -.75, -1]
# target_buffer_dist = [0, 0, 0, 0]
# lam_values = [2.0, 2.0, 2.0, 2.0]
# num_itr_list = [10, 10, 10, 10] # [1, 1, 1]
# scale_exp = [.25, .5, .75, 1]
# target_buffer_dist = [0, 0, 0, 0]
# lam_values = [1.0, 1.0, 1.0, 1.0]
# num_itr_list = [10, 10, 10, 10] # [1, 1, 1]
# scale_exp = [-.5, .5, 0, -.5, .5, 0]
# target_buffer_dist = [0, 0, 0, .9, .9, .9]
# lam_values = [3.0, 3.0, 3.0, 3.0, 3.0, 3.0]
# num_itr_list = [15, 15, 15, 15] # [1, 1, 1]
# neatvars
# scale_exp = [10.0, 10.0, 10.0]
# target_buffer_dist = [0, .5, 1.0]
# lam_values = [5.0, 5.0, 5.0]
# num_itr_list = [15, 15, 15] # [1, 1, 1]
# study_vars
lam = .75 #.75s
numit = 5
obs_size = 0 #0.5 #0.75 #75 #5 #75 #.75 #0.5 #1.0 #.5 #.5 #.95 #.5
# scale_exp = [-.66, .66, 0]
# # scale_exp = [-.75, .75, 0]
# # scale_exp = [-.8, .8, 0]
# target_buffer_dist = [obs_size, obs_size, obs_size]
# lam_values = [lam, lam, lam]
# num_itr_list = [numit, numit, numit] # [1, 1, 1]
# scale_exp = [-.66, .66]
# scale_exp = [-.85, .85]
# scale_exp = [-.75, .75, 0]
# scale_exp = [-.8, .8, 0]
scale_exp = [0]
target_buffer_dist = [obs_size]
lam_values = [lam]
num_itr_list = [numit] # [1, 1, 1]
# scale_exp = [0, 0, 0]
# # scale_exp = [-.75, .75, 0]
# # scale_exp = [-.8, .8, 0]
# target_buffer_dist = [obs_size, obs_size, obs_size]
# lam_values = [lam, lam + .1, lam + .1]
# num_itr_list = [numit, numit, numit] # [1, 1, 1]
setups = []
for ind in range(len(scale_exp)):
setup = (scale_exp[ind], target_buffer_dist[ind], lam_values[ind], num_itr_list[ind])
setups.append(setup)
# setups.append((10, 0, 30.0, 2))
# observer_gap = 2.0
for key in scenarios.keys():
scenario = scenarios[key]
scenario.set_run_filters(scenario_filters)
longest_distance = scenario.get_max_dist()
# if label == 'diam':
# longest_distance = longest_distance / 1.5
outputs = {}
label_dict = {}
test_setups = []
for setup_index in range(len(setups)):
test = copy.copy(test_template)
# print("Radius math")
# print(longest_distance)
# print((longest_distance / multiplier))
# print((longest_distance / multiplier) + observer_gap)
# new_N = (longest_distance / multiplier) + observer_gap
# n_percent = int(100.0 * multiplier)
# new_N = str("{0:.3g}".format((new_N)))
# new_N = float(new_N)
# scale_text = str("{0:.3g}".format((1.0 / multiplier)))
local_def = setups[setup_index][0]
keepout_dist = setups[setup_index][1]
lam = setups[setup_index][2]
num_itr = setups[setup_index][3]
# label_dict[multiplier] = local_def
test['label'] = "lc_" + str(local_def) + "_s" + str(keepout_dist) + "_lm" + str(lam)
test['local_distance'] = local_def
test_setups.append(test)
for g_index in range(len(scenario.get_goals())):
# RUN THE SOLVER WITH CONSTRAINTS ON EACH
mega_scenario = copy.copy(scenario)
# mega_scenario.set_fn_note(test['label'])
mega_scenario.set_test_options(test)
mega_scenario.set_target_goal_index(g_index)
mega_scenario.set_local_distance(local_def)
mega_scenario.set_goal_keepout_distance(keepout_dist)
mega_scenario.set_lambda(lam)
mega_scenario.set_num_iterations(num_itr)
tag = "lc_" + str(local_def) + "_s" + str(keepout_dist) + "_lm" + str(lam)
mega_scenario.set_fn_note(tag)
goal_name = mega_scenario.get_pretty_study_label(g_index, scenario.get_goals()[g_index])
save_location = get_file_id_for_exp(dash_folder, "dist-" + mega_scenario.get_exp_label() + "_" + goal_name)
if FLAG_DO_SCENARIO_TESTS:
do_scenario_tests(mega_scenario)
verts_with_n, us_with_n, cost_with_n, info_packet = solver.run_solver(mega_scenario)
# scale_exp[ind], target_buffer_dist[ind], lam_values[ind], num_itr_list[ind]
outputs[(local_def, keepout_dist, lam, num_itr), g_index] = verts_with_n, us_with_n, cost_with_n, test['label']
test_log.append(mega_scenario.get_solve_quality_status(test_group))
collate_and_report_on_results(dash_folder)
# This placement of the figure statement is actually really important
# numpy only likes to have one plot open at a time,
# so this is a fresh one not dependent on the graphing within the solver for each
# EXPORT PATHS FOR EACH GOAL
print("Exporting paths pic for each goal")
goal_indexes = range(len(mega_scenario.get_goals()))
for gi in goal_indexes:
fig, axes, ax_mappings = setup_axes_for_test_setups(test_setups)
ax_key = -1
# EXPORT GRAPH ACROSS ALL GOALS
for key in outputs.keys():
ax_tuple, goal_key = key
for si in range(len(setups)):
print(si)
print(setups[si])
setup = setups[si]
if setup[0] == ax_tuple[0] and setup[1] == ax_tuple[1] and setup[2] == ax_tuple[2] and setup[3] == ax_tuple[3]:
ax_key = si
else:
print(setups[si], ax_tuple)
if goal_key == gi:
ax = ax_mappings[ax_key]
verts, us, cost, label = outputs[key]
cost.get_overview_pic(verts, us, ax=ax, info_packet=info_packet, dash_folder=dash_folder, multilayer_draw=True)
_ = ax.set_title(label, fontweight='bold')
ax.set_aspect('equal')
ax.legend()
ax.get_legend().remove()
max_key = key
for ax_index in range(len(test_setups), len(ax_mappings)):
ax_mappings[ax_index].axis('off')
mega_scenario.set_target_goal_index(gi)
goal_name = mega_scenario.get_pretty_study_label(gi, scenario.get_goals()[g_index])
save_location = get_file_id_for_exp(dash_folder, "dist-" + mega_scenario.get_exp_label() + "_" + goal_name)
fig.suptitle("=g" + str(goal_name)) # + " " + mega_scenario.get_goal_label())
plt.subplots_adjust(top=0.9)
# plt.tight_layout()
plt.savefig(Path(save_location + ".png"))
plt.close()
plt.clf()
print("Exporting paths pic for all goals")
fig, axes, ax_mappings = setup_axes_for_test_setups(test_setups)
# EXPORT GRAPH ACROSS ALL GOALS
for key in outputs.keys():
ax_tuple, goal_key = key
for si in range(len(setups)):
print(si)
print(setups[si])
if setups[si] == ax_tuple:
ax_key = si
else:
print(setups[si], ax_tuple)
ax = ax_mappings[ax_key]
verts, us, cost, label = outputs[key]
cost.get_overview_pic(verts, us, ax=ax, info_packet=info_packet, dash_folder=dash_folder, multilayer_draw=True)
_ = ax.set_title(label, fontweight='bold')
ax.set_xlim([-.05, 6.05])
ax.set_ylim([-4, 0])
ax.legend()
ax.get_legend().remove()
max_key = key
for ax_index in range(len(test_setups), len(ax_mappings)):
ax_mappings[ax_index].axis('off')
save_location = get_file_id_for_exp(dash_folder, "cross-" + "-" + mega_scenario.get_exp_label() + "-all")
save_location = get_file_id_for_exp(dash_folder, "all-cross-" + "-" + mega_scenario.get_exp_label() + "-all-l" + str(mega_scenario.get_lambda()))
fig.suptitle("cross=all") # + " " + mega_scenario.get_goal_label())
plt.subplots_adjust(top=0.9)
# plt.tight_layout()
plt.savefig(Path(save_location + ".png"))
plt.close()
plt.clf()
def test_locality_set(dash_folder, scenario_filters):
scenarios = test_scenarios.get_scenarios(scenario_filters)
test_group = "locality"
test_template = {'label':"ll-", 'title':'Understanding Local Local', 'und_target': 'local', 'und_secondary': 'local'}
# scale_set = [.5, 0.625, .75, 0.875, 1, 1.125, 1.25, 1.375, 1.5]
scale_set = [1, 2, 4, 8, 16, 32, 64, 128][::-1]
# scale_set = [1, 3/2.0, 3/1.0][::-1]
scale_set = [14.0/3, 14.0/2.0, 14.0/1.0][::-1]
# scale_set = [1, 5/4.0, 5/3.0, 5/2.0, 5.0][::-1]
# scale_set = [1, 5/4.0, 5/2.0][::-1]
observer_gap = 2 #1.5
# observer_gap = 2.0
for key in scenarios.keys():
scenario = scenarios[key]
scenario.set_run_filters(scenario_filters)
longest_distance = scenario.get_max_dist()
# if label == 'diam':
# longest_distance = longest_distance / 1.5
outputs = {}
label_dict = {}
test_setups = []
for multiplier in scale_set:
test = copy.copy(test_template)
print("Radius math")
print(longest_distance)
print((longest_distance / multiplier))
print((longest_distance / multiplier) + observer_gap)
new_N = (longest_distance / multiplier) + observer_gap
n_percent = int(100.0 * multiplier)
new_N = str("{0:.3g}".format((new_N)))
new_N = float(new_N)
scale_text = str("{0:.3g}".format((1.0 / multiplier)))
label_dict[multiplier] = scale_text
test['label'] = 'local=' + str("{0:.3g}".format((new_N)))
test['local_distance'] = new_N
test_setups.append(test)
for g_index in range(len(scenario.get_goals())):
# RUN THE SOLVER WITH CONSTRAINTS ON EACH
mega_scenario = copy.copy(scenario)
# mega_scenario.set_fn_note(test['label'])
mega_scenario.set_test_options(test)
mega_scenario.set_target_goal_index(g_index)
mega_scenario.set_local_distance(new_N)
mega_scenario.set_fn_note("locdist_" + str((scale_text)))
save_location = get_file_id_for_exp(dash_folder, "dist-" + mega_scenario.get_exp_label() + "_g" + str(g_index))
do_scenario_tests(mega_scenario)
verts_with_n, us_with_n, cost_with_n, info_packet = solver.run_solver(mega_scenario)
outputs[(multiplier, g_index)] = verts_with_n, us_with_n, cost_with_n, test['label']
test_log.append(mega_scenario.get_solve_quality_status(test_group))
collate_and_report_on_results(dash_folder)
# This placement of the figure statement is actually really important
# numpy only likes to have one plot open at a time,
# so this is a fresh one not dependent on the graphing within the solver for each
# EXPORT PATHS FOR EACH GOAL
print("Exporting paths pic for each goal")
goal_indexes = range(len(mega_scenario.get_goals()))
for gi in goal_indexes:
fig, axes, ax_mappings = setup_axes_for_test_setups(test_setups)
# EXPORT GRAPH ACROSS ALL GOALS
for key in outputs.keys():
ax_number, goal_key = key
ax_key = scale_set.index(ax_number)
if goal_key == gi:
ax = ax_mappings[ax_key]
verts, us, cost, label = outputs[key]
cost.get_overview_pic(verts, us, ax=ax, info_packet=info_packet, dash_folder=dash_folder, multilayer_draw=True)
_ = ax.set_title(label, fontweight='bold')
ax.set_aspect('equal')
ax.get_legend().remove()
max_key = key
for ax_index in range(len(test_setups), len(ax_mappings)):
ax_mappings[ax_index].axis('off')
mega_scenario.set_target_goal_index(gi)
save_location = get_file_id_for_exp(dash_folder, "cross-" + mega_scenario.get_exp_label() + "_g" + str(gi))
fig.suptitle("=g" + str(gi)) # + " " + mega_scenario.get_goal_label())
plt.subplots_adjust(top=0.9)
# plt.tight_layout()
plt.savefig(Path(save_location + ".png"))
plt.close()
plt.clf()
print("Exporting paths pic for all goals")
fig, axes, ax_mappings = setup_axes_for_test_setups(test_setups)
# EXPORT GRAPH ACROSS ALL GOALS
for key in outputs.keys():
ax_number, goal_key = key
ax_key = scale_set.index(ax_number)
ax = ax_mappings[ax_key]
verts, us, cost, label = outputs[key]
cost.get_overview_pic(verts, us, ax=ax, info_packet=info_packet, dash_folder=dash_folder, multilayer_draw=True)
_ = ax.set_title(label, fontweight='bold')
ax.get_legend().remove()
max_key = key
for ax_index in range(len(test_setups), len(ax_mappings)):
ax_mappings[ax_index].axis('off')
save_location = get_file_id_for_exp(dash_folder, "cross-" + "-" + mega_scenario.get_exp_label() + "-all")
save_location = get_file_id_for_exp(dash_folder, "all-cross-" + "-" + mega_scenario.get_exp_label() + "-all")
fig.suptitle("cross=all") # + " " + mega_scenario.get_goal_label())
plt.subplots_adjust(top=0.9)
# plt.tight_layout()
plt.savefig(Path(save_location + ".png"))
plt.close()
plt.clf()
def test_raw_set(dash_folder, scenario_filters):
scenarios = test_scenarios.get_scenarios(scenario_filters)
test_group = "raw-options"
test_setups_og = []
# new_test = {'label':"und_all", 'title':'Understanding full path', 'mode_heading':None, 'mode_dist':None, 'mode_blend': None}
# test_setups_og.append(new_test)
# new_test = {'label':"und_handoff", 'title':'Understanding handoff', 'mode_heading':None, 'mode_dist':None, 'mode_blend': None}
# test_setups_og.append(new_test)
# new_test = {'label':"und_no_confuse", 'title':'Understanding No Confusion', 'mode_heading':None, 'mode_dist':None, 'mode_blend': None}
# test_setups_og.append(new_test)
new_test = {'label':"head_lin", 'title':'Pure linear heading', 'mode_heading':'lin', 'mode_dist':None, 'mode_blend': None}
test_setups_og.append(new_test)
new_test = {'label':"dist_lin", 'title':'Pure linear distance', 'mode_heading':None, 'mode_dist':'lin', 'mode_blend': None}
test_setups_og.append(new_test)
new_test = {'label':"dist_exp", 'title':'Pure OG', 'mode_heading':None, 'mode_dist':'exp', 'mode_blend': None}
test_setups_og.append(new_test)
for key in scenarios.keys():
scenario = scenarios[key]
scenario.set_run_filters(scenario_filters)
outputs = {}
label_dict = {}
for ti in range(len(test_setups_og)):
for g_index in range(len(scenario.get_goals())):
test = test_setups_og[ti]
# RUN THE SOLVER WITH CONSTRAINTS ON EACH
n_scenario = copy.copy(scenario)
mega_scenario = copy.copy(scenario)
mega_scenario.set_fn_note(test['label'])
mega_scenario.set_test_options(test)
mega_scenario.set_target_goal_index(g_index)
save_location = get_file_id_for_exp(dash_folder, "und-" + mega_scenario.get_exp_label() + "_g" + str(g_index))
verts_with_n, us_with_n, cost_with_n, info_packet = solver.run_solver(mega_scenario)
outputs[(ti, g_index)] = verts_with_n, us_with_n, cost_with_n, test['label']
test_log.append(mega_scenario.get_solve_quality_status(test_group))
collate_and_report_on_results(dash_folder)
# This placement of the figure statement is actually really important
# numpy only likes to have one plot open at a time,
# so this is a fresh one not dependent on the graphing within the solver for each
# EXPORT PATHS FOR EACH GOAL
print("Exporting paths pic for each goal")
goal_indexes = range(len(mega_scenario.get_goals()))
for gi in goal_indexes:
fig, axes, ax_mappings = setup_axes_for_test_setups(test_setups_og)
# EXPORT GRAPH ACROSS ALL GOALS
for key in outputs.keys():
ax_key, goal_key = key
if goal_key == gi:
ax = ax_mappings[ax_key]
verts, us, cost, label = outputs[key]
cost.get_overview_pic(verts, us, ax=ax, info_packet=info_packet, dash_folder=dash_folder, multilayer_draw=True)
_ = ax.set_title(label, fontweight='bold')
ax.set_aspect('equal')
ax.get_legend().remove()
max_key = key
for ax_index in range(len(test_setups_og), len(ax_mappings)):
ax_mappings[ax_index].axis('off')
mega_scenario.set_target_goal_index(gi)
save_location = get_file_id_for_exp(dash_folder, "cross-" + mega_scenario.get_exp_label() + "_g" + str(gi))
fig.suptitle("cross=g" + str(gi)) # + " " + mega_scenario.get_goal_label())
plt.subplots_adjust(top=0.9)
# plt.tight_layout()
plt.savefig(Path(save_location + ".png"))
plt.close()
plt.clf()
print("Exporting paths pic for all goals")
fig, axes, ax_mappings = setup_axes_for_test_setups(test_setups_og)
# EXPORT GRAPH ACROSS ALL GOALS
for key in outputs.keys():
ax_key, goal_key = key
ax = ax_mappings[ax_key]
verts, us, cost, label = outputs[key]
cost.get_overview_pic(verts, us, ax=ax, info_packet=info_packet, dash_folder=dash_folder, multilayer_draw=True)
_ = ax.set_title(label, fontweight='bold')
ax.get_legend().remove()
max_key = key
for ax_index in range(len(test_setups_og), len(ax_mappings)):
ax_mappings[ax_index].axis('off')
save_location = get_file_id_for_exp(dash_folder, "cross-" + "-" + mega_scenario.get_exp_label() + "-all")
save_location = get_file_id_for_exp(dash_folder, "all-cross-" + "-" + mega_scenario.get_exp_label() + "-all")
fig.suptitle("cross=all") # + " " + mega_scenario.get_goal_label())
plt.subplots_adjust(top=0.9)
# plt.tight_layout()
plt.savefig(Path(save_location + ".png"))
plt.close()
plt.clf()
def test_full_set(dash_folder, scenario_filters):
scenarios = test_scenarios.get_scenarios(scenario_filters)
test_group = "all-cross"
test_setups_og = []
# new_test = {'label':"no-legib", 'title':'No Legibility, just direct', 'mode_heading':None, 'mode_dist':None, 'mode_blend': None}
# test_setups_og.append(new_test)
# new_test = {'label':"head_lin", 'title':'Pure linear heading', 'mode_heading':'lin', 'mode_dist':None, 'mode_blend': None}
# test_setups_og.append(new_test)
# new_test = {'label':"head_sqr", 'title':'Pure squared heading', 'mode_heading':'sqr', 'mode_dist':None, 'mode_blend': None}
# test_setups_og.append(new_test)
new_test = {'label':"dist_lin", 'title':'Dist linear heading', 'mode_heading':None, 'mode_dist':'lin', 'mode_blend': None}
test_setups_og.append(new_test)
new_test = {'label':"dist_sqr", 'title':'Dist square heading', 'mode_heading':None, 'mode_dist':'sqr', 'mode_blend': None}
test_setups_og.append(new_test)
new_test = {'label':"dist_exp", 'title':'Pure OG', 'mode_heading':None, 'mode_dist':'exp', 'mode_blend': None}
test_setups_og.append(new_test)
# new_test = {'label':"head_exp", 'title':'Pure exp heading', 'mode_heading':'exp', 'mode_dist':None, 'mode_blend': None}
# test_setups_og.append(new_test)
# new_test = {'label':"dist_sqr", 'title':'Dist square heading', 'mode_heading':None, 'mode_dist':'sqr', 'mode_blend': None}
# test_setups_og.append(new_test)
# new_test = {'label':"dist_lin", 'title':'Dist linear heading', 'mode_heading':None, 'mode_dist':'lin', 'mode_blend': None}
# test_setups_og.append(new_test)
# new_test = {'label':"mixed_sqr", 'title':'Mixed Dist / sqr heading', 'mode_heading':'sqr', 'mode_dist':'sqr', 'mode_blend': 'min'}