-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
2075 lines (1812 loc) · 82.4 KB
/
index.html
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
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Visualizing the Evolution of Multi-agent Game-playing Behaviors</title>
<link rel="stylesheet" type="text/css" href="lib/tooltipster.bundle.css" />
<script src="lib/d3.min.js"></script>
<script src="lib/jquery.min.js"></script>
<!-- <script type="text/javascript" src="jquery-ui.js"></script> -->
<script type="text/javascript" src="lib/tooltipster.bundle.js"></script>
<script type="text/javascript" src="lib/parcoords.js"></script>
<script type="text/javascript" src="data.js"></script>
<link rel="stylesheet" href="lib/parcoords.css" type='text/css' media='all'>
<!-- <link rel="stylesheet" href="jquery-ui.css" type='text/css' media='all'> -->
<link rel="stylesheet" href="lib/tooltipster-sideTip-shadow.min.css" type='text/css' media='all'>
<style>
body
{
background-color: rgb(0, 0, 0);
font-family: system-ui;
position: fixed;
width: 100%;
left: 0%;
top: 0%;
background-color: white;
margin: 0px;
}
.axislabel
{
text-anchor: middle;
}
.trainingEpochLabel{
text-anchor: end;
}
.scatterplotCircle
{
opacity:0.5;
}
.grid-container {
display: grid;
/* padding: 25px; */
grid-template-rows: 20fr 80fr;
grid-template-columns: 50fr 50fr;
grid-gap: 5px;
height: 100vh;
background-color: #e8e8e8;
padding: 10px;
}
.splomaxislabel
{
text-anchor: end;
}
.scatterPlotRect
{
cursor:pointer;
}
.grid-container2 {
display: grid;
grid-template-columns: auto auto;
grid-gap: 10px;
height: 100vh;
background-color: #e8e8e8;
/* padding: 10px; */
}
.grid-container3 {
display: grid;
grid-template-columns: 25fr 25fr 25fr 25fr ;
grid-template-rows: auto auto auto auto ;
/* grid-gap: 0px; */
/* height: 100vh; */
background-color: white;
}
.grid-container4 {
display:grid;
grid-template-columns: auto;
grid-template-rows: auto auto auto ;
}
.smalllinechartDivs
{
float: left;
margin: 5px;
margin-top:10px;
padding: 2px;
display: grid;
text-align: center;
cursor: pointer;
}
.highlighted{
border: 2px solid black;
}
.dehighlightCircle{
fill: grey;
}
.parcoords{
height: 100%;
/* width: 100vw; */
grid-column: 1 / span 2;
}
.teamA {
color: tomato;
font-weight:700;
}
.teamAA{
color: tomato;
font-weight:700;
}
.teamB {
color: steelblue;
font-weight:700;
}
.teamBB{
color: steelblue;
font-weight:700;
}
.linechart{
opacity: 0.9;
stroke-opacity: 0.9;
fill-opacity: 0.9;
}
.dynamicText{
font-weight:700;
}
.computedText{
font-style:italic;
}
#div1{
padding-left: 10px;
padding-right: 10px;
}
/* Use this next selector to style things like font-size and line-height: */
.my-custom-theme .tooltipster-content {
font-family: Arial, sans-serif;
/* font-size: 14px; */
line-height: 24px;
padding: 8px 10px;
}
.tooltip-image-theme .tooltipster-content{
/* height: 300px; */
/* width: 250px; */
/* font-size: 14px; */
display: flex;
}
.tooltip_templates
{
display:none;
}
.infoIcon{
cursor:pointer;
}
#scatterPlotDiv{
overflow-y: scroll;
}
</style>
</head>
<body>
<div class="tooltip_templates">
<div id="pommermanDetails">
A bomb laying game played by two teams of two agents each.
<br/>
<br/>
<img height="200px" src="pommerman.gif" />
</div>
</div>
<h3 style="text-align: center; margin: auto">Visualizing the Evolution of Multi-agent Game-playing Behaviors</h3>
<p style="text-align: center; margin: auto">Training <span class="teamA">Skynet955</span> <span id="NNInfo">ⓘ</span> team (two agents) to play against <span class="teamB">Hakozaki Junctions</span> <span id="hakozakiInfo">ⓘ</span> (fully trained) in the <a href="https://www.pommerman.com/" target="_blank">Pommerman</a> Game Environment <span id="pommermanInfo" class="" data-tooltip-content="#pommermanDetails">ⓘ</span></p>
<!-- Use subtitle -->
<div class="grid-container">
<!-- <div> -->
<div id="parallelplot" class="parcoords" ></div>
<!-- </div> -->
<!-- <div class="grid-container2"> -->
<div >
<div class="grid-container4" id="lineCharts" >
<div id="lineChartSmallDiv" class="grid-container3">
</div>
<svg id="svg1">
<g id="bigLineChartGroup">
</g>
</svg>
<div id="div1"></div>
</div>
</div>
<div id="scatterPlotDiv">
<svg id="svg2" >
<g id="bigscatterplotGroup">
</g>
</svg>
</div>
<!-- </div> -->
</div>
<script>
let cycle_results=[
cycle_01.results["1hakozaki"],cycle_02.results["1hakozaki"],
cycle_03.results["1hakozaki"],cycle_04.results["1hakozaki"],
cycle_05.results["1hakozaki"],cycle_06.results["1hakozaki"],
cycle_07.results["1hakozaki"],cycle_08.results["1hakozaki"],
cycle_09.results["1hakozaki"],cycle_10.results["1hakozaki"],
cycle_11.results["1hakozaki"],cycle_12.results["1hakozaki"]
];
// console.log("cycle_results: ",cycle_results);
// ########## ANALYSIS ##########
// Create array of label names
let labelNames=[];
let labelid_NameDictionary = {
"Epochs": "Epochs",
"win": "Wins",
"loss": "Losses",
"tie": "Ties",
"self_kicker": "Self-bomb Kicks",
"kick_frenzy": "Rapid Bomb Kicks",
"item_fan": "Self-powerup Pickups",
"item_friend": "Team Powerup Pickups",
"chain_killer": "Bomb-chain Kills",
"chain_victim": "Bomb-chain Deaths",
"kick_thief": "Enemy Bomb Kicks",
"item_thief": "Enemy Powerup Pickups",
"hara_kiri": "Suicides", //Self-bomb Deaths
"friendly_fire": "Friendly Fires",
"chain_fan": "Bomb in chains",
"slack_king": "Idle Spans",
"bomb_layer": "Bombs"
};
let bindex_id = {
0: "win",
1: "loss",
2: "tie",
3: "self_kicker",
4: "kick_frenzy",
5: "item_fan",
6: "item_friend",
7: "chain_killer",
8: "chain_victim",
9: "kick_thief",
10: "item_thief",
11: "hara_kiri",
12: "friendly_fire",
13: "chain_fan",
14: "slack_king",
15: "bomb_layer"
};
// neutral, competitive, collaborative
let labelid_Category = {
"Epochs": "neutral",
"win": "neutral",
"loss": "neutral",
"tie": "neutral",
"self_kicker": "collaborative",
"kick_frenzy": "collaborative",
"item_fan": "collaborative",
"item_friend": "collaborative",
"chain_killer": "collaborative",
"chain_victim": "collaborative",
"kick_thief": "competitive",
"item_thief": "competitive",
"hara_kiri": "collaborative",
"friendly_fire": "collaborative",
"chain_fan": "collaborative",
"slack_king": "collaborative",
"bomb_layer": "collaborative"
};
for (i in cycle_01.environment.parameterLabel){
labelNames.push(labelid_NameDictionary[i]);
}
console.log("labelNames: ",labelNames);
// Create array of behavior definitions
let behaviorDefinitions = [
"Number of wins.",
"Number of loss.",
"Number of tie.",
"Number of times, an agent kicked his own bomb.",
"Number of times, an agent kicked a bomb more than once in a short sequence.",
"Number of times the agent uncovered an item and then picked it up itself.",
"Number of times the agents picked up an item uncovered by an allied agent.",
"Number of kills scored by using chained bombs.",
"Number of times agent got killed by bomb chains from other agents.",
"Number of times, an agent kicked a bomb of an enemy agent.",
"Number of times, an agent picked up an item uncovered by the enemy.",
"Number of times, an agents got killed by a bomb placed by itself.",
"Number of times an agent killed an ally with a bomb place by itself.",
"Number of bombs of an agent that were involved in a chain.",
"Number of times an agent did not anything for more than 5 timesteps.",
"Number of times an agent laid a bomb."
]
console.log("behaviorDefinitions: ",behaviorDefinitions);
// Create array of behavior result arrays for both agents combined
let iA=0, iB=0, iC=0;
let m00=[], m01=[], m02=[], m03=[], m04=[], m05=[], m06=[], m07=[],
m08=[], m09=[], m10=[], m11=[], m12=[], m13=[], m14=[], m15=[];
for (c in cycle_results){ //c = cycles;
iA=0;
for (a in cycle_results[c]){ //a = agents; cycle[c][a] = agent results (JSON)
iB=0;
for (b in cycle_results[c][a]){ //b = behaviors; cycle[c][a][b] = behavior results (Int)
if (iB==0){m00.push(cycle_results[c][a][b]);}
if (iB==1){m01.push(cycle_results[c][a][b]);}
if (iB==2){m02.push(cycle_results[c][a][b]);}
if (iB==3){m03.push(cycle_results[c][a][b]);}
if (iB==4){m04.push(cycle_results[c][a][b]);}
if (iB==5){m05.push(cycle_results[c][a][b]);}
if (iB==6){m06.push(cycle_results[c][a][b]);}
if (iB==7){m07.push(cycle_results[c][a][b]);}
if (iB==8){m08.push(cycle_results[c][a][b]);}
if (iB==9){m09.push(cycle_results[c][a][b]);}
if (iB==10){m10.push(cycle_results[c][a][b]);}
if (iB==11){m11.push(cycle_results[c][a][b]);}
if (iB==12){m12.push(cycle_results[c][a][b]);}
if (iB==13){m13.push(cycle_results[c][a][b]);}
if (iB==14){m14.push(cycle_results[c][a][b]);}
if (iB==15){m15.push(cycle_results[c][a][b]);}
iB++;
}
iA++;
}
iC++;
}
let m = [m00,m01,m02,m03,m04,m05,m06,m07,m08,m09,m10,m11,m12,m13,m14,m15]
// console.log("metric results 'm': ",m)
// Calculate the slope for every behavior and each team
let slopesTeamH=[];
let slopesTeamN=[];
let stepsTeamH = rangeStep(0,46,2);
let stepsTeamN = rangeStep(1,47,2);
let stepsAgentH = rangeStep(0,46,4);
let stepsAgentN = rangeStep(1,47,4);
for (i in range(1,16)){
if (i==0||i==1||i==2){
slopesTeamN.push(slopeSolo(stepsAgentN,m[i]));
}
else{
slopesTeamN.push(slopeTeam(stepsTeamN,m[i]));
}
}
for (i in range(1,16)){
if (i==0||i==1||i==2){
slopesTeamH.push(slopeSolo(stepsAgentH,m[i]));
}
else{
slopesTeamH.push(slopeTeam(stepsTeamH,m[i]));
}
}
// for (i in range(0,15)){
// console.log("slopes of Team N: "+i,slopesTeamN[i].toFixed(2));
// console.log("slopes of Team H: "+i,slopesTeamH[i].toFixed(2));
// }
// Create array of all correlations between behaviors
let correlation = [];
for (i in range(0,15)){
for (j in range(0,15)){
if(i!=j){
correlation.push([i,labelNames[i],j,labelNames[j],pearsonCorrelation([m[i],m[j]],0,1)]);
}
}
}
console.log("correlation: ", correlation);
// Create array with the highest correlation for each behavior
let maximalCorr=[0,0,0,0,0];
let maxCorr00=[0,0,0,0,0], maxCorr01=[0,0,0,0,0], maxCorr02=[0,0,0,0,0], maxCorr03=[0,0,0,0,0],
maxCorr04=[0,0,0,0,0], maxCorr05=[0,0,0,0,0], maxCorr06=[0,0,0,0,0], maxCorr07=[0,0,0,0,0],
maxCorr08=[0,0,0,0,0], maxCorr09=[0,0,0,0,0], maxCorr10=[0,0,0,0,0], maxCorr11=[0,0,0,0,0],
maxCorr12=[0,0,0,0,0], maxCorr13=[0,0,0,0,0], maxCorr14=[0,0,0,0,0], maxCorr15=[0,0,0,0,0];
for (i in correlation){
if (correlation[i][0]==0 && correlation[i][2]!=1 && Math.abs(maxCorr00[4]) <= Math.abs(correlation[i][4])){maxCorr00=correlation[i];}
if (correlation[i][0]==1 && correlation[i][2]!=0 && Math.abs(maxCorr01[4]) <= Math.abs(correlation[i][4])){maxCorr01=correlation[i];}
if (correlation[i][0]==2 && Math.abs(maxCorr02[4]) <= Math.abs(correlation[i][4])){maxCorr02=correlation[i];}
if (correlation[i][0]==3 && Math.abs(maxCorr03[4]) <= Math.abs(correlation[i][4])){maxCorr03=correlation[i];}
if (correlation[i][0]==4 && Math.abs(maxCorr04[4]) <= Math.abs(correlation[i][4])){maxCorr04=correlation[i];}
if (correlation[i][0]==5 && Math.abs(maxCorr05[4]) <= Math.abs(correlation[i][4])){maxCorr05=correlation[i];}
if (correlation[i][0]==6 && Math.abs(maxCorr06[4]) <= Math.abs(correlation[i][4])){maxCorr06=correlation[i];}
if (correlation[i][0]==7 && Math.abs(maxCorr07[4]) <= Math.abs(correlation[i][4])){maxCorr07=correlation[i];}
if (correlation[i][0]==8 && Math.abs(maxCorr08[4]) <= Math.abs(correlation[i][4])){maxCorr08=correlation[i];}
if (correlation[i][0]==9 && Math.abs(maxCorr09[4]) <= Math.abs(correlation[i][4])){maxCorr09=correlation[i];}
if (correlation[i][0]==10 && Math.abs(maxCorr10[4]) <= Math.abs(correlation[i][4])){maxCorr10=correlation[i];}
if (correlation[i][0]==11 && Math.abs(maxCorr11[4]) <= Math.abs(correlation[i][4])){maxCorr11=correlation[i];}
if (correlation[i][0]==12 && Math.abs(maxCorr12[4]) <= Math.abs(correlation[i][4])){maxCorr12=correlation[i];}
if (correlation[i][0]==13 && Math.abs(maxCorr13[4]) <= Math.abs(correlation[i][4])){maxCorr13=correlation[i];}
if (correlation[i][0]==14 && Math.abs(maxCorr14[4]) <= Math.abs(correlation[i][4])){maxCorr14=correlation[i];}
if (correlation[i][0]==15 && Math.abs(maxCorr15[4]) <= Math.abs(correlation[i][4])){maxCorr15=correlation[i];}
if (Math.abs(maximalCorr[4]) <= Math.abs(correlation[i][4])){maximalCorr=correlation[i];}
}
let maxCorr = [
maxCorr00, maxCorr01, maxCorr02, maxCorr03,
maxCorr04, maxCorr05, maxCorr06, maxCorr07,
maxCorr08, maxCorr09, maxCorr10, maxCorr11,
maxCorr12, maxCorr13, maxCorr14, maxCorr15
]
// console.log("maxCorr: ",maxCorr,maximalCorr);
// Log the maxima and minima for both Teams and behavior seperate
// {
// console.log("Max&Min NNT m0: "+maximaMinimaSolo(rangeStep(1,47,4),m[0]));
// console.log("Max&Min NNT m1: "+maximaMinimaSolo(rangeStep(1,47,4),m[1]));
// console.log("Max&Min NNT m2: "+maximaMinimaSolo(rangeStep(1,47,4),m[2]));
// console.log("Max&Min NNT m3: "+maximaMinimaTeam(rangeStep(1,47,2),m[3]));
// console.log("Max&Min NNT m4: "+maximaMinimaTeam(rangeStep(1,47,2),m[4]));
// console.log("Max&Min NNT m5: "+maximaMinimaTeam(rangeStep(1,47,2),m[5]));
// console.log("Max&Min NNT m6: "+maximaMinimaTeam(rangeStep(1,47,2),m[6]));
// console.log("Max&Min NNT m7: "+maximaMinimaTeam(rangeStep(1,47,2),m[7]));
// console.log("Max&Min NNT m8: "+maximaMinimaTeam(rangeStep(1,47,2),m[8]));
// console.log("Max&Min NNT m9: "+maximaMinimaTeam(rangeStep(1,47,2),m[9]));
// console.log("Max&Min NNT m10: "+maximaMinimaTeam(rangeStep(1,47,2),m[10]));
// console.log("Max&Min NNT m11: "+maximaMinimaTeam(rangeStep(1,47,2),m[11]));
// console.log("Max&Min NNT m12: "+maximaMinimaTeam(rangeStep(1,47,2),m[12]));
// console.log("Max&Min NNT m13: "+maximaMinimaTeam(rangeStep(1,47,2),m[13]));
// console.log("Max&Min NNT m14: "+maximaMinimaTeam(rangeStep(1,47,2),m[14]));
// console.log("Max&Min NNT m15: "+maximaMinimaTeam(rangeStep(1,47,2),m[15]));
// console.log("Max&Min HJT m0: "+maximaMinimaSolo(rangeStep(0,46,4),m[0]));
// console.log("Max&Min HJT m1: "+maximaMinimaSolo(rangeStep(0,46,4),m[1]));
// console.log("Max&Min HJT m2: "+maximaMinimaSolo(rangeStep(0,46,4),m[2]));
// console.log("Max&Min HJT m3: "+maximaMinimaTeam(rangeStep(0,46,2),m[3]));
// console.log("Max&Min HJT m4: "+maximaMinimaTeam(rangeStep(0,46,2),m[4]));
// console.log("Max&Min HJT m5: "+maximaMinimaTeam(rangeStep(0,46,2),m[5]));
// console.log("Max&Min HJT m6: "+maximaMinimaTeam(rangeStep(0,46,2),m[6]));
// console.log("Max&Min HJT m7: "+maximaMinimaTeam(rangeStep(0,46,2),m[7]));
// console.log("Max&Min HJT m8: "+maximaMinimaTeam(rangeStep(0,46,2),m[8]));
// console.log("Max&Min HJT m9: "+maximaMinimaTeam(rangeStep(0,46,2),m[9]));
// console.log("Max&Min HJT m10: "+maximaMinimaTeam(rangeStep(0,46,2),m[10]));
// console.log("Max&Min HJT m11: "+maximaMinimaTeam(rangeStep(0,46,2),m[11]));
// console.log("Max&Min HJT m12: "+maximaMinimaTeam(rangeStep(0,46,2),m[12]));
// console.log("Max&Min HJT m13: "+maximaMinimaTeam(rangeStep(0,46,2),m[13]));
// console.log("Max&Min HJT m14: "+maximaMinimaTeam(rangeStep(0,46,2),m[14]));
// console.log("Max&Min HJT m15: "+maximaMinimaTeam(rangeStep(0,46,2),m[15]));
// }
function computeRelativeFrequencyText(sumTeamN, sumTeamH)
{
let min = sumTeamN;
let max = sumTeamH;
let maxTeam = "Hakozaki Junctions";
let team = "teamB";
if(sumTeamH<sumTeamN)
{
min = sumTeamH;
max = sumTeamN;
maxTeam = "Skynet955";
team = "teamA";
}
let nRatio = Math.round(max/min);
// return {nRatio, maxTeam, team};
if(nRatio == 1)
return `almost same number of times by both teams. `;
else
return `almost <span class='dynamicText'>${nRatio}</span> times more by <span class='${team}'>${maxTeam}</span>. `;
}
function aggregateBehaviorCount(obj1, obj2)
{
let aggregatedObj = {};
let teamStats = ["win", "tie", "loss"];
for(const [behavior, count] of Object.entries(obj1))
{
if(teamStats.indexOf(behavior)>=0)
{
aggregatedObj[behavior] = obj1[behavior];
}
else
aggregatedObj[behavior] = obj1[behavior] + obj2[behavior];
}
return aggregatedObj;
}
let rev_data = [];
for (const [epochid, value] of Object.entries(cycle_results))
{
let epochVal = (parseInt(epochid)+1)*1000;
let hakozaki = aggregateBehaviorCount(value["1hakozaki"], value["2hakozaki"] );
let ppo = aggregateBehaviorCount(value["1ppo"], value["2ppo"] );
// console.log(hakozaki, ppo);
rev_data.push({"Epochs": +(epochVal), "teamId":2, ...hakozaki});
rev_data.push({"Epochs": +(epochVal), "teamId":1, ...ppo});
}
window.aggregatedData = rev_data;
// ########## VIS ##########
// Configurate Parameters
// let width=1920;
// let height=1200;
let width = window.screen.width;
let height = window.screen.height;
/*colornames = aqua, aquamarine, beige, bisque, chocolate,
greenyellow, lavenderblush, lemonchiffon, darkcyan,
magenta, peachpuff, plum, turquoise, blueviolet,
darkseagreen, darkslategrey, darkviolet, indigo, lightsalmon,
olive, orchid, teal, tan, tomato, steelblue*/
let colorAgent1="steelblue";
let colorAgent2="tomato";
let svg1Color="white";
let div1Color="white"
let divFontColor="black";
let svg2Color="white";
let svg2Color2="white";
let positiveColor = "green";
let negativeColor = "red";
let nuetralColor = "black";
// let font1 = "18px system-ui"; //tick labels
// let font2 = "20px system-ui";
// let font3 = "18px system-ui";
// let tickLabelSize = "14px system-ui";
let font1 = "18px system-ui"; //tick labels
let font2 = "20px system-ui";
let font3 = "18px system-ui";
let tickLabelSize = "14px system-ui";
let parcoordsAxisLabel = "12px";
if (window.screen.width<=1920)
{
font1 = "12px system-ui"; //tick labels
font2 = "14px system-ui";
font3 = "12px system-ui";
tickLabelSize = "10px system-ui";
parcoordsAxisLabel = "9px";
}
if (window.screen.width<=1200)
{
font1 = "8px system-ui"; //tick labels
font2 = "10px system-ui";
font3 = "8px system-ui";
tickLabelSize = "6px system-ui";
parcoordsAxisLabel = "5px";
}
let divFontStyle="";
let selectWidth=100;
let selectHeight=0;
let selectMarginTop=0
let selectMarginLeft=50;
// let svg1Width=width*0.5;
// let svg1Height=height*0.5;
// let svg1Width=width*0.5;
// let svg1Width = +d3.select("#lineCharts").style('width').slice(0, -2);
let svg1Width = document.getElementById("lineCharts").offsetWidth;
let svg1Height=300;
let svg1MarginTop=selectHeight;
let svg1MarginLeft=0;
let lineChartHeight=150;
let lineChartWidth=svg1Width-90;
// let svg2Width=width*0.5;
let svg2Width = document.getElementById("scatterPlotDiv").offsetWidth;
let svg2Height=document.getElementById("scatterPlotDiv").offsetHeight;
if (svg2Height > 956) svg2Height = 956;
let svg2MarginTop=selectHeight+"px";
let svg2MarginLeft=svg1Width+"px";
// let divWidth=(width-svg1Width)+"px";
let divWidth = svg1Width;
let divHeight=(svg2Height-svg1Height-280)+"px";
let div1MarginTop=(svg1Height+selectHeight)+"px";
let div1MarginLeft=0+"px";
let axisLineThickness = "1px";
let selectedMetricsForScatterPlot = [14,0];
let smallVisAxisColor = "grey";
let scatterplotScaleRatio = 16;
d3.select("body").style("font-size", font2);
// Create the 1st SVG for the Linechart
let svg1 = d3.select("#svg1")
.attr("width",svg1Width)
.attr("height",svg1Height)
// .style("position","absolute")
// .style("margin-top",svg1MarginTop+"px")
// .style("margin-left",svg1MarginLeft+"px")
// .style("padding-left","10px")
// .style("padding-right","10px")
.style('background-color',svg1Color);
// Create Select1 Button (Filter)
let select1 = d3.select("body").append("select")
.attr("id","select1")
.attr("width",selectWidth)
.attr("height",selectHeight)
// .style("position","absolute")
.style("direction","ltr")
.style("margin-top","0px")
.style("margin-left",selectMarginLeft+"px")
.style('background-color',"white");
// Create Select2 Button (Filter)
let select2 = d3.select("body").append("select")
.attr("id","select2")
.attr("width",selectWidth)
.attr("height",selectHeight)
// .style("position","absolute")
.style("direction","ltr")
.style("margin-top","0px")
.style("margin-left",selectMarginLeft+150+"px")
.style('background-color',"white")
;
// Create Select3 Button (Filter)
let select3 = d3.select("body").append("select")
.attr("id","select3")
.attr("width",selectWidth)
.attr("height",selectHeight)
// .style("position","absolute")
.style("direction","ltr")
.style("margin-top","0px")
.style("margin-left",selectMarginLeft+250+"px")
.style('background-color',"white");
// Create the DIV for the dynamic analysis text
let div1 = d3.select("#div1")
.style("width",divWidth)
.style("height",divHeight)
// .style("position","absolute")
// .style("margin-top",div1MarginTop)
// .style("padding-left","10px")
// .style("padding-right","10px")
// .style("margin-left",div1MarginLeft)
.style('background-color',div1Color)
.style("text-align","justify");
// Create the 2nd SVG for the Scatterplot-matrix
let svg2 = d3.select("#svg2")
// .attr("width",svg2Width)
.attr("width","100%")
.attr("height",svg2Height)
// .style("position","absolute")
// .style("margin-left",svg2MarginLeft)
// .style("margin-top",svg2MarginTop)
.style('background-color',svg2Color);
// Draw the Linechart
let startCycle=1, endCycle=cycle_results.length;
let xRoot=50;
let yRoot=svg1Height;
let metricForLineChart=14;
let numberOfBattles=50;
let numberOfTrainings=1000;
appendLineChart(cycle_results,xRoot,yRoot,metricForLineChart);
appendLineChartSmall(cycle_results);
// Write the Analysis
analysis(cycle_results,metricForLineChart,startCycle,endCycle);
// Draw the Scatterplot Matrix
let agent=0;
let xRoot2=0;
let yRoot2=svg2Height;
appendScatterplotMatrix(cycle_results,xRoot2,yRoot2);
// Fill select1 with the behavior labels
// https://www.d3-graph-gallery.com/graph/line_select.html
d3.select("#select1").selectAll("PerformanceLabels")
.data(labelNames)
.enter()
.append("option")
.text(function(d){return d;})
.attr("value",function(d){return d;});
// Fill select2 with the startcycle labels
d3.select("#select2").selectAll("startCycles")
.data(rangeStep(1*1000,cycle_results.length*1000,1000))
.enter()
.append("option")
.text(function(d){return d;})
.attr("value",function(d){return d;});
// Fill select3 with the startcycle labels
d3.select("#select3").selectAll("endCycles")
.data(rangeStep(1*1000,cycle_results.length*1000,1000))
.enter()
.append("option")
.text(function(d){return d;})
.attr("value",function(d){return d;})
.attr("selected",true);
// Update svg1 and div1 when using select1
let selectedOption = metricForLineChart;
d3.select("#select1").on("change", function(d){
d3.select("#bigLineChartGroup").selectAll("*").remove();
div1.selectAll("*").remove();
selectedOption=d3.select(this).property("value");
let iO=0;
for (i in labelNames){
if (labelNames[i]==selectedOption){
selectedOption=iO;
}
iO++;
}
appendLineChartUpdate(cycle_results,xRoot,yRoot,selectedOption,startCycle,endCycle);
analysis(cycle_results,selectedOption,startCycle,endCycle);
})
// Update svg1 and div1 when using select1
d3.select("#select2").on("change", function(d){
d3.select("#bigLineChartGroup").selectAll("*").remove();
div1.selectAll("*").remove();
startCycle=d3.select(this).property("value")/1000;
appendLineChartUpdate(cycle_results,xRoot,yRoot,selectedOption,startCycle,endCycle);
analysis(cycle_results,selectedOption,startCycle,endCycle);
endCycle=cycle_results.length;
select3.selectAll("*").remove();
d3.select("#select3").selectAll("endCycles")
.data(rangeStep(startCycle*1000,endCycle*1000,1000))
.enter()
.append("option")
.text(function(d){return d;})
.attr("value",function(d){return d;})
.attr("selected",true);
})
// Update svg1 and div1 when using select1
d3.select("#select3").on("change", function(d){
d3.select("#bigLineChartGroup").selectAll("*").remove();
div1.selectAll("*").remove();
endCycle=d3.select(this).property("value")/1000;
appendLineChartUpdate(cycle_results,xRoot,yRoot,selectedOption,startCycle,endCycle);
analysis(cycle_results,selectedOption,startCycle,endCycle);
startCycle=1;
select2.selectAll("*").remove();
d3.select("#select2").selectAll("endCycles")
.data(rangeStep(startCycle*1000,endCycle*1000,1000))
.enter()
.append("option")
.text(function(d){return d;})
.attr("value",function(d){return d;});
})
// Draw the big detailed Scatterplot
let scatterplotZoomX1=50;
let scatterplotZoomY1=300;
let scatterplotZoomX2=250;
let scatterplotZoomY2=100;
// appendRect(svg2,0,scatterplotZoomY1,scatterplotZoomX2,0,svg2Color)
appendScatterplotUpdate(cycle_results,scatterplotZoomX1,scatterplotZoomY1,selectedMetricsForScatterPlot[0],selectedMetricsForScatterPlot[1]);
function computeCorrelation(metric1, metric2)
{
let maxMetric1=(m[metric1].reduce(function(a,b){return Math.max(a,b);}));
let maxMetric2=(m[metric2].reduce(function(a,b){return Math.max(a,b);}));
let iC=0, iA=0, iB=0;
let data = new Array(m[metric1],m[metric2]);
let corr = pearsonCorrelation(data,0,1);
return corr;
}
function computeCorrelationIntensityText(corrWithWin)
{
let corrIntensity = "";
if(corrWithWin < -0.7) corrIntensity = "a high negative";
if(corrWithWin < -0.4) corrIntensity = "a negative";
else if(corrWithWin < -0.1) corrIntensity = "a low negative";
// else if(corrWithWin < 0.25) corrIntensity = "almost no";
else if(corrWithWin < 0.1) corrIntensity = "almost no";
else if(corrWithWin < 0.4) corrIntensity = "a low positive";
else if(corrWithWin < 0.7) corrIntensity = "a positive";
else if(corrWithWin <= 1) corrIntensity = "a high positive";
return corrIntensity;
}
function maxMetricCount(obj, behaviorid)
{
let max = -1;
for(var i=0; i< obj.length; i++)
{
let count = obj[i][behaviorid];
if(count > max)
max = count;
}
return max;
}
// ########## FUNCTIONS ##########
function appendScatterplotUpdate(cycle,x,y,metric1,metric2){
d3.select("#bigscatterplotGroup").selectAll("*").remove();
// let plotWidth=300, plotHeight=svg2Height=200;
let tempWidth = document.getElementById("scatterPlotDiv").offsetWidth;
let plotWidth = tempWidth*0.25, plotHeight=svg2Height=plotWidth;
x=0, y=plotWidth;
let colorPlot="black";
let circleSize=5;
let x1=x, x2=x, y1=y, y2=y;
let maxMetric1 = roundOffCustom(maxMetricCount(window.aggregatedData, bindex_id[metric1]));
let maxMetric2 = roundOffCustom(maxMetricCount(window.aggregatedData, bindex_id[metric2]));
let iC=0, iA=0, iB=0;
// let data = new Array(m[metric1],m[metric2]);
let m1=-1, m2=-1;
if(metric1<metric2)
{
m1= metric1;
m2= metric2;
}
else
{
m1= metric2;
m2= metric1;
}
let corr = computeCorrelation(m1, m2);
let corrIntensity = computeCorrelationIntensityText(corr);
// Write Legend
let bigscatterplotG = d3.select("#bigscatterplotGroup");
appendRect(bigscatterplotG,0,y+15,x+130,0,svg2Color);
// let descriptiveText = `The two behaviors show ${corrIntensity} correlation between them (r=${corr.toFixed(3)})`;
// appendText(bigscatterplotG,-40,60,
// descriptiveText,font2,colorPlot);
let textElem = bigscatterplotG.append("text")
.text("The two behaviors have ")
.attr("x", 0)
.attr("y", -10)
.attr("fill", colorPlot)
.style("font", font2);
textElem.append("tspan").text(corrIntensity).attr("class", "computedText")
textElem.append("tspan").text(` correlation between them (r=${corr.toFixed(3)})`);
// appendText(svg2,x,55,
// "x-Axis: Number of displayed behavior '"+labelNames[metric1]+"'",font3,colorPlot);
appendText(bigscatterplotG,x + plotWidth/2,y+40,
"# "+labelNames[metric1]+"",font2,colorPlot,'',"axislabel scatterplotlabel");
let ylabelx = x-50;
let ylabely = plotWidth/2;
appendText(bigscatterplotG,ylabelx,ylabely,
"# "+ labelNames[metric2]+"",font2,colorPlot, `rotate(-90 ${ylabelx} ${ylabely})`, "axislabel scatterplotlabel");
// Draw y-Axis
let iY=0;
let ySteps=2;
for (iY in range(1,ySteps+1)){
// appendCircle(svg2,x,(y-(plotHeight/ySteps*iY)),colorPlot,circleSize);
appendTickMark(bigscatterplotG,x,(y-(plotHeight/ySteps*iY)),colorPlot, 0);
// appendText(bigscatterplotG,(x-30),(y-(plotHeight/ySteps*iY)),(maxMetric2/ySteps*iY).toFixed(0),font1,colorPlot);
bigscatterplotG.append("text")
.text((maxMetric2/ySteps*iY).toFixed(0))
.attr("x", x-10)
.attr("y", (y-(plotHeight/ySteps*iY)))
.attr("fill", colorPlot)
.style("font", tickLabelSize)
.style("text-anchor","end")
.style("dominant-baseline", "central");
}
appendLine(bigscatterplotG,x,y,x,(y-plotHeight),colorPlot,axisLineThickness);
// Draw x-Axis
let iX=0;
let xSteps=2;
for (iX in range(1,xSteps+1)){
// appendCircle(svg2,x+(plotWidth/xSteps*iX),y,colorPlot,circleSize);
appendTickMark(bigscatterplotG,x+(plotWidth/xSteps*iX),y,colorPlot, -90);
// appendText(bigscatterplotG,x+(plotWidth/xSteps*iX),(y+15),
// (maxMetric1/xSteps*iX).toFixed(0),
// font1, colorPlot);
bigscatterplotG.append("text").text((maxMetric1/xSteps*iX).toFixed(0))
.attr("x", x+(plotWidth/xSteps*iX))
.attr("y", y+15)
.attr("fill", colorPlot)
.style("font", tickLabelSize)
.style("text-anchor","middle")
.style("dominant-baseline", "central")
;
}
appendLine(bigscatterplotG,x,y,x+plotWidth,y,colorPlot, axisLineThickness);
// Draw Circles
for( var i=0; i<window.aggregatedData.length; i++)
{
let epochid = window.aggregatedData[i]["Epochs"]/1000;
let teamId = window.aggregatedData[i]["teamId"];
let xvalue = window.aggregatedData[i][bindex_id[metric1]];
let yvalue = window.aggregatedData[i][bindex_id[metric2]];
let x1=x+(plotWidth/maxMetric1)*xvalue;
let y1=y-(plotHeight/maxMetric2)*yvalue;
if (teamId == 2){
appendCircleOnHover(bigscatterplotG,x1,y1,colorAgent1,circleSize, `x: ${xvalue}, y: ${yvalue}` ,"teamAA scatterplotCircle cycle"+epochid);
}
else if (teamId == 1){
appendCircleOnHover(bigscatterplotG,x1,y1,colorAgent2,circleSize, `x: ${xvalue}, y: ${yvalue}` ,"teamBB scatterplotCircle cycle"+epochid);
}
}
bigscatterplotG.attr("transform","translate(70 30)");
highlightSelectedScatterPlot(metric1, metric2);
highlightScatterPlotCircles(startCycle, endCycle);
}
function appendScatterplotMatrix(cycle,x,y){
let x1=x;
let y1=y;
let scatterplotWidth=svg2Width/(scatterplotScaleRatio+0.4);
let scatterplotHeight=svg2Height/(scatterplotScaleRatio+1);
let xStep=scatterplotWidth;
let yStep=scatterplotHeight;
let iL1=0;
let splomGroup = svg2.append("g");
for (l1 in labelNames){
y1=y-(yStep*iL1);
let iL2=0;
// splomGroup.append("rect").attr({
// x:x+(xStep*iL1),
// y: y1 - scatterplotHeight*(iL1)-scatterplotHeight,
// width: 100,
// height: scatterplotHeight,
// fill: "grey",
// "fill-opacity": 0.3
// });
for (l2 in labelNames){
x1=x+(xStep*iL2);
if(iL1==iL2){
let t_x = x1 + scatterplotWidth - 5 ;
let t_y = y1-scatterplotHeight/2 ;
if(labelNames[l1] == "Bombs")
t_y = y1-svg2Height/60;
appendText(splomGroup,t_x ,t_y,labelNames[l1],font1,"black", `rotate(0 ${t_x} ${t_y})`, 'splomaxislabel')
}
if(iL1!=iL2 && iL1<iL2){
appendScatterplot(splomGroup, cycle,x1,y1,iL2,iL1);
}
iL2++;
}
iL1++;
}
}
function appendScatterplot(svg2, cycle,x,y,metric1,metric2){
let splomPadding = 12;