diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py')
-rw-r--r-- | Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py | 71 |
1 files changed, 42 insertions, 29 deletions
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py b/Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py index eb9d4ae2..02f28546 100644 --- a/Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py | |||
@@ -12,36 +12,45 @@ import DistributionMetrics as metrics | |||
12 | 12 | ||
13 | def main(): | 13 | def main(): |
14 | # read models | 14 | # read models |
15 | human = GraphCollection('../input/human_30_500_no_xml/', 500, 'human_no_xml') | 15 | alloy = GraphCollection('../input/measurement2/yakindu/Alloy/', 100, 'Alloy') |
16 | human2 = GraphCollection('../input/human_30_500_xml/', 500, 'human_xml') | 16 | human = GraphCollection('../input/measurement2/yakindu/Human/', 304, 'Human') |
17 | # human_na = GraphCollection('../input/human_models_50_500/na_rep/', 1, 'Human rep') | 17 | base = GraphCollection('../input/measurement2/yakindu/BaseViatra/', 100, 'BaseViatra') |
18 | # human_mpc = GraphCollection('../input/human_models_50_500/mpc_rep/', 1, 'Human rep') | 18 | real = GraphCollection('../input/measurement2/yakindu/RealViatra/', 100, 'RealViatra') |
19 | # human_od = GraphCollection('../input/human_models_50_500/od_rep/', 1, 'Human rep') | 19 | random = GraphCollection('../input/measurement2/yakindu/Random/', 100, 'Random') |
20 | 20 | na_rep = GraphCollection('../input/measurement2/yakindu/Human/na_rep/', 1, 'rep') | |
21 | # viatra75 = GraphCollection('../input/viatra_75/', 500, 'Viatra (75 nodes)') | 21 | mpc_rep = GraphCollection('../input/measurement2/yakindu/Human/mpc_rep/', 1, 'rep') |
22 | # viatra30 = GraphCollection('../input/viatraOutput30/', 500,'Viatra (30 nodes)') | 22 | od_rep = GraphCollection('../input/measurement2/yakindu/Human/od_rep/', 1, 'rep') |
23 | # viatra60 = GraphCollection('../input/viatraOutput60/', 500, 'Viatra (60 nodes)') | 23 | |
24 | # viatra100 = GraphCollection('../input/viatraOutput100/', 500, 'Viatra (100 nodes)') | 24 | # a hack to make the node type as the same as an exiting model |
25 | # viatra100R = GraphCollection('../input/realisticViatraOutput_newMetric/', 500, 'Realistic Viatra (100 nodes)') | 25 | type_rep = GraphCollection('../input/measurement2/yakindu/Human/od_rep/', 1, 'rep') |
26 | # viatra100C = GraphCollection('../input/yakindumm/viatraOutput100C/', 500, 'Viatra consistent (100 nodes)') | 26 | type_rep.nts = [{'Entry': 0.04257802080554814, 'Choice': 0.1267671379034409, 'State': 0.1596092291277674, 'Transition': 0.6138636969858629, 'Statechart': 0.010136036276340358, 'Region': 0.04467858095492131, 'Exit': 0.0018338223526273673, 'FinalState': 0.0005334755934915977}] |
27 | # viatra100EE = GraphCollection('../input/realisticViatra_excludeExit/', 500, 'Realistic Viatra no Exit (100 nodes)') | 27 | types = sorted(type_rep.nts[0].keys()) |
28 | # viatra100EEF = GraphCollection('../input/realisticViatra_excludeExitFinal/', 500, 'Realistic Viatra no Exit Final (100 nodes)') | ||
29 | # viatra100NT = GraphCollection('../input/yakindumm/realisticVIatraOutput_nodeTypeKS/', 500, 'Realistic Viatra with Node Type KS (100 nodes)') | ||
30 | 28 | ||
31 | # random = GraphCollection('../input/randomOutput/', 500, 'Random') | 29 | # random = GraphCollection('../input/randomOutput/', 500, 'Random') |
32 | # alloy = GraphCollection('../input/alloy/', 500, 'Alloy (30 nodes)') | 30 | # alloy = GraphCollection('../input/alloy/', 500, 'Alloy (30 nodes)') |
33 | # realistic_viatra = GraphCollection('../input/viatra_output_consistent_100/', 50, 'Realistic Viatra With Some Constraints (100 nodes)') | 31 | # realistic_viatra = GraphCollection('../input/viatra_output_consistent_100/', 50, 'Realistic Viatra With Some Constraints (100 nodes)') |
34 | models_to_compare_na = [human, human2] | 32 | models_to_compare_na = [human, alloy,base, real, random, na_rep] |
35 | models_to_compare_mpc = [human, human2] | 33 | models_to_compare_mpc = [human, alloy,base, real, random, mpc_rep] |
36 | models_to_compare_od = [human, human2] | 34 | models_to_compare_od = [human, alloy,base, real, random, od_rep] |
37 | 35 | models_to_compare_nt = [human, alloy,base, real, random, type_rep] | |
36 | for modelCollection in models_to_compare_nt: | ||
37 | type_dists = [] | ||
38 | for nt in modelCollection.nts: | ||
39 | type_dist = [] | ||
40 | for key in types: | ||
41 | type_dist.append(nt.get(key, 0.0)) | ||
42 | type_dists.append(type_dist) | ||
43 | modelCollection.nts = type_dists | ||
44 | |||
45 | |||
38 | # define output folder | 46 | # define output folder |
39 | outputFolder = '../output/' | 47 | outputFolder = '../output/' |
40 | 48 | ||
41 | #calculate metrics | 49 | #calculate metrics |
42 | metricStat(models_to_compare_na, 'Node Activity', nodeActivity, 0, outputFolder) | 50 | # metricStat(models_to_compare_na, 'Node_Activity', nodeActivity, 0, outputFolder) |
43 | metricStat(models_to_compare_od, 'Out Degree', outDegree, 1, outputFolder) | 51 | metricStat(models_to_compare_od, 'Out_Degree', outDegree, 1, outputFolder) |
44 | metricStat(models_to_compare_mpc, 'MPC', mpc, 2, outputFolder) | 52 | # metricStat(models_to_compare_mpc, 'MPC', mpc, 2, outputFolder) |
53 | # metricStat(models_to_compare_nt, 'Node Types', nodeType, 3, outputFolder) | ||
45 | 54 | ||
46 | def calculateKSMatrix(dists): | 55 | def calculateKSMatrix(dists): |
47 | dist = [] | 56 | dist = [] |
@@ -65,18 +74,19 @@ def calculateMDS(dissimilarities): | |||
65 | return trans | 74 | return trans |
66 | 75 | ||
67 | def plot(graphTypes, coords, title='',index = 0, savePath = ''): | 76 | def plot(graphTypes, coords, title='',index = 0, savePath = ''): |
68 | color = ['blue', 'red', 'yellow', 'green', 'k'] | 77 | color = ['blue', 'm', 'gold', 'green', 'k', 'red'] |
69 | plt.figure(index, figsize=(7, 4)) | 78 | markers = ['o', 'v', '+', 'x', '^', '*'] |
70 | plt.title(title) | 79 | plt.figure(index, figsize=(5, 4)) |
80 | # plt.title(title) | ||
71 | index = 0 | 81 | index = 0 |
72 | for i in range(len(graphTypes)): | 82 | for i in range(len(graphTypes)): |
73 | x = (coords[index:index+graphTypes[i].size, 0].tolist()) | 83 | x = (coords[index:index+graphTypes[i].size, 0].tolist()) |
74 | y = (coords[index:index+graphTypes[i].size, 1].tolist()) | 84 | y = (coords[index:index+graphTypes[i].size, 1].tolist()) |
75 | index += graphTypes[i].size | 85 | index += graphTypes[i].size |
76 | plt.plot(x, y, color=color[i], marker='o', label = graphTypes[i].name, linestyle='', alpha=0.7) | 86 | plt.plot(x, y, color=color[i], marker=markers[i], label = graphTypes[i].name, linestyle='', alpha=0.7) |
87 | plt.savefig(fname = savePath+'.png', dpi=500) | ||
77 | plt.legend(loc='upper right') | 88 | plt.legend(loc='upper right') |
78 | plt.savefig(fname = savePath, dpi=150) | 89 | plt.savefig(fname = savePath+'_lengend.png', dpi=500) |
79 | #graph.show() | ||
80 | 90 | ||
81 | def mkdir_p(mypath): | 91 | def mkdir_p(mypath): |
82 | '''Creates a directory. equivalent to using mkdir -p on the command line''' | 92 | '''Creates a directory. equivalent to using mkdir -p on the command line''' |
@@ -99,7 +109,7 @@ def metricStat(graphTypes, metricName, metric, graphIndex, outputFolder): | |||
99 | print('calculate' + metricName +' for ' + outputFolder) | 109 | print('calculate' + metricName +' for ' + outputFolder) |
100 | mkdir_p(outputFolder) | 110 | mkdir_p(outputFolder) |
101 | out_d_coords = calculateMDS(calculateKSMatrix(metrics)) | 111 | out_d_coords = calculateMDS(calculateKSMatrix(metrics)) |
102 | plot(graphTypes, out_d_coords, metricName, graphIndex,outputFolder + '/'+ metricName+'.png') | 112 | plot(graphTypes, out_d_coords, metricName, graphIndex,outputFolder + '/'+ metricName) |
103 | 113 | ||
104 | def nodeActivity(graphType): | 114 | def nodeActivity(graphType): |
105 | return graphType.nas | 115 | return graphType.nas |
@@ -110,5 +120,8 @@ def outDegree(graphType): | |||
110 | def mpc(graphType): | 120 | def mpc(graphType): |
111 | return graphType.mpcs | 121 | return graphType.mpcs |
112 | 122 | ||
123 | def nodeType(graphType): | ||
124 | return graphType.nts | ||
125 | |||
113 | if __name__ == '__main__': | 126 | if __name__ == '__main__': |
114 | main() \ No newline at end of file | 127 | main() \ No newline at end of file |