Repository navigation
Expand file tree
/
Copy pathanalysis-explora.py
More file actions
991 lines (822 loc) · 43.5 KB
/
Copy pathanalysis-explora.py
File metadata and controls
991 lines (822 loc) · 43.5 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
"""
EXPLORA Core
10/12/2023
_______________
Summary: The script runs the main EXPLORA operations like generation and processing of attributed graphs,
train of DT on top of the outcomes of the attributed graph processing and visualization of
the results.
These are Fig. 7, 8 of Section 6.2 and Fig. 13, 14 of Appendix C.
DISCLAIMER: THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
"""
####^^^^ Imports and settings
##^^ misc
from sklearn.preprocessing import MinMaxScaler
import graphviz
import tikzplotlib
from scipy.stats import norm
##^^ decision trees to evaluate the meaning of the transitions and their link to KPIs
from sklearn.tree import DecisionTreeClassifier # Import Decision Tree Classifier
from sklearn.model_selection import train_test_split # Import train_test_split function
from sklearn import metrics #Import scikit-learn metrics module for accuracy calculation
#^ exporting decision trees
from sklearn.tree import export_graphviz
from six import StringIO
#from sklearn.externals.six import StringIO
from IPython.display import Image
import pydotplus
##^^ importing project functions
from utils_shap_plotting import *
from utils_db_process import *
from utils_generic_functions import computeMedoid
from utils_experiment_list import *
from utils_attr_graphs import *
##^^ functions
def processKPIStateTransitions(dict_kpi_ues, dict_trans,exp):
"""
Parameters
_______________
dict_kpi_ues: the complex dictionary
dict_trans: dictionary with transitions useful for later analysis
exp: experiment ID
Output
_______________
dict_kpi_distr_state: dictionary with STATE as key and avg/std per slice KPIs as value (as dictionary as well)
dict_kpi_state_transition: dictionary with full STATE TRANSITION as key and CF-distance as value (as dictionary as well)
"""
##^^ list with transitions we want to study
list_hot_trans = []
##^^ reading the dict_trans dictionary
for keys,values in dict_trans.items():
##^^ picking up from and to states, then weight and then
keys = str(keys)
#^ split in two to retrieve from and to state
elements = keys[1:-1].split(',')
from_state = [int(elements[el]) for el in range(6)]
to_state = [int(elements[el]) for el in range(6,12)]
##^^ DEBUG: counting how many items for each slice ID we have in a given state
# print(f'From state {from_state} with (',end=' ')#) to {to_state}: {values} ')
from_kpis_count = dict_kpi_ues[tuple(from_state)]
from_lens = []
for ue_key, ue_item in from_kpis_count.items():
if ue_key == 0:
# print(f'SL{ue_key}: {len(ue_item)} ', end = '')
from_lens.append(len(ue_item))
if ue_key == 1:
# print(f'SL{ue_key}: {len(ue_item)} ', end = '')
from_lens.append(len(ue_item))
if ue_key == 2:
# print(f'SL{ue_key}: {len(ue_item)} ', end = '')
from_lens.append(len(ue_item))
# print(f') to state {to_state} with (',end=' ')
to_kpis_count = dict_kpi_ues[tuple(from_state)]
to_lens = []
for ue_key, ue_item in to_kpis_count.items():
if ue_key == 0:
# print(f'SL{ue_key}: {len(ue_item)} ', end = '')
to_lens.append(len(ue_item))
if ue_key == 1:
# print(f'SL{ue_key}: {len(ue_item)} ', end = '')
to_lens.append(len(ue_item))
if ue_key == 2:
# print(f'SL{ue_key}: {len(ue_item)} ', end = '')
to_lens.append(len(ue_item))
# print(f') => {values}')
##^^ NOTE that the debugging highlights the following:
## there exists links between states with 1 occurrence that are fully negligible because also have little KPIs like
## ___From state [30, 9, 11, 2, 2, 0] with ( SL0: 1 SL1: 1 SL2: 1 ) to state [12, 15, 23, 1, 2, 0] with ( SL0: 1 SL1: 1 SL2: 1 ) => 1
## but others do not:
## ___From state [12, 15, 23, 1, 2, 0] with ( SL0: 101 SL1: 101 SL2: 101 ) to state [12, 15, 23, 2, 1, 1] with
## ( SL0: 101 SL1: 101 SL2: 101 ) => 1
## hence use a combined "values" + "num of KPIs reported" to set which transitions to use or not for the evaluation
if values > 1 :
list_hot_trans.append(keys)
elif values == 1:
reason_to_add = False
for j in from_lens:
if j > 50:
reason_to_add = True
for j in to_lens:
if j > 50:
reason_to_add = True
if reason_to_add:
list_hot_trans.append(keys)
##^^ cleaning unused structure
dict_trans.clear()
##^^ dictionaries in output
#^ dictionary with STATE as key and avg/std per slice KPIs as value (as dictionary as well)
dict_kpi_distr_state = {}
#^ dictionary with full STATE TRANSITION as key and 1 as value - FUTURE WORK: add distribution distance as value (as dictionary as well)
dict_kpi_state_transition = {}
##^^ Analysis of the transitions: linking KPIs and computing distances
for el in list_hot_trans:
keys = str(el)
from_state, to_state = getFromToStates(keys)
# print(f'{keys} - {from_state} to {to_state}')
# print(f'{keys} - {from_state} to {to_state}: ', end='')
##^^ np array with the distribution of the from_state
from_kpis = dict_kpi_ues[tuple(from_state)]
dist_from_sl0 = []
dist_from_sl1 = []
dist_from_sl2 = []
from_sl0_tx_brate = []
from_sl0_tx_pkts = []
from_sl0_dl_buffer = []
from_sl1_tx_brate = []
from_sl1_tx_pkts = []
from_sl1_dl_buffer = []
from_sl2_tx_brate = []
from_sl2_tx_pkts = []
from_sl2_dl_buffer = []
for ue_key, ue_item in from_kpis.items():
if ue_key==0:
for el in ue_item:
for e in el:
dist_from_sl0.append((e.tx_brate, e.tx_pkts, e.dl_buffer))
from_sl0_tx_brate.append(e.tx_brate)
from_sl0_tx_pkts.append(e.tx_pkts)
from_sl0_dl_buffer.append(e.dl_buffer)
if ue_key==1:
for el in ue_item:
for e in el:
dist_from_sl1.append((e.tx_brate, e.tx_pkts, e.dl_buffer))
from_sl1_tx_brate.append(e.tx_brate)
from_sl1_tx_pkts.append(e.tx_pkts)
from_sl1_dl_buffer.append(e.dl_buffer)
if ue_key==2:
for el in ue_item:
for e in el:
dist_from_sl2.append((e.tx_brate, e.tx_pkts, e.dl_buffer))
from_sl2_tx_brate.append(e.tx_brate)
from_sl2_tx_pkts.append(e.tx_pkts)
from_sl2_dl_buffer.append(e.dl_buffer)
# print(np.array(dist_from_sl0).shape,np.array(dist_from_sl1).shape,np.array(dist_from_sl2).shape)
##^^ np array with the distribution of the to_state
to_kpis = dict_kpi_ues[tuple(to_state)]
dist_to_sl0 = []
dist_to_sl1 = []
dist_to_sl2 = []
to_sl0_tx_brate = []
to_sl0_tx_pkts = []
to_sl0_dl_buffer = []
to_sl1_tx_brate = []
to_sl1_tx_pkts = []
to_sl1_dl_buffer = []
to_sl2_tx_brate = []
to_sl2_tx_pkts = []
to_sl2_dl_buffer = []
for ue_key, ue_item in to_kpis.items():
if ue_key==0:
for el in ue_item:
for e in el:
dist_to_sl0.append((e.tx_brate, e.tx_pkts, e.dl_buffer))
to_sl0_tx_brate.append(e.tx_brate)
to_sl0_tx_pkts.append(e.tx_pkts)
to_sl0_dl_buffer.append(e.dl_buffer)
if ue_key==1:
for el in ue_item:
for e in el:
dist_to_sl1.append((e.tx_brate, e.tx_pkts, e.dl_buffer))
to_sl1_tx_brate.append(e.tx_brate)
to_sl1_tx_pkts.append(e.tx_pkts)
to_sl1_dl_buffer.append(e.dl_buffer)
if ue_key==2:
for el in ue_item:
for e in el:
dist_to_sl2.append((e.tx_brate, e.tx_pkts, e.dl_buffer))
to_sl2_tx_brate.append(e.tx_brate)
to_sl2_tx_pkts.append(e.tx_pkts)
to_sl2_dl_buffer.append(e.dl_buffer)
# print(np.array(dist_to_sl0).shape,np.array(dist_to_sl1).shape,np.array(dist_to_sl2).shape)
##^^ At this point we have 6 np arrays with the distribution of "FROM/TO" states and each "slice"
##^^ Now create a dictionary with STATE as key and 1 as value // future: have distribution distance
if keys not in dict_kpi_state_transition:
dict_kpi_state_transition[keys]={"dist_SL0": 1, "dist_SL1": 1, "dist_SL2": 1}
##^^ Now create a dictionary with STATE as key and (mean, std) KPIs per slice
#^ helper printing
# print("---")
# print(f'FROM stats: ')
# print(f'SL0 {round(np.array(from_sl0_tx_brate).mean(),2)}|{round(np.array(from_sl0_tx_brate).std(),2)}\
# {round(np.array(from_sl0_tx_pkts).mean(),2)}|{round(np.array(from_sl0_tx_pkts).std(),2)}\
# {round(np.array(from_sl0_dl_buffer).mean(),2)}|{round(np.array(from_sl0_dl_buffer).std(),2)} ')
# print(f'SL1 {round(np.array(from_sl1_tx_brate).mean(),2)}|{round(np.array(from_sl1_tx_brate).std(),2)}\
# {round(np.array(from_sl1_tx_pkts).mean(),2)}|{round(np.array(from_sl1_tx_pkts).std(),2)}\
# {round(np.array(from_sl1_dl_buffer).mean(),2)}|{round(np.array(from_sl1_dl_buffer).std(),2)} ')
# print(f'SL2 {round(np.array(from_sl2_tx_brate).mean(),2)}|{round(np.array(from_sl2_tx_brate).std(),2)}\
# {round(np.array(from_sl2_tx_pkts).mean(),2)}|{round(np.array(from_sl2_tx_pkts).std(),2)}\
# {round(np.array(from_sl2_dl_buffer).mean(),2)}|{round(np.array(from_sl2_dl_buffer).std(),2)} ')
# print(f'Lengths. {len(from_sl0_tx_brate)}')
# print("---")
# print(f'TO stats: ')
# print(f'SL0 {round(np.array(to_sl0_tx_brate).mean(),2)}|{round(np.array(to_sl0_tx_brate).std(),2)}\
# {round(np.array(to_sl0_tx_pkts).mean(),2)}|{round(np.array(to_sl0_tx_pkts).std(),2)}\
# {round(np.array(to_sl0_dl_buffer).mean(),2)}|{round(np.array(to_sl0_dl_buffer).std(),2)} ')
# print(f'SL1 {round(np.array(to_sl1_tx_brate).mean(),2)}|{round(np.array(to_sl1_tx_brate).std(),2)}\
# {round(np.array(to_sl1_tx_pkts).mean(),2)}|{round(np.array(to_sl1_tx_pkts).std(),2)}\
# {round(np.array(to_sl1_dl_buffer).mean(),2)}|{round(np.array(to_sl1_dl_buffer).std(),2)} ')
# print(f'SL2 {round(np.array(from_sl2_tx_brate).mean(),2)}|{round(np.array(to_sl2_tx_brate).std(),2)}\
# {round(np.array(to_sl2_tx_pkts).mean(),2)}|{round(np.array(to_sl2_tx_pkts).std(),2)}\
# {round(np.array(to_sl2_dl_buffer).mean(),2)}|{round(np.array(to_sl2_dl_buffer).std(),2)} ')
# print(f'Lengths. {len(to_sl0_tx_brate)}')
# print("---")
from_state_sl0_kpi = stateSliceKPI(round(np.array(from_sl0_dl_buffer).mean(),2),round(np.array(from_sl0_dl_buffer).std(),2),\
round(np.array(from_sl0_tx_brate).mean(),2),round(np.array(from_sl0_tx_brate).std(),2),\
round(np.array(from_sl0_tx_pkts).mean(),2),round(np.array(from_sl0_tx_pkts).std(),2))
from_state_sl1_kpi = stateSliceKPI(round(np.array(from_sl1_dl_buffer).mean(),2),round(np.array(from_sl1_dl_buffer).std(),2),\
round(np.array(from_sl1_tx_brate).mean(),2),round(np.array(from_sl1_tx_brate).std(),2),\
round(np.array(from_sl1_tx_pkts).mean(),2),round(np.array(from_sl1_tx_pkts).std(),2))
from_state_sl2_kpi = stateSliceKPI(round(np.array(from_sl2_dl_buffer).mean(),2),round(np.array(from_sl2_dl_buffer).std(),2),\
round(np.array(from_sl2_tx_brate).mean(),2),round(np.array(from_sl2_tx_brate).std(),2),\
round(np.array(from_sl2_tx_pkts).mean(),2),round(np.array(from_sl2_tx_pkts).std(),2))
to_state_sl0_kpi = stateSliceKPI(round(np.array(to_sl0_dl_buffer).mean(),2),round(np.array(to_sl0_dl_buffer).std(),2),\
round(np.array(to_sl0_tx_brate).mean(),2),round(np.array(to_sl0_tx_brate).std(),2),\
round(np.array(to_sl0_tx_pkts).mean(),2),round(np.array(to_sl0_tx_pkts).std(),2))
to_state_sl1_kpi = stateSliceKPI(round(np.array(to_sl1_dl_buffer).mean(),2),round(np.array(to_sl1_dl_buffer).std(),2),\
round(np.array(to_sl1_tx_brate).mean(),2),round(np.array(to_sl1_tx_brate).std(),2),\
round(np.array(to_sl1_tx_pkts).mean(),2),round(np.array(to_sl1_tx_pkts).std(),2))
to_state_sl2_kpi = stateSliceKPI(round(np.array(to_sl2_dl_buffer).mean(),2),round(np.array(to_sl2_dl_buffer).std(),2),\
round(np.array(to_sl2_tx_brate).mean(),2),round(np.array(to_sl2_tx_brate).std(),2),\
round(np.array(to_sl2_tx_pkts).mean(),2),round(np.array(to_sl2_tx_pkts).std(),2))
##^^ inclusion in dictionary if not present yet
if tuple(from_state) not in dict_kpi_state_transition:
dict_kpi_distr_state[tuple(from_state)]= {"SL0":from_state_sl0_kpi,
"SL1":from_state_sl1_kpi,
"SL2":from_state_sl2_kpi,
"Distr_elements":len(from_sl0_dl_buffer),
}
if tuple(to_state) not in dict_kpi_state_transition:
dict_kpi_distr_state[tuple(to_state)]= {"SL0":to_state_sl0_kpi,
"SL1":to_state_sl1_kpi,
"SL2":to_state_sl2_kpi,
"Distr_elements":len(to_sl0_dl_buffer),
}
return dict_kpi_state_transition, dict_kpi_distr_state
def printFullGraphwithKPIs(global_dict_kpi_state_transition,global_dict_kpi_distr_state,agent):
"""
-
Parameters
_______________
global_dict_kpi_distr_state: dictionary with STATE as key and avg/std per slice KPIs as value (as dictionary as well)
global_dict_kpi_state_transition: dictionary with full STATE TRANSITION as key and CF-distance as value (as dictionary as well)
Output
_______________
"""
##^^ Printing results
print(f'--- Results ---')
print(f'-- Links between graph nodes --')
#^ the "global_dict_kpi_state_transition", i.e., the EDGES
for keys, values in global_dict_kpi_state_transition.items():
# print(keys)
from_state, to_state = getFromToStates(keys)
print(f'From {from_state} to {to_state}')
print(f'-- Graph node full attribute info --')
#^ the "global_dict_kpi_distr_state", i.e., the NODES
for keys, values in global_dict_kpi_distr_state.items():
print(keys)
#^ looping over the list of dictionaries composed of {exp:dict_kpis_per_state}
for el in values:
for key, value in el.items():
list_of_print = ["SL0","SL1","SL2"]
for el in list_of_print:
val = value[el]
print(f'{key}, {value["Distr_elements"]}, {el}, {val.avg_tx_brate}, ',end = '')
print(f'{val.std_tx_brate}, {val.avg_tx_pkts}, {val.std_tx_pkts}, {val.avg_dl_buffer},{val.std_dl_buffer}')
def processExperiments(list_of_experiments,agent):
"""
-
Parameters
_______________
Output
_______________
"""
global_dict_kpi_state_transition = {}
global_dict_kpi_distr_state = {}
##^^ ANALYSIS for each experiment
for exp in list_of_experiments:
# print(f'Current experiment under analysis: {exp} \n-------')
##^^ read the UE reported metrics
dict_ue_metrics, dict_sched_pol = readUEMetrics(exp)
##^^ create dictionaries with distribution of user KPIs per slice per state [e.g. (24, 15, 11, 2, 1, 0)] and transitions between states
dict_kpi_ues, dict_trans = createDictKPIStateTransitions(dict_ue_metrics,dict_sched_pol,exp)
##^^ cleaning
dict_ue_metrics.clear()
dict_sched_pol.clear()
dict_kpi_state_transition, dict_kpi_distr_state = processKPIStateTransitions(dict_kpi_ues, dict_trans,exp)
##^^ analyze the distance metric for this experiment
# analysisDistanceStateTransitions(dict_kpi_state_transition,dict_kpi_distr_state,exp)
##^^ cleaning
dict_kpi_ues.clear()
dict_trans.clear()
##^^ Including experiment-related info (from "dict_kpi_state_transition" and "dict_kpi_distr_state") into one big dictionary
for keys, values in dict_kpi_state_transition.items():
##^^ Printing
# from_state, to_state = getFromToStates(keys)
# print(f'From {from_state} to {to_state}: ')
# print(yaml.dump(values, default_flow_style=False))# very convenient way of printing dictionaries
##^^ Inclusion into the global dictionary
if keys not in global_dict_kpi_state_transition:
global_dict_kpi_state_transition[keys]=[values]
else:
global_dict_kpi_state_transition[keys].append(values)
for keys, values in dict_kpi_distr_state.items():
if agent == "embb-trf1":
num_ues = exp_num_ues_embb_trf1[exp]
if agent == "embb-trf2":
num_ues = exp_num_ues_embb_trf2[exp]
if agent == "urllc-trf1":
num_ues = exp_num_ues_urllc_trf1[exp]
if agent == "urllc-trf2":
num_ues = exp_num_ues_urllc_trf2[exp]
##^^ Inclusion into the global dictionary
if keys not in global_dict_kpi_distr_state:
global_dict_kpi_distr_state[keys] = [{num_ues:values}]
else:
global_dict_kpi_distr_state[keys].append({num_ues:values})
##^^ cleaning structures
dict_kpi_state_transition.clear()
dict_kpi_distr_state.clear()
#^ full print of the created structures
# printFullGraphwithKPIs(global_dict_kpi_state_transition, global_dict_kpi_distr_state, agent)
return global_dict_kpi_state_transition, global_dict_kpi_distr_state
"""
NOTES
- Regarding the "global_dict_kpi_state_transition," this structure is useful only to create the edges of the graph
hence, for cases where for each edge there are multiple elements (i.e., two or more experiments have the same edge)
"""
def visualizeGraph(global_dict_kpi_state_transition,global_dict_kpi_distr_state,agent):
"""
-
Parameters
_______________
global_dict_kpi_state_transition:
global_dict_kpi_distr_state:
agent: self-explicative
Output
_______________
"""
##^^ Function variables
outdir="../results/graphs-agents/"+str(agent)+"/"
filetitle = outdir+"g-"+str(agent)
filename = filetitle+".gv"
##^^ Creating the graph
f = graphviz.Digraph(filetitle, filename=filename) #,engine='neato'
for el in global_dict_kpi_distr_state.keys():
# print(el)
el = str(el)[1:-1]
f.node(str(el))
for keys, values in global_dict_kpi_state_transition.items():
from_state, to_state = getFromToStates(keys)
from_state = str(from_state)[1:-1]
to_state = str(to_state)[1:-1]
# print(f'From {from_state} to {to_state} - {keys}')
f.edge(from_state,to_state)
dotfile = filetitle + ".dot"
f.render(filename=dotfile)
def plotTransitionEffectOnKPIs(sl0_df,sl1_df,sl2_df, agent, TikZExp=False):
"""
The function makes the plots of Figure 7, those that show how two KPIs at a time
vary according to the labels we have given to the current transition
(same-PRB, same-sched, distinct, self)
-
Parameters
_______________
three pandas dataframes, one per slice with columns:
(trans tx_brate tx_pkts dl_buffer trans_cls)
Output
_______________
"""
outdir="../results/plots-interpretation-agents/"+str(agent)+"/"
#^ medoids computation
classes = ['same-prbs', 'same-pol', 'distinct', 'self']
#^ Plot of tx_brate vs dl_buffer
fig,(ax0,ax1,ax2) = plt.subplots(nrows=1,ncols=3,squeeze=True,figsize=(10,4))
#^ first pair: tx_brate and dl_buffer
txbrate_dlbuff_medoids_sl0 = []
txbrate_dlbuff_medoids_sl1 = []
txbrate_dlbuff_medoids_sl2 = []
for i, cl in enumerate(classes):
medoid_i_sl0 = computeMedoid(sl0_df['tx_brate'][(sl0_df.trans_cls == cl)], sl0_df['dl_buffer'][(sl0_df.trans_cls == cl)])
medoid_i_sl1 = computeMedoid(sl1_df['tx_brate'][(sl1_df.trans_cls == cl)], sl1_df['dl_buffer'][(sl1_df.trans_cls == cl)])
medoid_i_sl2 = computeMedoid(sl2_df['tx_brate'][(sl2_df.trans_cls == cl)], sl2_df['dl_buffer'][(sl2_df.trans_cls == cl)])
# print(f'TXBRATE vs DL_BUFFER: Medoid {cl}: {medoid_i_sl0[0]},{medoid_i_sl0[1]} ({i})')
txbrate_dlbuff_medoids_sl0.append(medoid_i_sl0)
txbrate_dlbuff_medoids_sl1.append(medoid_i_sl1)
txbrate_dlbuff_medoids_sl2.append(medoid_i_sl2)
#^ second pair: tx_packets and dl_buffer
txpkts_dlbuff_medoids_sl0 = []
txpkts_dlbuff_medoids_sl1 = []
txpkts_dlbuff_medoids_sl2 = []
for i, cl in enumerate(classes):
medoid_i_sl0 = computeMedoid(sl0_df['tx_pkts'][(sl0_df.trans_cls == cl)], sl0_df['dl_buffer'][(sl0_df.trans_cls == cl)])
medoid_i_sl1 = computeMedoid(sl1_df['tx_pkts'][(sl1_df.trans_cls == cl)], sl1_df['dl_buffer'][(sl1_df.trans_cls == cl)])
medoid_i_sl2 = computeMedoid(sl2_df['tx_pkts'][(sl2_df.trans_cls == cl)], sl2_df['dl_buffer'][(sl2_df.trans_cls == cl)])
# print(f'TX_PKTS vs DL_BUFFER: Medoid {cl}: {medoid_i_sl0[0]},{medoid_i_sl0[1]} ({i})')
txpkts_dlbuff_medoids_sl0.append(medoid_i_sl0)
txpkts_dlbuff_medoids_sl1.append(medoid_i_sl1)
txpkts_dlbuff_medoids_sl2.append(medoid_i_sl2)
#^ third pair: tx_brate and tx_packets
txbrate_txpkts_medoids_sl0 = []
txbrate_txpkts_medoids_sl1 = []
txbrate_txpkts_medoids_sl2 = []
for i, cl in enumerate(classes):
medoid_i_sl0 = computeMedoid(sl0_df['tx_brate'][(sl0_df.trans_cls == cl)], sl0_df['tx_pkts'][(sl0_df.trans_cls == cl)])
medoid_i_sl1 = computeMedoid(sl1_df['tx_brate'][(sl1_df.trans_cls == cl)], sl1_df['tx_pkts'][(sl1_df.trans_cls == cl)])
medoid_i_sl2 = computeMedoid(sl2_df['tx_brate'][(sl2_df.trans_cls == cl)], sl2_df['tx_pkts'][(sl2_df.trans_cls == cl)])
# print(f'tx_brate vs TX_PKTS: Medoid {cl}: {medoid_i_sl0[0]},{medoid_i_sl0[1]} ({i})')
txbrate_txpkts_medoids_sl0.append(medoid_i_sl0)
txbrate_txpkts_medoids_sl1.append(medoid_i_sl1)
txbrate_txpkts_medoids_sl2.append(medoid_i_sl2)
#^ SL0
ax0.set(xlabel='SL0', ylabel='DL buffer size')
ax0.scatter(txbrate_dlbuff_medoids_sl0[0][0], txbrate_dlbuff_medoids_sl0[0][1],
marker='x',
color='blue',
label='same-prbs')
ax0.scatter(txbrate_dlbuff_medoids_sl0[1][0], txbrate_dlbuff_medoids_sl0[1][1],
marker='s',
color='green',
label='same-pol')
ax0.scatter(txbrate_dlbuff_medoids_sl0[2][0], txbrate_dlbuff_medoids_sl0[2][1],
marker='*',
color='orange',
label='distinct')
ax0.scatter(sl0_df['tx_brate'][(sl0_df.trans_cls == 'self')], sl0_df['dl_buffer'][(sl0_df.trans_cls == 'self')],
marker='D',
color='red',
label='self')
#^ SL1
ax1.set(xlabel='SL1\n tx_brate')
ax1.scatter(txbrate_dlbuff_medoids_sl1[0][0], txbrate_dlbuff_medoids_sl1[0][1],
marker='x',
color='blue',
label='same-prbs')
ax1.scatter(txbrate_dlbuff_medoids_sl1[1][0], txbrate_dlbuff_medoids_sl1[1][1],
marker='s',
color='green',
label='same-pol')
ax1.scatter(txbrate_dlbuff_medoids_sl1[2][0], txbrate_dlbuff_medoids_sl1[2][1],
marker='*',
color='orange',
label='distinct')
ax1.scatter(sl1_df['tx_brate'][(sl1_df.trans_cls == 'self')], sl1_df['dl_buffer'][(sl1_df.trans_cls == 'self')],
marker='D',
color='red',
label='self')
#^ SL2
ax2.set(xlabel='SL2')
ax2.scatter(txbrate_dlbuff_medoids_sl2[0][0], txbrate_dlbuff_medoids_sl2[0][1],
marker='x',
color='blue',
label='same-prbs')
ax2.scatter(txbrate_dlbuff_medoids_sl2[1][0], txbrate_dlbuff_medoids_sl2[1][1],
marker='s',
color='green',
label='same-pol')
ax2.scatter(txbrate_dlbuff_medoids_sl2[2][0], txbrate_dlbuff_medoids_sl2[2][1],
marker='*',
color='orange',
label='distinct')
ax2.scatter(sl2_df['tx_brate'][(sl2_df.trans_cls == 'self')], sl2_df['dl_buffer'][(sl2_df.trans_cls == 'self')],
marker='D',
color='red',
label='self')
plt.legend(ncol=4, bbox_to_anchor=[0.3, 1.15])
fig.subplots_adjust(top=0.9,bottom=0.15)
filename = outdir + "tx_brate-vs-dl_buffer"
if TikZExp:
full_filename = filename + ".tex"
tikzplotlib.save(full_filename)
else:
full_filename = filename + ".png"
plt.show()
plt.savefig(full_filename)
plt.close()
#^ Plot of tx_brate vs tx_pkts
fig,(ax0,ax1,ax2) = plt.subplots(nrows=1,ncols=3,squeeze=True,figsize=(10,4))
#^ SL0
ax0.set(xlabel='SL0', ylabel='tx_pkts')
ax0.scatter(txbrate_txpkts_medoids_sl0[0][0], txbrate_txpkts_medoids_sl0[0][1],
marker='x',
color='blue',
label='same-prbs')
ax0.scatter(txbrate_txpkts_medoids_sl0[1][0], txbrate_txpkts_medoids_sl0[1][1],
marker='s',
color='green',
label='same-pol')
ax0.scatter(txbrate_txpkts_medoids_sl0[2][0], txbrate_txpkts_medoids_sl0[2][1],
marker='*',
color='orange',
label='distinct')
ax0.scatter(sl0_df['tx_brate'][(sl0_df.trans_cls == 'self')], sl0_df['tx_pkts'][(sl0_df.trans_cls == 'self')],
marker='D',
color='red',
label='self')
#^ SL1
ax1.set(xlabel='SL1\n tx_brate')
ax1.scatter(txbrate_txpkts_medoids_sl1[0][0], txbrate_txpkts_medoids_sl1[0][1],
marker='x',
color='blue',
label='same-prbs')
ax1.scatter(txbrate_txpkts_medoids_sl1[1][0], txbrate_txpkts_medoids_sl1[1][1],
marker='s',
color='green',
label='same-pol')
ax1.scatter(txbrate_txpkts_medoids_sl1[2][0], txbrate_txpkts_medoids_sl1[2][1],
marker='*',
color='orange',
label='distinct')
ax1.scatter(sl1_df['tx_brate'][(sl1_df.trans_cls == 'self')], sl1_df['tx_pkts'][(sl1_df.trans_cls == 'self')],
marker='D',
color='red',
label='self')
#^ SL2
ax2.set(xlabel='SL2')
ax2.scatter(txbrate_txpkts_medoids_sl2[0][0], txbrate_txpkts_medoids_sl2[0][1],
marker='x',
color='blue',
label='same-prbs')
ax2.scatter(txbrate_txpkts_medoids_sl2[1][0], txbrate_txpkts_medoids_sl2[1][1],
marker='s',
color='green',
label='same-pol')
ax2.scatter(txbrate_txpkts_medoids_sl2[2][0], txbrate_txpkts_medoids_sl2[2][1],
marker='*',
color='orange',
label='distinct')
ax2.scatter(sl2_df['tx_brate'][(sl2_df.trans_cls == 'self')], sl2_df['tx_pkts'][(sl2_df.trans_cls == 'self')],
marker='D',
color='red',
label='self')
plt.legend(ncol=4, bbox_to_anchor=[0.3, 1.15])
fig.subplots_adjust(top=0.9,bottom=0.15)
filename = outdir + "tx_brate-vs-tx_pkts"
if TikZExp:
full_filename = filename + ".tex"
tikzplotlib.save(full_filename)
else:
full_filename = filename + ".png"
plt.show()
plt.savefig(full_filename)
plt.close()
#^ Plot of tx_pkts vs dl_buffer
fig,(ax0,ax1,ax2) = plt.subplots(nrows=1,ncols=3,squeeze=True,figsize=(10,4))
#^ SL0
ax0.set(xlabel='SL0', ylabel='DL buffer size')
ax0.scatter(sl0_df['tx_pkts'][(sl0_df.trans_cls == 'same-prbs')], sl0_df['dl_buffer'][(sl0_df.trans_cls == 'same-prbs')],
marker='x',
color='blue',
label='same-prbs')
ax0.scatter(sl0_df['tx_pkts'][(sl0_df.trans_cls == 'self')], sl0_df['dl_buffer'][(sl0_df.trans_cls == 'self')],
marker='D',
color='red',
label='self')
ax0.scatter(sl0_df['tx_pkts'][(sl0_df.trans_cls == 'same-pol')], sl0_df['dl_buffer'][(sl0_df.trans_cls == 'same-pol')],
marker='s',
color='green',
label='same-pol')
ax0.scatter(sl0_df['tx_pkts'][(sl0_df.trans_cls == 'distinct')], sl0_df['dl_buffer'][(sl0_df.trans_cls == 'distinct')],
marker='*',
color='orange',
label='distinct')
#^ SL1
ax1.set(xlabel='SL1\n tx_pkts')
ax1.set_xlim([min(sl1_df['tx_pkts']), max(sl1_df['tx_pkts'])])
ax1.set_ylim([min(sl1_df['dl_buffer']), max(sl1_df['dl_buffer'])])
ax1.scatter(sl1_df['tx_pkts'][(sl1_df.trans_cls == 'same-prbs')], sl1_df['dl_buffer'][(sl1_df.trans_cls == 'same-prbs')],
marker='x',
color='blue',
label='same-prbs')
ax1.scatter(sl1_df['tx_pkts'][(sl1_df.trans_cls == 'same-pol')], sl1_df['dl_buffer'][(sl1_df.trans_cls == 'same-pol')],
marker='s',
color='green',
label='same-pol')
ax1.scatter(sl1_df['tx_pkts'][(sl1_df.trans_cls == 'distinct')], sl1_df['dl_buffer'][(sl1_df.trans_cls == 'distinct')],
marker='*',
color='orange',
label='distinct')
ax1.scatter(sl1_df['tx_pkts'][(sl1_df.trans_cls == 'self')], sl1_df['dl_buffer'][(sl1_df.trans_cls == 'self')],
marker='D',
color='red',
label='self')
#^ SL2
ax2.set(xlabel='SL2')
ax2.set_xlim([min(sl2_df['tx_pkts']), max(sl2_df['tx_pkts'])])
ax2.set_ylim([min(sl2_df['dl_buffer']), max(sl2_df['dl_buffer'])])
ax2.scatter(sl2_df['tx_pkts'][(sl2_df.trans_cls == 'same-prbs')], sl2_df['dl_buffer'][(sl2_df.trans_cls == 'same-prbs')],
marker='x',
color='blue',
label='same-prbs')
ax2.scatter(sl2_df['tx_pkts'][(sl2_df.trans_cls == 'same-pol')], sl2_df['dl_buffer'][(sl2_df.trans_cls == 'same-pol')],
marker='s',
color='green',
label='same-pol')
ax2.scatter(sl2_df['tx_pkts'][(sl2_df.trans_cls == 'distinct')], sl2_df['dl_buffer'][(sl2_df.trans_cls == 'distinct')],
marker='*',
color='orange',
label='distinct')
ax2.scatter(sl2_df['tx_pkts'][(sl2_df.trans_cls == 'self')], sl2_df['dl_buffer'][(sl2_df.trans_cls == 'self')],
marker='D',
color='red',
label='self')
plt.legend(ncol=4, bbox_to_anchor=[0.3, 1.15])
fig.subplots_adjust(top=0.9,bottom=0.15)
filename = outdir + "tx_pkts-vs-dl_buffer"
if TikZExp:
full_filename = filename + ".tex"
tikzplotlib.save(full_filename)
else:
full_filename = filename + ".png"
plt.show()
plt.savefig(full_filename)
plt.close()
def createDTonGraph(sl0_df,sl1_df,sl2_df, agent, ExportTree=False):
"""
The function makes the plots of Figure 7, those that show how two KPIs at a time
vary according to the labels we have given to the current transition
(same-PRB, same-sched, distinct, self)
-
Parameters
_______________
three pandas dataframes, one per slice with columns:
(trans tx_brate tx_pkts dl_buffer trans_cls)
agent: current agent under analysis
ExportTree: to save the generated figure
Output
_______________
"""
outdir="../results/dts-interpretations/"+str(agent)+"/"
transition_classes = ['same-PRB', 'same-sched', 'distinct', 'self']
list_of_dfs = [sl0_df,sl1_df,sl2_df]
##^^ Printing the panda dataframes
# for slice in {0,1,2}:
# print(f'---\n Slice {slice}\n {list_of_dfs[slice]}')
##^^ buildling DTs per slice
for sl_idx in range (0,3):
df_considered = list_of_dfs[sl_idx]
slice_tree_filename = outdir+"slice-"+str(sl_idx)+"_tree.png"
df_considered["trans"] = df_considered["trans"].astype(str)
# print(slice_tree_filename)
feature_cols = ['tx_brate', 'dl_buffer'] #['tx_brate', 'tx_pkts'] #, 'dl_buffer']
X = df_considered[feature_cols] # Features
y = df_considered.trans_cls # Target variable
#^ Split dataset into training set and test set
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1) # 70% training and 30% test
# print(f'Lens: Train {len(X_train)}, Test {len(X_test)}, - Y train {len(y_train)}, test {len(y_test)}')
#^ Create Decision Tree classifer object
clf = DecisionTreeClassifier()
#^ Train Decision Tree Classifer
clf = clf.fit(X_train,y_train)
#^ Predict the response for test dataset
y_pred = clf.predict(X_test)
#^ Model Accuracy, how often is the classifier correct?
# print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
if ExportTree:
dot_data = StringIO()
export_graphviz(clf, out_file=dot_data,
filled=True, rounded=True,
special_characters=True,
feature_names = feature_cols,
class_names = transition_classes
)
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
graph.write_png(slice_tree_filename)
Image(graph.create_png())
def analysisAgentBehavior(global_dict_kpi_state_transition,global_dict_kpi_distr_state,agent):
"""
Note: same traffic scenario means that we do this for experiments with different number of users
-
Parameters
_______________
Output
_______________
"""
print(f'Current set of experiments under analysis: {agent} \n-------')
#^ dataframes for each slice
cols = ['trans','tx_brate', 'tx_pkts', 'dl_buffer', 'trans_cls']
sl0_df = pd.DataFrame([],columns=cols)
sl1_df = pd.DataFrame([],columns=cols)
sl2_df = pd.DataFrame([],columns=cols)
#^ this is to count statistics on the type of transitions
dict_classes_stats = {}
##^^ iteratate over all the possible transitions:
for keys, values in global_dict_kpi_state_transition.items():
#^ get FROM and TO states
from_state, to_state = getFromToStates(keys)
#^ get PRBs and Pol of both FROM and TO states
from_state_prbs, from_state_pol = getFromPRBPol(from_state)
to_state_prbs, to_state_pol = getFromPRBPol(to_state)
#^ classes of transitions:
transition_class = None
if from_state_prbs == to_state_prbs and from_state_pol == to_state_pol:
transition_class = "self"
elif from_state_prbs == to_state_prbs and from_state_pol != to_state_pol:
transition_class = "same-prbs"
elif from_state_prbs != to_state_prbs and from_state_pol == to_state_pol:
transition_class = "same-pol"
elif from_state_prbs != to_state_prbs and from_state_pol != to_state_pol:
transition_class = "distinct"
# print(f'From {from_state} to {to_state} - Class: {transition_class}')
#^ adding to the stats
if transition_class not in dict_classes_stats:
dict_classes_stats[transition_class] = 1
else:
dict_classes_stats[transition_class] += 1
#^ get the KPIs from global_dict_kpi_distr_state
from_state_kpi = global_dict_kpi_distr_state[tuple(from_state)]
to_state_kpi = global_dict_kpi_distr_state[tuple(to_state)]
#^ iterate first over the "FROM" state
for el_fs in from_state_kpi:
for el_f, el_f_values in el_fs.items():
#^ variables to compare the KPIs (tx brate, tx pkts, dl buffer) per slice
from_kpis_values_sl0 = None
from_kpis_values_sl1 = None
from_kpis_values_sl2 = None
#^ now I access the from values and store them
list_of_sl = ["SL0","SL1","SL2"]
for sl in list_of_sl:
value = el_f_values[sl]
if sl == "SL0":
from_kpis_values_sl0 = value
if sl == "SL1":
from_kpis_values_sl1 = value
if sl == "SL2":
from_kpis_values_sl2 = value
#^ for each of the FROM elements, take a look if we can find the correspondent num. of users in the TO state
# if yes: pick the KPIs as well to compare
for el_ts in to_state_kpi:
for el_t, el_t_values in el_ts.items():
#^ if the two are equal, then we can make the comparison
if el_t == el_f:
to_kpis_values_sl0 = None
to_kpis_values_sl1 = None
to_kpis_values_sl2 = None
for sl in list_of_sl:
value = el_t_values[sl]
if sl == "SL0":
to_kpis_values_sl0 = value
#^ adding to the df sl0_df
sl0_df.loc[len(sl0_df)] = {'trans': keys,
'tx_brate':round(from_kpis_values_sl0.avg_tx_brate-to_kpis_values_sl0.avg_tx_brate,2),
'tx_pkts':round(from_kpis_values_sl0.avg_tx_pkts-to_kpis_values_sl0.avg_tx_pkts,2),
'dl_buffer':round(from_kpis_values_sl0.avg_dl_buffer-to_kpis_values_sl0.avg_dl_buffer,2),
'trans_cls':transition_class}
if sl == "SL1":
to_kpis_values_sl1 = value
#^ adding to the df sl0_df
sl1_df.loc[len(sl1_df)] ={'trans': keys,
'tx_brate':round(from_kpis_values_sl1.avg_tx_brate-to_kpis_values_sl1.avg_tx_brate,2),
'tx_pkts':round(from_kpis_values_sl1.avg_tx_pkts-to_kpis_values_sl1.avg_tx_pkts,2),
'dl_buffer':round(from_kpis_values_sl1.avg_dl_buffer-to_kpis_values_sl1.avg_dl_buffer,2),
'trans_cls':transition_class}
if sl == "SL2":
to_kpis_values_sl2 = value
#^ adding to the df sl0_df
sl2_df.loc[len(sl2_df)] = {'trans': keys,
'tx_brate':round(from_kpis_values_sl2.avg_tx_brate-to_kpis_values_sl2.avg_tx_brate,2),
'tx_pkts':round(from_kpis_values_sl2.avg_tx_pkts-to_kpis_values_sl2.avg_tx_pkts,2),
'dl_buffer':round(from_kpis_values_sl2.avg_dl_buffer-to_kpis_values_sl2.avg_dl_buffer,2),
'trans_cls':transition_class}
##^ At this point we have all the info to compare the KPIs of one transition of one experiment
# print(f'SL0: tx_brate ({from_kpis_values_sl0.avg_tx_brate} {to_kpis_values_sl0.avg_tx_brate}) {round(from_kpis_values_sl0.avg_tx_brate-to_kpis_values_sl0.avg_tx_brate,2)}\
# tx_pkts ({from_kpis_values_sl0.avg_tx_pkts} {to_kpis_values_sl0.avg_tx_pkts}) {round(from_kpis_values_sl0.avg_tx_pkts-to_kpis_values_sl0.avg_tx_pkts,2)}\
# dl_buffer ({from_kpis_values_sl0.avg_dl_buffer} {to_kpis_values_sl0.avg_dl_buffer}) {round(from_kpis_values_sl0.avg_dl_buffer-to_kpis_values_sl0.avg_dl_buffer,2)}')
# print(f'SL1: tx_brate ({from_kpis_values_sl1.avg_tx_brate} {to_kpis_values_sl1.avg_tx_brate}) {round(from_kpis_values_sl1.avg_tx_brate-to_kpis_values_sl1.avg_tx_brate,2)}\
# tx_pkts ({from_kpis_values_sl1.avg_tx_pkts} {to_kpis_values_sl1.avg_tx_pkts}) {round(from_kpis_values_sl1.avg_tx_pkts-to_kpis_values_sl1.avg_tx_pkts,2)}\
# dl_buffer ({from_kpis_values_sl1.avg_dl_buffer} {to_kpis_values_sl1.avg_dl_buffer}) {round(from_kpis_values_sl1.avg_dl_buffer-to_kpis_values_sl1.avg_dl_buffer,2)}')
# print(f'SL2: tx_brate ({from_kpis_values_sl2.avg_tx_brate} {to_kpis_values_sl2.avg_tx_brate}) {round(from_kpis_values_sl2.avg_tx_brate-to_kpis_values_sl2.avg_tx_brate,2)}\
# tx_pkts ({from_kpis_values_sl2.avg_tx_pkts} {to_kpis_values_sl2.avg_tx_pkts}) {round(from_kpis_values_sl2.avg_tx_pkts-to_kpis_values_sl2.avg_tx_pkts,2)}\
# dl_buffer ({from_kpis_values_sl2.avg_dl_buffer} {to_kpis_values_sl2.avg_dl_buffer}) {round(from_kpis_values_sl2.avg_dl_buffer-to_kpis_values_sl2.avg_dl_buffer,2)}')
# print()
##^^ at this stage, all the information is collected: for each slice, we know for each transition the KPI variation
plotTransitionEffectOnKPIs(sl0_df,sl1_df,sl2_df,agent,TikZExp=False)# use this one to plot
createDTonGraph(sl0_df,sl1_df,sl2_df, agent, ExportTree=True)# use this one to create a DT that analyzes the explanations
#^ exporting the stats on the transitions
print("Stats. on classes of actions:")
tot_items = sum(dict_classes_stats.values())
for k,v in dict_classes_stats.items():
print(f'{k}: {v} | {round((v/tot_items)*100,2)}%')
if __name__ == "__main__":
##^^ Analysis for to retrieve interpretations
#^ defining the data structures: list_exp_<agent> makes it possible to run all experiments at once
g_d_kpi_state_transition_embb_trf1, g_d_kpi_distr_state_embb_trf1 = processExperiments(list_exp_embb_trf1,agent_embb_trf1)
g_d_kpi_state_transition_embb_trf2, g_d_kpi_distr_state_embb_trf2 = processExperiments(list_exp_embb_trf2,agent_embb_trf2)
g_d_kpi_state_transition_urllc_trf1, g_d_kpi_distr_state_urllc_trf1 = processExperiments(list_exp_urllc_trf1,agent_urllc_trf1)
g_d_kpi_state_transition_urllc_trf2, g_d_kpi_distr_state_urllc_trf2 = processExperiments(list_exp_urllc_trf2,agent_urllc_trf2)
exp_selection = {"embb-trf1":[g_d_kpi_state_transition_embb_trf1,g_d_kpi_distr_state_embb_trf1],
"embb-trf2":[g_d_kpi_state_transition_embb_trf2,g_d_kpi_distr_state_embb_trf2],
"urllc-trf1":[g_d_kpi_state_transition_urllc_trf1,g_d_kpi_distr_state_urllc_trf1],
"urllc-trf2":[g_d_kpi_state_transition_urllc_trf2,g_d_kpi_distr_state_urllc_trf2],
}
#^ choose: 0 for "embb-trf1", 1 for "embb-trf2", 2 for "urllc-trf1", and 3 for "urllc-trf2"
agent = list(exp_selection.keys())[2]
# configures the proper structures to be analyzed
g_d_kpi_state_trans = exp_selection[agent][0]
g_d_kpi_distr_state = exp_selection[agent][1]
#^ visualizes and characterizes the graph without attributes (only NODES, i.e., actions)
visualizeGraph(g_d_kpi_state_trans,g_d_kpi_distr_state,agent)
#^ analysis to synthesize explanations in form of plots that highlight effect of transitions on two KPIs at a time
analysisAgentBehavior(g_d_kpi_state_trans,g_d_kpi_distr_state,agent)
#^ clearing the data structures
g_d_kpi_state_trans.clear()
g_d_kpi_distr_state.clear()
print("-- Finished main --")