aboutsummaryrefslogtreecommitdiffstats
path: root/Metrics/Metrics-Calculation/metrics_plot/src/plot_ks_stats.py
diff options
context:
space:
mode:
Diffstat (limited to 'Metrics/Metrics-Calculation/metrics_plot/src/plot_ks_stats.py')
-rw-r--r--Metrics/Metrics-Calculation/metrics_plot/src/plot_ks_stats.py90
1 files changed, 0 insertions, 90 deletions
diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/plot_ks_stats.py b/Metrics/Metrics-Calculation/metrics_plot/src/plot_ks_stats.py
deleted file mode 100644
index ad72a4a1..00000000
--- a/Metrics/Metrics-Calculation/metrics_plot/src/plot_ks_stats.py
+++ /dev/null
@@ -1,90 +0,0 @@
1import glob
2import random
3from sklearn.manifold import MDS
4import matplotlib.pyplot as plt
5from scipy import stats
6import numpy as np
7from GraphType import GraphCollection
8
9def calculateKSMatrix(dists):
10 dist = []
11
12 for i in range(len(dists)):
13 dist = dist + dists[i]
14 matrix = np.empty((len(dist),len(dist)))
15
16 for i in range(len(dist)):
17 matrix[i,i] = 0
18 for j in range(i+1, len(dist)):
19 value, p = stats.ks_2samp(dist[i], dist[j])
20 matrix[i, j] = value
21 matrix[j, i] = value
22 return matrix
23
24
25def calculateMDS(dissimilarities):
26 embedding = MDS(n_components=2, dissimilarity='precomputed')
27 trans = embedding.fit_transform(X=dissimilarities)
28 return trans
29
30def plot(graphTypes, coords, title='',index = 0, savePath = ''):
31 half_length = int(coords.shape[0] / len(graphTypes))
32 color = ['blue', 'red', 'green', 'yellow']
33 lineStyle = ['', '-']
34 plt.figure(index, figsize=(7, 4))
35 plt.title(title)
36 for i in range(len(graphTypes)):
37 x = (coords[(i*half_length):((i+1)*half_length), 0].tolist())
38 y = (coords[(i*half_length):((i+1)*half_length), 1].tolist())
39 plt.plot(x, y, color=color[i], marker='o', label = graphTypes[i].name, linestyle=lineStyle[i], alpha=0.7)
40 plt.legend(loc='upper right')
41 plt.savefig(fname = savePath, dpi=150)
42 #graph.show()
43
44def mkdir_p(mypath):
45 '''Creates a directory. equivalent to using mkdir -p on the command line'''
46
47 from errno import EEXIST
48 from os import makedirs,path
49
50 try:
51 makedirs(mypath)
52 except OSError as exc: # Python >2.5
53 if exc.errno == EEXIST and path.isdir(mypath):
54 pass
55 else: raise
56
57def metricStat(graphTypes, metricName, metric, graphIndex):
58 metrics = []
59 foldName = '../output/'
60 for graph in graphTypes:
61 metrics.append(metric(graph))
62 foldName = foldName + graph.name + '-'
63 print('calculate' + metricName +' for ' + foldName)
64 mkdir_p(foldName)
65 out_d_coords = calculateMDS(calculateKSMatrix(metrics))
66 plot(graphTypes, out_d_coords, metricName, graphIndex,foldName + '/'+ metricName+'.png')
67
68def nodeActivity(graphType):
69 return graphType.nas
70
71def outDegree(graphType):
72 return graphType.out_ds
73
74def mpc(graphType):
75 return graphType.mpcs
76
77
78# read models
79human = GraphCollection('../statistics/humanOutput/', 500, 'Human')
80# viatra30 = GraphCollection('../statistics/viatraOutput30/', 500, 'Viatra (30 nodes)')
81# viatra60 = GraphCollection('../statistics/viatraOutput60/', 500, 'Viatra (60 nodes)')
82# viatra100 = GraphCollection('../statistics/viatraOutput100/', 500, 'Viatra (100 nodes)')
83# random = GraphCollection('../statistics/randomOutput/', 500, 'Random')
84# alloy = GraphCollection('../statistics/alloyOutput/', 500, 'Alloy (30 nodes)')
85viatraEvolve = GraphCollection('../statistics/viatraEvolve/', 130, 'viatraEvolve', shouldShuffle = False)
86
87#calculate metrics
88metricStat([human, viatraEvolve], 'Node Activity', nodeActivity, 0)
89metricStat([human, viatraEvolve], 'Out Degree', outDegree, 1)
90metricStat([human, viatraEvolve], 'MPC', mpc, 2) \ No newline at end of file