diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/metrics_plot/model comparison')
17 files changed, 101 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/input/.gitignore b/Metrics/Metrics-Calculation/metrics_plot/model comparison/input/.gitignore new file mode 100644 index 00000000..b3934b01 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/input/.gitignore | |||
@@ -0,0 +1,3 @@ | |||
1 | # ignore everything in this folder | ||
2 | * | ||
3 | !.gitignore \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/MPC.png new file mode 100644 index 00000000..cd2af5ce --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/MPC.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Node Activity.png new file mode 100644 index 00000000..2ce3672b --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Node Activity.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Out Degree.png new file mode 100644 index 00000000..d4d9afe1 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Out Degree.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/MPC.png new file mode 100644 index 00000000..8d76fed9 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/MPC.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/Node Activity.png new file mode 100644 index 00000000..daa7929a --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/Node Activity.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/Out Degree.png new file mode 100644 index 00000000..e56b1b6e --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/Out Degree.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/MPC.png new file mode 100644 index 00000000..8705cee2 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/MPC.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Node Activity.png new file mode 100644 index 00000000..bdab3741 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Node Activity.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Out Degree.png new file mode 100644 index 00000000..e4269f6e --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Out Degree.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/MPC.png new file mode 100644 index 00000000..e4b6b527 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/MPC.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Node Activity.png new file mode 100644 index 00000000..e067ad66 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Node Activity.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Out Degree.png new file mode 100644 index 00000000..9b89e4f9 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Out Degree.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/MPC.png new file mode 100644 index 00000000..4f189578 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/MPC.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/Node Activity.png new file mode 100644 index 00000000..add3c0f8 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/Node Activity.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/Out Degree.png new file mode 100644 index 00000000..f4717a1a --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/Out Degree.png | |||
Binary files differ | |||
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 new file mode 100644 index 00000000..2f39ca93 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py | |||
@@ -0,0 +1,98 @@ | |||
1 | import os, sys | ||
2 | lib_path = os.path.abspath(os.path.join('..', '..', 'utils')) | ||
3 | sys.path.append(lib_path) | ||
4 | import glob | ||
5 | import random | ||
6 | from sklearn.manifold import MDS | ||
7 | import matplotlib.pyplot as plt | ||
8 | from scipy import stats | ||
9 | import numpy as np | ||
10 | from GraphType import GraphCollection | ||
11 | |||
12 | def main(): | ||
13 | # read models | ||
14 | human = GraphCollection('../input/humanOutput/', 500, 'Human') | ||
15 | viatra30 = GraphCollection('../input/viatraOutput30/', 500, 'Viatra (30 nodes)') | ||
16 | # viatra60 = GraphCollection('../input/viatraOutput60/', 500, 'Viatra (60 nodes)') | ||
17 | # viatra100 = GraphCollection('../input/viatraOutput100/', 500, 'Viatra (100 nodes)') | ||
18 | # random = GraphCollection('../input/randomOutput/', 500, 'Random') | ||
19 | # alloy = GraphCollection('../input/alloyOutput/', 500, 'Alloy (30 nodes)') | ||
20 | |||
21 | models_to_compare = [human, viatra30] | ||
22 | |||
23 | # define output folder | ||
24 | outputFolder = '../output/' | ||
25 | |||
26 | #calculate metrics | ||
27 | metricStat(models_to_compare, 'Node Activity', nodeActivity, 0, outputFolder) | ||
28 | metricStat(models_to_compare, 'Out Degree', outDegree, 1, outputFolder) | ||
29 | metricStat(models_to_compare, 'MPC', mpc, 2, outputFolder) | ||
30 | |||
31 | def calculateKSMatrix(dists): | ||
32 | dist = [] | ||
33 | |||
34 | for i in range(len(dists)): | ||
35 | dist = dist + dists[i] | ||
36 | matrix = np.empty((len(dist),len(dist))) | ||
37 | |||
38 | for i in range(len(dist)): | ||
39 | matrix[i,i] = 0 | ||
40 | for j in range(i+1, len(dist)): | ||
41 | value, p = stats.ks_2samp(dist[i], dist[j]) | ||
42 | matrix[i, j] = value | ||
43 | matrix[j, i] = value | ||
44 | return matrix | ||
45 | |||
46 | |||
47 | def calculateMDS(dissimilarities): | ||
48 | embedding = MDS(n_components=2, dissimilarity='precomputed') | ||
49 | trans = embedding.fit_transform(X=dissimilarities) | ||
50 | return trans | ||
51 | |||
52 | def plot(graphTypes, coords, title='',index = 0, savePath = ''): | ||
53 | half_length = int(coords.shape[0] / len(graphTypes)) | ||
54 | color = ['blue', 'red', 'green', 'yellow'] | ||
55 | plt.figure(index, figsize=(7, 4)) | ||
56 | plt.title(title) | ||
57 | for i in range(len(graphTypes)): | ||
58 | x = (coords[(i*half_length):((i+1)*half_length), 0].tolist()) | ||
59 | y = (coords[(i*half_length):((i+1)*half_length), 1].tolist()) | ||
60 | plt.plot(x, y, color=color[i], marker='o', label = graphTypes[i].name, linestyle='', alpha=0.7) | ||
61 | plt.legend(loc='upper right') | ||
62 | plt.savefig(fname = savePath, dpi=150) | ||
63 | #graph.show() | ||
64 | |||
65 | def mkdir_p(mypath): | ||
66 | '''Creates a directory. equivalent to using mkdir -p on the command line''' | ||
67 | |||
68 | from errno import EEXIST | ||
69 | from os import makedirs,path | ||
70 | |||
71 | try: | ||
72 | makedirs(mypath) | ||
73 | except OSError as exc: # Python >2.5 | ||
74 | if exc.errno == EEXIST and path.isdir(mypath): | ||
75 | pass | ||
76 | else: raise | ||
77 | |||
78 | def metricStat(graphTypes, metricName, metric, graphIndex, outputFolder): | ||
79 | metrics = [] | ||
80 | for graph in graphTypes: | ||
81 | metrics.append(metric(graph)) | ||
82 | outputFolder = outputFolder + graph.name + '-' | ||
83 | print('calculate' + metricName +' for ' + outputFolder) | ||
84 | mkdir_p(outputFolder) | ||
85 | out_d_coords = calculateMDS(calculateKSMatrix(metrics)) | ||
86 | plot(graphTypes, out_d_coords, metricName, graphIndex,outputFolder + '/'+ metricName+'.png') | ||
87 | |||
88 | def nodeActivity(graphType): | ||
89 | return graphType.nas | ||
90 | |||
91 | def outDegree(graphType): | ||
92 | return graphType.out_ds | ||
93 | |||
94 | def mpc(graphType): | ||
95 | return graphType.mpcs | ||
96 | |||
97 | if __name__ == '__main__': | ||
98 | main() \ No newline at end of file | ||