aboutsummaryrefslogtreecommitdiffstats
path: root/Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py
diff options
context:
space:
mode:
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.py46
1 files changed, 30 insertions, 16 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 02f28546..af231a98 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
@@ -24,15 +24,14 @@ def main():
24 # a hack to make the node type as the same as an exiting model 24 # a hack to make the node type as the same as an exiting model
25 type_rep = GraphCollection('../input/measurement2/yakindu/Human/od_rep/', 1, 'rep') 25 type_rep = GraphCollection('../input/measurement2/yakindu/Human/od_rep/', 1, 'rep')
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}] 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 # type_rep.nts = [{'EAttribute': 0.23539778449144008, 'EClass': 0.30996978851963747, 'EReference': 0.33081570996978854, 'EPackage': 0.012789526686807653, 'EAnnotation': 0.002517623363544813, 'EEnumLiteral': 0.07275931520644502, 'EEnum': 0.013645518630412891, 'EDataType': 0.004028197381671702, 'EParameter': 0.005941591137965764, 'EGenericType': 0.002014098690835851, 'EOperation': 0.009415911379657605, 'ETypeParameter': 0.0007049345417925478}]
27 types = sorted(type_rep.nts[0].keys()) 28 types = sorted(type_rep.nts[0].keys())
28 29
29 # random = GraphCollection('../input/randomOutput/', 500, 'Random') 30 models_to_compare_na = [human, alloy, base, real, random, na_rep]
30 # alloy = GraphCollection('../input/alloy/', 500, 'Alloy (30 nodes)') 31 models_to_compare_mpc = [human, alloy, base, real, random, mpc_rep]
31 # realistic_viatra = GraphCollection('../input/viatra_output_consistent_100/', 50, 'Realistic Viatra With Some Constraints (100 nodes)') 32 models_to_compare_od = [human, alloy, base, real, random, od_rep]
32 models_to_compare_na = [human, alloy,base, real, random, na_rep] 33 models_to_compare_nt = [human, alloy, base, real, random, type_rep]
33 models_to_compare_mpc = [human, alloy,base, real, random, mpc_rep] 34
34 models_to_compare_od = [human, alloy,base, real, random, od_rep]
35 models_to_compare_nt = [human, alloy,base, real, random, type_rep]
36 for modelCollection in models_to_compare_nt: 35 for modelCollection in models_to_compare_nt:
37 type_dists = [] 36 type_dists = []
38 for nt in modelCollection.nts: 37 for nt in modelCollection.nts:
@@ -44,13 +43,13 @@ def main():
44 43
45 44
46 # define output folder 45 # define output folder
47 outputFolder = '../output/' 46 outputFolder = '../output/yakindu/'
48 47
49 #calculate metrics 48 #calculate metrics
50 # metricStat(models_to_compare_na, 'Node_Activity', nodeActivity, 0, outputFolder) 49 metricStat(models_to_compare_na, 'Node_Activity', nodeActivity, 0, outputFolder, calculateKSMatrix)
51 metricStat(models_to_compare_od, 'Out_Degree', outDegree, 1, outputFolder) 50 metricStat(models_to_compare_od, 'Out_Degree', outDegree, 1, outputFolder, calculateKSMatrix)
52 # metricStat(models_to_compare_mpc, 'MPC', mpc, 2, outputFolder) 51 metricStat(models_to_compare_mpc, 'MPC', mpc, 2, outputFolder, calculateKSMatrix)
53 # metricStat(models_to_compare_nt, 'Node Types', nodeType, 3, outputFolder) 52 metricStat(models_to_compare_nt, 'Node_Types', nodeType, 3, outputFolder, calculateManualKSMatrix)
54 53
55def calculateKSMatrix(dists): 54def calculateKSMatrix(dists):
56 dist = [] 55 dist = []
@@ -67,6 +66,21 @@ def calculateKSMatrix(dists):
67 matrix[j, i] = value 66 matrix[j, i] = value
68 return matrix 67 return matrix
69 68
69def calculateManualKSMatrix(dists):
70 dist = []
71
72 for i in range(len(dists)):
73 dist = dist + dists[i]
74 matrix = np.empty((len(dist),len(dist)))
75
76 for i in range(len(dist)):
77 matrix[i,i] = 0
78 for j in range(i+1, len(dist)):
79 value = metrics.manual_ks(dist[i], dist[j])
80 matrix[i, j] = value
81 matrix[j, i] = value
82 return matrix
83
70 84
71def calculateMDS(dissimilarities): 85def calculateMDS(dissimilarities):
72 embedding = MDS(n_components=2, dissimilarity='precomputed') 86 embedding = MDS(n_components=2, dissimilarity='precomputed')
@@ -74,8 +88,8 @@ def calculateMDS(dissimilarities):
74 return trans 88 return trans
75 89
76def plot(graphTypes, coords, title='',index = 0, savePath = ''): 90def plot(graphTypes, coords, title='',index = 0, savePath = ''):
77 color = ['blue', 'm', 'gold', 'green', 'k', 'red'] 91 color = ['blue' , 'm', 'gold', 'green', 'k', 'red']
78 markers = ['o', 'v', '+', 'x', '^', '*'] 92 markers = ['o', 'v','+', 'x', '^', '*']
79 plt.figure(index, figsize=(5, 4)) 93 plt.figure(index, figsize=(5, 4))
80 # plt.title(title) 94 # plt.title(title)
81 index = 0 95 index = 0
@@ -101,14 +115,14 @@ def mkdir_p(mypath):
101 pass 115 pass
102 else: raise 116 else: raise
103 117
104def metricStat(graphTypes, metricName, metric, graphIndex, outputFolder): 118def metricStat(graphTypes, metricName, metric, graphIndex, outputFolder, matrix_calculator):
105 metrics = [] 119 metrics = []
106 for graph in graphTypes: 120 for graph in graphTypes:
107 metrics.append(metric(graph)) 121 metrics.append(metric(graph))
108 outputFolder = outputFolder + graph.name + '-' 122 outputFolder = outputFolder + graph.name + '-'
109 print('calculate' + metricName +' for ' + outputFolder) 123 print('calculate' + metricName +' for ' + outputFolder)
110 mkdir_p(outputFolder) 124 mkdir_p(outputFolder)
111 out_d_coords = calculateMDS(calculateKSMatrix(metrics)) 125 out_d_coords = calculateMDS(matrix_calculator(metrics))
112 plot(graphTypes, out_d_coords, metricName, graphIndex,outputFolder + '/'+ metricName) 126 plot(graphTypes, out_d_coords, metricName, graphIndex,outputFolder + '/'+ metricName)
113 127
114def nodeActivity(graphType): 128def nodeActivity(graphType):