diff options
author | 20001LastOrder <boqi.chen@mail.mcgill.ca> | 2019-05-27 15:40:43 -0400 |
---|---|---|
committer | 20001LastOrder <boqi.chen@mail.mcgill.ca> | 2019-05-27 15:40:43 -0400 |
commit | 77b37ddbb27f9bf185b8803746b1b3448c77b97c (patch) | |
tree | c44a98fc0ac81e845ee88bb139e986abb042d038 /Metrics | |
parent | REALMET: implement incoming edges in visualisation. multips need fix (diff) | |
download | VIATRA-Generator-77b37ddbb27f9bf185b8803746b1b3448c77b97c.tar.gz VIATRA-Generator-77b37ddbb27f9bf185b8803746b1b3448c77b97c.tar.zst VIATRA-Generator-77b37ddbb27f9bf185b8803746b1b3448c77b97c.zip |
add metrics data plot tool
Diffstat (limited to 'Metrics')
31 files changed, 1063 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/metrics_plot/.gitignore b/Metrics/Metrics-Calculation/metrics_plot/.gitignore new file mode 100644 index 00000000..dc53b109 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/.gitignore | |||
@@ -0,0 +1,10 @@ | |||
1 | # virtual enviroment | ||
2 | venv/ | ||
3 | |||
4 | # python cache | ||
5 | *.pyc | ||
6 | .ipynb_checkpoints/ | ||
7 | .idea/ | ||
8 | |||
9 | # keep folders | ||
10 | !.gitignore \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/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/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/MPC.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/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/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Node Activity.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/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/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Out Degree.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/MPC.png new file mode 100644 index 00000000..8d76fed9 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/MPC.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/Node Activity.png new file mode 100644 index 00000000..daa7929a --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/Node Activity.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/Out Degree.png new file mode 100644 index 00000000..e56b1b6e --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/Out Degree.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/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/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/MPC.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/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/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Node Activity.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/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/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Out Degree.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/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/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/MPC.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/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/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/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/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/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/output/Human-viatraEvolve-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/MPC.png new file mode 100644 index 00000000..d819aad5 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/MPC.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/Node Activity.png new file mode 100644 index 00000000..4b3b187e --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/Node Activity.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/Out Degree.png new file mode 100644 index 00000000..d8e01f6e --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/Out Degree.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/MPC.png new file mode 100644 index 00000000..4f189578 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/MPC.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/Node Activity.png new file mode 100644 index 00000000..add3c0f8 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/Node Activity.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/Out Degree.png new file mode 100644 index 00000000..f4717a1a --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/Out Degree.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/GraphType.py b/Metrics/Metrics-Calculation/metrics_plot/src/GraphType.py new file mode 100644 index 00000000..b3c9f359 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/src/GraphType.py | |||
@@ -0,0 +1,27 @@ | |||
1 | import readCSV as reader | ||
2 | import constants | ||
3 | import numpy as np | ||
4 | |||
5 | # graph stats for a collection of graphs | ||
6 | class GraphCollection: | ||
7 | |||
8 | # init with path contrain files and number of files to read reader is imported from (readCSV) | ||
9 | def __init__(self, path, number, name, shouldShuffle = True): | ||
10 | self.out_ds = [] | ||
11 | self.nas = [] | ||
12 | self.mpcs = [] | ||
13 | self.name = name | ||
14 | models = reader.readmultiplefiles(path, number, shouldShuffle) | ||
15 | for i in range(len(models)): | ||
16 | contents, out_d, na, mpc = reader.getmetrics(models[i]) | ||
17 | self.out_ds.append(out_d) | ||
18 | self.nas.append(na) | ||
19 | self.mpcs.append(mpc) | ||
20 | |||
21 | #Graph stat for one graph | ||
22 | class GraphStat: | ||
23 | # init with teh file name of the stat | ||
24 | def __init__(self, filename): | ||
25 | contents, self.out_d, self.na, self.mpc = reader.getmetrics(filename) | ||
26 | self.num_nodes = np.array(contents[constants.NUMBER_NODES]) | ||
27 | self.id = (contents[constants.STATE_ID])[0] | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/src/MPC.png new file mode 100644 index 00000000..4f189578 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/src/MPC.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/Metrics Comparison .ipynb b/Metrics/Metrics-Calculation/metrics_plot/src/Metrics Comparison .ipynb new file mode 100644 index 00000000..17ad1253 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/src/Metrics Comparison .ipynb | |||
@@ -0,0 +1,207 @@ | |||
1 | { | ||
2 | "cells": [ | ||
3 | { | ||
4 | "cell_type": "markdown", | ||
5 | "metadata": {}, | ||
6 | "source": [ | ||
7 | "## Metric comparison preperation" | ||
8 | ] | ||
9 | }, | ||
10 | { | ||
11 | "cell_type": "code", | ||
12 | "execution_count": 2, | ||
13 | "metadata": {}, | ||
14 | "outputs": [], | ||
15 | "source": [ | ||
16 | "import readCSV as reader\n", | ||
17 | "import glob\n", | ||
18 | "import random \n", | ||
19 | "from sklearn.manifold import MDS\n", | ||
20 | "import matplotlib.pyplot as plt\n", | ||
21 | "from scipy import stats\n", | ||
22 | "import numpy as np" | ||
23 | ] | ||
24 | }, | ||
25 | { | ||
26 | "cell_type": "code", | ||
27 | "execution_count": 3, | ||
28 | "metadata": {}, | ||
29 | "outputs": [], | ||
30 | "source": [ | ||
31 | "def calculateKSMatrix(dists):\n", | ||
32 | " dist = []\n", | ||
33 | "\n", | ||
34 | " for i in range(len(dists)):\n", | ||
35 | " dist = dist + dists[i]\n", | ||
36 | " matrix = np.empty((len(dist),len(dist)))\n", | ||
37 | "\n", | ||
38 | " for i in range(len(dist)):\n", | ||
39 | " matrix[i,i] = 0\n", | ||
40 | " for j in range(i+1, len(dist)):\n", | ||
41 | " value, p = stats.ks_2samp(dist[i], dist[j])\n", | ||
42 | " matrix[i, j] = value\n", | ||
43 | " matrix[j, i] = value\n", | ||
44 | " value, p = stats.ks_2samp(dist[j], dist[i])\n", | ||
45 | " return matrix\n" | ||
46 | ] | ||
47 | }, | ||
48 | { | ||
49 | "cell_type": "code", | ||
50 | "execution_count": 4, | ||
51 | "metadata": {}, | ||
52 | "outputs": [], | ||
53 | "source": [ | ||
54 | "def calculateMDS(dissimilarities):\n", | ||
55 | " embedding = MDS(n_components=2, dissimilarity='precomputed')\n", | ||
56 | " trans = embedding.fit_transform(X=dissimilarities)\n", | ||
57 | " return trans" | ||
58 | ] | ||
59 | }, | ||
60 | { | ||
61 | "cell_type": "code", | ||
62 | "execution_count": 5, | ||
63 | "metadata": {}, | ||
64 | "outputs": [], | ||
65 | "source": [ | ||
66 | "def plot(names, coords, index = 0, title=''):\n", | ||
67 | " half_length = int(coords.shape[0] / len(names))\n", | ||
68 | " color = ['blue', 'red', 'green']\n", | ||
69 | " graph = plt.figure(index)\n", | ||
70 | " plt.title(title)\n", | ||
71 | " for i in range(len(names)):\n", | ||
72 | " x = (coords[(i*half_length):((i+1)*half_length), 0].tolist())\n", | ||
73 | " y = (coords[(i*half_length):((i+1)*half_length), 1].tolist())\n", | ||
74 | " plt.plot(x, y, color=color[i], marker='o', label = names[i], linestyle='', alpha=0.7)\n", | ||
75 | " plt.legend(loc='upper right')\n", | ||
76 | " plt.savefig(fname = title+'.png', dpi=150)\n", | ||
77 | " #graph.show()\n" | ||
78 | ] | ||
79 | }, | ||
80 | { | ||
81 | "cell_type": "markdown", | ||
82 | "metadata": {}, | ||
83 | "source": [ | ||
84 | "## Read Files\n", | ||
85 | "1. define class for metric reading of each graph type" | ||
86 | ] | ||
87 | }, | ||
88 | { | ||
89 | "cell_type": "code", | ||
90 | "execution_count": 6, | ||
91 | "metadata": {}, | ||
92 | "outputs": [], | ||
93 | "source": [ | ||
94 | "class GraphType:\n", | ||
95 | " \n", | ||
96 | " # init with path contrain files and number of files to read reader is imported from (readCSV)\n", | ||
97 | " def __init__(self, path, number):\n", | ||
98 | " self.out_ds = []\n", | ||
99 | " self.nas = []\n", | ||
100 | " self.mpcs = []\n", | ||
101 | " models = reader.readmultiplefiles(path, number)\n", | ||
102 | " for i in range(len(models)):\n", | ||
103 | " out_d, na, mpc = reader.getmetrics(models[i])\n", | ||
104 | " self.out_ds.append(out_d)\n", | ||
105 | " self.nas.append(na)\n", | ||
106 | " self.mpcs.append(mpc)" | ||
107 | ] | ||
108 | }, | ||
109 | { | ||
110 | "cell_type": "markdown", | ||
111 | "metadata": {}, | ||
112 | "source": [ | ||
113 | "2. read metrics for each graph type" | ||
114 | ] | ||
115 | }, | ||
116 | { | ||
117 | "cell_type": "code", | ||
118 | "execution_count": 9, | ||
119 | "metadata": {}, | ||
120 | "outputs": [], | ||
121 | "source": [ | ||
122 | "human = GraphType('../statistics/humanOutput/', 300)\n", | ||
123 | "viatra30 = GraphType('../statistics/viatraOutput30/', 300)\n", | ||
124 | "viatra100 = GraphType('../statistics/viatraOutput100/', 300)\n", | ||
125 | "random = GraphType('../statistics/randomOutput/', 300)\n", | ||
126 | "alloy = GraphType('../statistics/alloyOutput/', 300)" | ||
127 | ] | ||
128 | }, | ||
129 | { | ||
130 | "cell_type": "markdown", | ||
131 | "metadata": {}, | ||
132 | "source": [ | ||
133 | "* outdegree comparison for human, Viatra30, and alloy" | ||
134 | ] | ||
135 | }, | ||
136 | { | ||
137 | "cell_type": "code", | ||
138 | "execution_count": 11, | ||
139 | "metadata": {}, | ||
140 | "outputs": [ | ||
141 | { | ||
142 | "ename": "KeyboardInterrupt", | ||
143 | "evalue": "", | ||
144 | "output_type": "error", | ||
145 | "traceback": [ | ||
146 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | ||
147 | "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", | ||
148 | "\u001b[1;32m<ipython-input-11-5692e29d4679>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mout_d_coords\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcalculateMDS\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcalculateKSMatrix\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mviatra30\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mout_ds\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0malloy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mout_ds\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mhuman\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mout_ds\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'Viatra (30 nodes)'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'Alloy (30 nodes)'\u001b[0m \u001b[1;33m,\u001b[0m \u001b[1;34m'Human'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mout_d_coords\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'Out Degree'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | ||
149 | "\u001b[1;32m<ipython-input-3-37c4264e6073>\u001b[0m in \u001b[0;36mcalculateKSMatrix\u001b[1;34m(dists)\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[0mmatrix\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mj\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 13\u001b[0m \u001b[0mmatrix\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 14\u001b[1;33m \u001b[0mvalue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mstats\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mks_2samp\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdist\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mj\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdist\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 15\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mmatrix\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | ||
150 | "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\scipy\\stats\\stats.py\u001b[0m in \u001b[0;36mks_2samp\u001b[1;34m(data1, data2)\u001b[0m\n\u001b[0;32m 4854\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4855\u001b[0m \"\"\"\n\u001b[1;32m-> 4856\u001b[1;33m \u001b[0mdata1\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msort\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4857\u001b[0m \u001b[0mdata2\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msort\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4858\u001b[0m \u001b[0mn1\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdata1\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | ||
151 | "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\numpy\\core\\fromnumeric.py\u001b[0m in \u001b[0;36msort\u001b[1;34m(a, axis, kind, order)\u001b[0m\n\u001b[0;32m 932\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 933\u001b[0m \u001b[0ma\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0masanyarray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcopy\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0morder\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"K\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 934\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msort\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkind\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mkind\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0morder\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0morder\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 935\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 936\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", | ||
152 | "\u001b[1;31mKeyboardInterrupt\u001b[0m: " | ||
153 | ] | ||
154 | } | ||
155 | ], | ||
156 | "source": [ | ||
157 | "out_d_coords = calculateMDS(calculateKSMatrix([viatra30.out_ds, alloy.out_ds, human.out_ds]))\n", | ||
158 | "plot(['Viatra (30 nodes)', 'Alloy (30 nodes)' , 'Human'], out_d_coords,0, 'Out Degree')" | ||
159 | ] | ||
160 | }, | ||
161 | { | ||
162 | "cell_type": "markdown", | ||
163 | "metadata": {}, | ||
164 | "source": [ | ||
165 | "* outdegree comparison for human, Viatra30, and alloy" | ||
166 | ] | ||
167 | }, | ||
168 | { | ||
169 | "cell_type": "code", | ||
170 | "execution_count": null, | ||
171 | "metadata": {}, | ||
172 | "outputs": [], | ||
173 | "source": [ | ||
174 | "out_d_coords = calculateMDS(calculateKSMatrix([viatra30.nas, alloy.nas, human.nas]))\n", | ||
175 | "plot(['Viatra (30 nodes)', 'Alloy (30 nodes)' , 'Human'], out_d_coords,0, 'Node Activity')" | ||
176 | ] | ||
177 | }, | ||
178 | { | ||
179 | "cell_type": "code", | ||
180 | "execution_count": null, | ||
181 | "metadata": {}, | ||
182 | "outputs": [], | ||
183 | "source": [] | ||
184 | } | ||
185 | ], | ||
186 | "metadata": { | ||
187 | "kernelspec": { | ||
188 | "display_name": "Python 3", | ||
189 | "language": "python", | ||
190 | "name": "python3" | ||
191 | }, | ||
192 | "language_info": { | ||
193 | "codemirror_mode": { | ||
194 | "name": "ipython", | ||
195 | "version": 3 | ||
196 | }, | ||
197 | "file_extension": ".py", | ||
198 | "mimetype": "text/x-python", | ||
199 | "name": "python", | ||
200 | "nbconvert_exporter": "python", | ||
201 | "pygments_lexer": "ipython3", | ||
202 | "version": "3.7.3" | ||
203 | } | ||
204 | }, | ||
205 | "nbformat": 4, | ||
206 | "nbformat_minor": 2 | ||
207 | } | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/src/Node Activity.png new file mode 100644 index 00000000..add3c0f8 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/src/Node Activity.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/src/Out Degree.png new file mode 100644 index 00000000..5978c7cb --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/src/Out Degree.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/average_ks_plot.py b/Metrics/Metrics-Calculation/metrics_plot/src/average_ks_plot.py new file mode 100644 index 00000000..e949a729 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/src/average_ks_plot.py | |||
@@ -0,0 +1,62 @@ | |||
1 | from GraphType import GraphStat | ||
2 | from GraphType import GraphCollection | ||
3 | from scipy import stats | ||
4 | import readCSV as reader | ||
5 | import matplotlib.pyplot as plt | ||
6 | |||
7 | class GraphDistance: | ||
8 | #init with a graph stat and a collection of graph stats | ||
9 | def __init__(self, graphStat, collection): | ||
10 | self.graph = graphStat | ||
11 | self.collection = collection | ||
12 | print('calculating for %d' %(self.graph.id)) | ||
13 | self.out_d_distance = average_ks_distance(collection.out_ds, graphStat.out_d) | ||
14 | self.na_distance = average_ks_distance(collection.nas, graphStat.na) | ||
15 | self.mpc_distance = average_ks_distance(collection.mpcs, graphStat.mpc) | ||
16 | |||
17 | def average_ks_distance(targets, sample): | ||
18 | distance = 0.0 | ||
19 | for target in targets: | ||
20 | value, p = stats.ks_2samp(target, sample) | ||
21 | distance += value | ||
22 | |||
23 | distance = distance / len(targets) | ||
24 | return distance | ||
25 | |||
26 | # metric_selector: GraphDistance -> float | ||
27 | def plot(infos, lines, id, metric_selector, title): | ||
28 | metric_distances = retrive_info_from_list(metric_selector, list(infos.values())) | ||
29 | x = retrive_info_from_list(lambda a : a.graph.num_nodes, list(infos.values)) | ||
30 | graph = plt.figure(id) | ||
31 | plt.title(title) | ||
32 | |||
33 | for line in lines: | ||
34 | line_infos = retrive_info_from_list(lambda a: infos[a], line) | ||
35 | line_y = retrive_info_from_list(metric_selector, line_infos) | ||
36 | line_x = retrive_info_from_list(lambda a : a.graph.num_nodes, list(infos.values)) | ||
37 | plt.plot(line_x, line_y, color='blue') | ||
38 | plt.plot(x, metric_distances, color='red', linestyle='', marker='o',alpha=0.7) | ||
39 | graph.show() | ||
40 | |||
41 | def retrive_info_from_list(selector, distances): | ||
42 | return list(map(selector, list(infos.values))) | ||
43 | |||
44 | human = GraphCollection('../statistics/humanOutput/', 300, 'Human') | ||
45 | file_names = reader.readmultiplefiles('../statistics/viatraEvolve/', 500, False) | ||
46 | |||
47 | infos = [] | ||
48 | # read all files | ||
49 | for name in file_names: | ||
50 | infos.append(GraphStat(name)) | ||
51 | |||
52 | infos = list(map(lambda s: GraphDistance(s, human), infos)) | ||
53 | |||
54 | info_dic = {} | ||
55 | for info in infos: | ||
56 | info_dic[info.graph.id] = info | ||
57 | |||
58 | plot(info_dic, [[1,2,3,4,5,6,7,8,9,10]], 0, lambda a: a.out_d_distance, 'out degree') | ||
59 | # plot(info_dic, 1, lambda a: a.na_distance, 'node activity') | ||
60 | # plot(info_dic, 2, lambda a: a.mpc_distance, 'mpc') | ||
61 | |||
62 | input() \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/constants.py b/Metrics/Metrics-Calculation/metrics_plot/src/constants.py new file mode 100644 index 00000000..4504030e --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/src/constants.py | |||
@@ -0,0 +1,19 @@ | |||
1 | NUMBER_EDGE_TYPES = 'Number of Edge types' | ||
2 | |||
3 | NUMBER_NODES = 'Number Of Nodes' | ||
4 | |||
5 | OUT_DEGREE_COUNT = 'OutDegreeCount' | ||
6 | |||
7 | OUT_DEGREE_VALUE = 'OutDegreeValue' | ||
8 | |||
9 | NA_COUNT = 'NACount' | ||
10 | |||
11 | NA_VALUE = 'NAValue' | ||
12 | |||
13 | MPC_VALUE = 'MPCValue' | ||
14 | |||
15 | MPC_COUNT = 'MPCCount' | ||
16 | |||
17 | METAMODEL = 'Meta Mode' | ||
18 | |||
19 | STATE_ID = 'State Id' \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance.ipynb b/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance.ipynb new file mode 100644 index 00000000..c7daa75e --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance.ipynb | |||
@@ -0,0 +1,441 @@ | |||
1 | { | ||
2 | "cells": [ | ||
3 | { | ||
4 | "cell_type": "markdown", | ||
5 | "metadata": {}, | ||
6 | "source": [ | ||
7 | "# Compare Metrics Distances to The Human Models" | ||
8 | ] | ||
9 | }, | ||
10 | { | ||
11 | "cell_type": "markdown", | ||
12 | "metadata": {}, | ||
13 | "source": [ | ||
14 | "### Imports" | ||
15 | ] | ||
16 | }, | ||
17 | { | ||
18 | "cell_type": "code", | ||
19 | "execution_count": 1, | ||
20 | "metadata": {}, | ||
21 | "outputs": [], | ||
22 | "source": [ | ||
23 | "from GraphType import GraphStat\n", | ||
24 | "from GraphType import GraphCollection\n", | ||
25 | "from scipy import stats\n", | ||
26 | "from ipywidgets import interact, fixed, interactive\n", | ||
27 | "import readCSV as reader\n", | ||
28 | "import ipywidgets as widgets\n", | ||
29 | "import matplotlib.pyplot as plt\n", | ||
30 | "import random\n" | ||
31 | ] | ||
32 | }, | ||
33 | { | ||
34 | "cell_type": "markdown", | ||
35 | "metadata": {}, | ||
36 | "source": [ | ||
37 | "### Classes" | ||
38 | ] | ||
39 | }, | ||
40 | { | ||
41 | "cell_type": "markdown", | ||
42 | "metadata": {}, | ||
43 | "source": [ | ||
44 | "* Record the average distances of different metrics for a model to the human models " | ||
45 | ] | ||
46 | }, | ||
47 | { | ||
48 | "cell_type": "code", | ||
49 | "execution_count": 2, | ||
50 | "metadata": {}, | ||
51 | "outputs": [], | ||
52 | "source": [ | ||
53 | "class GraphDistance:\n", | ||
54 | " #init with a graph stat and a collection of graph stats\n", | ||
55 | " def __init__(self, graphStat, collection):\n", | ||
56 | " self.graph = graphStat\n", | ||
57 | " self.collection = collection\n", | ||
58 | " self.out_d_distance = average_ks_distance(collection.out_ds, graphStat.out_d)\n", | ||
59 | " self.na_distance = average_ks_distance(collection.nas, graphStat.na)\n", | ||
60 | " self.mpc_distance = average_ks_distance(collection.mpcs, graphStat.mpc)" | ||
61 | ] | ||
62 | }, | ||
63 | { | ||
64 | "cell_type": "markdown", | ||
65 | "metadata": {}, | ||
66 | "source": [ | ||
67 | "### Methods" | ||
68 | ] | ||
69 | }, | ||
70 | { | ||
71 | "cell_type": "markdown", | ||
72 | "metadata": {}, | ||
73 | "source": [ | ||
74 | "* Calculate the average ks distance" | ||
75 | ] | ||
76 | }, | ||
77 | { | ||
78 | "cell_type": "code", | ||
79 | "execution_count": 3, | ||
80 | "metadata": {}, | ||
81 | "outputs": [], | ||
82 | "source": [ | ||
83 | "def average_ks_distance(targets, sample):\n", | ||
84 | " distance = 0.0\n", | ||
85 | " for target in targets:\n", | ||
86 | " value, p = stats.ks_2samp(target, sample)\n", | ||
87 | " distance += value\n", | ||
88 | " \n", | ||
89 | " distance = distance / len(targets)\n", | ||
90 | " return distance" | ||
91 | ] | ||
92 | }, | ||
93 | { | ||
94 | "cell_type": "markdown", | ||
95 | "metadata": {}, | ||
96 | "source": [ | ||
97 | "* Plot Diagram" | ||
98 | ] | ||
99 | }, | ||
100 | { | ||
101 | "cell_type": "code", | ||
102 | "execution_count": 4, | ||
103 | "metadata": {}, | ||
104 | "outputs": [], | ||
105 | "source": [ | ||
106 | "# metric_selector: GraphDistance -> float\n", | ||
107 | "def plot(infos, lines, id, metric_selector,colors, title):\n", | ||
108 | " metric_distances = retrive_info_from_list(metric_selector, list(infos.values()))\n", | ||
109 | " x = retrive_info_from_list(lambda a : a.graph.num_nodes, list(infos.values()))\n", | ||
110 | " graph = plt.figure(id,figsize=(18, 10))\n", | ||
111 | " plt.title(title)\n", | ||
112 | " plt.plot(x, metric_distances, color='red', linestyle='', marker='o',alpha=0.7)\n", | ||
113 | " for i in range(0, len(lines)):\n", | ||
114 | " line_infos = retrive_info_from_list(lambda a: infos[a], lines[i])\n", | ||
115 | " line_y = retrive_info_from_list(metric_selector, line_infos)\n", | ||
116 | " line_x = retrive_info_from_list(lambda a : a.graph.num_nodes, line_infos)\n", | ||
117 | " plt.plot(line_x, line_y, marker='o', color=colors[i])\n", | ||
118 | " #graph.show()" | ||
119 | ] | ||
120 | }, | ||
121 | { | ||
122 | "cell_type": "markdown", | ||
123 | "metadata": {}, | ||
124 | "source": [ | ||
125 | "* Retrieve information from a list " | ||
126 | ] | ||
127 | }, | ||
128 | { | ||
129 | "cell_type": "code", | ||
130 | "execution_count": 5, | ||
131 | "metadata": {}, | ||
132 | "outputs": [], | ||
133 | "source": [ | ||
134 | "def retrive_info_from_list(selector, distances):\n", | ||
135 | " return list(map(selector, distances))" | ||
136 | ] | ||
137 | }, | ||
138 | { | ||
139 | "cell_type": "markdown", | ||
140 | "metadata": {}, | ||
141 | "source": [ | ||
142 | "### Read Models" | ||
143 | ] | ||
144 | }, | ||
145 | { | ||
146 | "cell_type": "code", | ||
147 | "execution_count": 6, | ||
148 | "metadata": {}, | ||
149 | "outputs": [], | ||
150 | "source": [ | ||
151 | "human = GraphCollection('../statistics/humanOutput/', 300, 'Human')\n", | ||
152 | "file_names = reader.readmultiplefiles('../statistics/viatraEvolve/', 1000, False)" | ||
153 | ] | ||
154 | }, | ||
155 | { | ||
156 | "cell_type": "markdown", | ||
157 | "metadata": {}, | ||
158 | "source": [ | ||
159 | "### Calculate Distances" | ||
160 | ] | ||
161 | }, | ||
162 | { | ||
163 | "cell_type": "code", | ||
164 | "execution_count": 7, | ||
165 | "metadata": {}, | ||
166 | "outputs": [], | ||
167 | "source": [ | ||
168 | "# Progress Widge\n", | ||
169 | "w2 = widgets.FloatProgress(\n", | ||
170 | " value=0,\n", | ||
171 | " min=0,\n", | ||
172 | " max=1.0,\n", | ||
173 | " step=0.1,\n", | ||
174 | " description='Loading Files...:',\n", | ||
175 | " bar_style='info',\n", | ||
176 | " orientation='horizontal'\n", | ||
177 | ")" | ||
178 | ] | ||
179 | }, | ||
180 | { | ||
181 | "cell_type": "code", | ||
182 | "execution_count": 8, | ||
183 | "metadata": {}, | ||
184 | "outputs": [ | ||
185 | { | ||
186 | "data": { | ||
187 | "application/vnd.jupyter.widget-view+json": { | ||
188 | "model_id": "60e3295a164f48428bc882868e68f26f", | ||
189 | "version_major": 2, | ||
190 | "version_minor": 0 | ||
191 | }, | ||
192 | "text/plain": [ | ||
193 | "FloatProgress(value=0.0, bar_style='info', description='Loading Files...:', max=1.0)" | ||
194 | ] | ||
195 | }, | ||
196 | "metadata": {}, | ||
197 | "output_type": "display_data" | ||
198 | } | ||
199 | ], | ||
200 | "source": [ | ||
201 | "infos = []\n", | ||
202 | "# read all files\n", | ||
203 | "counter = 0.0\n", | ||
204 | "size = len(file_names)\n", | ||
205 | "#display progress bar\n", | ||
206 | "display(w2)\n", | ||
207 | "for name in file_names:\n", | ||
208 | " infos.append(GraphStat(name))\n", | ||
209 | "\n", | ||
210 | "info_dic = {}\n", | ||
211 | "for info in infos:\n", | ||
212 | " w2.value = (counter/size)\n", | ||
213 | " counter+=1\n", | ||
214 | " info = GraphDistance(info, human)\n", | ||
215 | " info_dic[info.graph.id] = info" | ||
216 | ] | ||
217 | }, | ||
218 | { | ||
219 | "cell_type": "markdown", | ||
220 | "metadata": {}, | ||
221 | "source": [ | ||
222 | "#### Plot Graphs" | ||
223 | ] | ||
224 | }, | ||
225 | { | ||
226 | "cell_type": "markdown", | ||
227 | "metadata": {}, | ||
228 | "source": [ | ||
229 | "* widget for select trajectory" | ||
230 | ] | ||
231 | }, | ||
232 | { | ||
233 | "cell_type": "code", | ||
234 | "execution_count": 9, | ||
235 | "metadata": {}, | ||
236 | "outputs": [], | ||
237 | "source": [ | ||
238 | "filenames = reader.readmultiplefiles('../statistics/trajectories/', 10, False)\n", | ||
239 | "trajectories = {}\n", | ||
240 | "for name in filenames:\n", | ||
241 | " trajectories[name] = reader.readTrajectory(name)\n", | ||
242 | "\n", | ||
243 | "w = widgets.SelectMultiple(\n", | ||
244 | " options = trajectories,\n", | ||
245 | " value = [trajectories[filenames[0]]],\n", | ||
246 | " description='Trajectory:',\n", | ||
247 | " disabled=False,\n", | ||
248 | ")\n", | ||
249 | "\n", | ||
250 | "#generate random color for each line\n", | ||
251 | "colors = []\n", | ||
252 | "\n", | ||
253 | "for i in range(0, len(trajectories)):\n", | ||
254 | " color = \"#%06x\" % random.randint(0, 0xFFFFFF)\n", | ||
255 | " colors.append(color)" | ||
256 | ] | ||
257 | }, | ||
258 | { | ||
259 | "cell_type": "markdown", | ||
260 | "metadata": {}, | ||
261 | "source": [ | ||
262 | "#### Out Degree" | ||
263 | ] | ||
264 | }, | ||
265 | { | ||
266 | "cell_type": "code", | ||
267 | "execution_count": 10, | ||
268 | "metadata": {}, | ||
269 | "outputs": [ | ||
270 | { | ||
271 | "data": { | ||
272 | "application/vnd.jupyter.widget-view+json": { | ||
273 | "model_id": "f69502eba4af40f19acc09f36681387a", | ||
274 | "version_major": 2, | ||
275 | "version_minor": 0 | ||
276 | }, | ||
277 | "text/plain": [ | ||
278 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/trajectori…" | ||
279 | ] | ||
280 | }, | ||
281 | "metadata": {}, | ||
282 | "output_type": "display_data" | ||
283 | }, | ||
284 | { | ||
285 | "data": { | ||
286 | "text/plain": [ | ||
287 | "<function __main__.plot_out_degree(lines)>" | ||
288 | ] | ||
289 | }, | ||
290 | "execution_count": 10, | ||
291 | "metadata": {}, | ||
292 | "output_type": "execute_result" | ||
293 | } | ||
294 | ], | ||
295 | "source": [ | ||
296 | "def plot_out_degree(lines):\n", | ||
297 | " plot(info_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree')\n", | ||
298 | "interact(plot_out_degree, lines=w)" | ||
299 | ] | ||
300 | }, | ||
301 | { | ||
302 | "cell_type": "markdown", | ||
303 | "metadata": {}, | ||
304 | "source": [ | ||
305 | "#### Node Activity" | ||
306 | ] | ||
307 | }, | ||
308 | { | ||
309 | "cell_type": "code", | ||
310 | "execution_count": 11, | ||
311 | "metadata": {}, | ||
312 | "outputs": [ | ||
313 | { | ||
314 | "data": { | ||
315 | "application/vnd.jupyter.widget-view+json": { | ||
316 | "model_id": "0df16294cd86434b8f144ff08702d44a", | ||
317 | "version_major": 2, | ||
318 | "version_minor": 0 | ||
319 | }, | ||
320 | "text/plain": [ | ||
321 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/trajectori…" | ||
322 | ] | ||
323 | }, | ||
324 | "metadata": {}, | ||
325 | "output_type": "display_data" | ||
326 | }, | ||
327 | { | ||
328 | "data": { | ||
329 | "text/plain": [ | ||
330 | "<function __main__.plot_out_degree(lines)>" | ||
331 | ] | ||
332 | }, | ||
333 | "execution_count": 11, | ||
334 | "metadata": {}, | ||
335 | "output_type": "execute_result" | ||
336 | } | ||
337 | ], | ||
338 | "source": [ | ||
339 | "def plot_out_degree(lines):\n", | ||
340 | " plot(info_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity')\n", | ||
341 | "interact(plot_out_degree, lines=w)" | ||
342 | ] | ||
343 | }, | ||
344 | { | ||
345 | "cell_type": "markdown", | ||
346 | "metadata": {}, | ||
347 | "source": [ | ||
348 | "#### MPC" | ||
349 | ] | ||
350 | }, | ||
351 | { | ||
352 | "cell_type": "code", | ||
353 | "execution_count": 12, | ||
354 | "metadata": {}, | ||
355 | "outputs": [ | ||
356 | { | ||
357 | "data": { | ||
358 | "application/vnd.jupyter.widget-view+json": { | ||
359 | "model_id": "b4e76d41b3d644808e47e3d1d7aaf1a7", | ||
360 | "version_major": 2, | ||
361 | "version_minor": 0 | ||
362 | }, | ||
363 | "text/plain": [ | ||
364 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/trajectori…" | ||
365 | ] | ||
366 | }, | ||
367 | "metadata": {}, | ||
368 | "output_type": "display_data" | ||
369 | }, | ||
370 | { | ||
371 | "data": { | ||
372 | "text/plain": [ | ||
373 | "<function __main__.plot_out_degree(lines)>" | ||
374 | ] | ||
375 | }, | ||
376 | "execution_count": 12, | ||
377 | "metadata": {}, | ||
378 | "output_type": "execute_result" | ||
379 | } | ||
380 | ], | ||
381 | "source": [ | ||
382 | "def plot_out_degree(lines):\n", | ||
383 | " plot(info_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC')\n", | ||
384 | "interact(plot_out_degree, lines=w)" | ||
385 | ] | ||
386 | }, | ||
387 | { | ||
388 | "cell_type": "code", | ||
389 | "execution_count": 42, | ||
390 | "metadata": {}, | ||
391 | "outputs": [ | ||
392 | { | ||
393 | "name": "stdout", | ||
394 | "output_type": "stream", | ||
395 | "text": [ | ||
396 | "../statistics/viatraEvolve\\state_735.csv\n" | ||
397 | ] | ||
398 | } | ||
399 | ], | ||
400 | "source": [ | ||
401 | "for name in file_names:\n", | ||
402 | " contents = reader.readcsvfile(name)\n", | ||
403 | " if(contents['State Id'][0] == 1032396643):\n", | ||
404 | " print(name)" | ||
405 | ] | ||
406 | }, | ||
407 | { | ||
408 | "cell_type": "code", | ||
409 | "execution_count": null, | ||
410 | "metadata": {}, | ||
411 | "outputs": [], | ||
412 | "source": [] | ||
413 | }, | ||
414 | { | ||
415 | "cell_type": "markdown", | ||
416 | "metadata": {}, | ||
417 | "source": [] | ||
418 | } | ||
419 | ], | ||
420 | "metadata": { | ||
421 | "kernelspec": { | ||
422 | "display_name": "Python 3", | ||
423 | "language": "python", | ||
424 | "name": "python3" | ||
425 | }, | ||
426 | "language_info": { | ||
427 | "codemirror_mode": { | ||
428 | "name": "ipython", | ||
429 | "version": 3 | ||
430 | }, | ||
431 | "file_extension": ".py", | ||
432 | "mimetype": "text/x-python", | ||
433 | "name": "python", | ||
434 | "nbconvert_exporter": "python", | ||
435 | "pygments_lexer": "ipython3", | ||
436 | "version": "3.7.3" | ||
437 | } | ||
438 | }, | ||
439 | "nbformat": 4, | ||
440 | "nbformat_minor": 2 | ||
441 | } | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/plot_ks_stats.py b/Metrics/Metrics-Calculation/metrics_plot/src/plot_ks_stats.py new file mode 100644 index 00000000..ad72a4a1 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/src/plot_ks_stats.py | |||
@@ -0,0 +1,90 @@ | |||
1 | import glob | ||
2 | import random | ||
3 | from sklearn.manifold import MDS | ||
4 | import matplotlib.pyplot as plt | ||
5 | from scipy import stats | ||
6 | import numpy as np | ||
7 | from GraphType import GraphCollection | ||
8 | |||
9 | def 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 | |||
25 | def calculateMDS(dissimilarities): | ||
26 | embedding = MDS(n_components=2, dissimilarity='precomputed') | ||
27 | trans = embedding.fit_transform(X=dissimilarities) | ||
28 | return trans | ||
29 | |||
30 | def 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 | |||
44 | def 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 | |||
57 | def 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 | |||
68 | def nodeActivity(graphType): | ||
69 | return graphType.nas | ||
70 | |||
71 | def outDegree(graphType): | ||
72 | return graphType.out_ds | ||
73 | |||
74 | def mpc(graphType): | ||
75 | return graphType.mpcs | ||
76 | |||
77 | |||
78 | # read models | ||
79 | human = 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)') | ||
85 | viatraEvolve = GraphCollection('../statistics/viatraEvolve/', 130, 'viatraEvolve', shouldShuffle = False) | ||
86 | |||
87 | #calculate metrics | ||
88 | metricStat([human, viatraEvolve], 'Node Activity', nodeActivity, 0) | ||
89 | metricStat([human, viatraEvolve], 'Out Degree', outDegree, 1) | ||
90 | metricStat([human, viatraEvolve], 'MPC', mpc, 2) \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/readCSV.py b/Metrics/Metrics-Calculation/metrics_plot/src/readCSV.py new file mode 100644 index 00000000..8627ad4a --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/src/readCSV.py | |||
@@ -0,0 +1,169 @@ | |||
1 | import numpy as np | ||
2 | import matplotlib.pyplot as plt | ||
3 | from scipy import stats | ||
4 | import glob | ||
5 | import random | ||
6 | import constants | ||
7 | |||
8 | # | ||
9 | # read csvfile returns outdegree, node activity, mpc | ||
10 | # as matrix with the first row of values and second row of count | ||
11 | # | ||
12 | def readcsvfile(filename): | ||
13 | |||
14 | contents = {} | ||
15 | with open(filename) as f: | ||
16 | for i, line in enumerate(f): | ||
17 | arr = line.split(',') | ||
18 | # if there is no element in the line, continue | ||
19 | if len(line) < 0: continue | ||
20 | # else check for contents | ||
21 | # if it is MPC then use float | ||
22 | if arr[0] == constants.MPC_VALUE: | ||
23 | contents[constants.MPC_VALUE] = list(map(float, arr[1:])) | ||
24 | # meta models are string | ||
25 | elif(arr[0] == constants.METAMODEL): | ||
26 | contents[constants.METAMODEL] = arr[1:] | ||
27 | # all other contants are integer | ||
28 | else: | ||
29 | contents[arr[0]] = list(map(int, arr[1:])) | ||
30 | f.close() | ||
31 | return contents | ||
32 | |||
33 | def checkAndReshape(arr): | ||
34 | if len(arr.shape) < 2: | ||
35 | arr = np.reshape(arr, (arr.shape[0],1)) | ||
36 | return arr | ||
37 | |||
38 | def readTrajectory(filename): | ||
39 | state_codes = [] | ||
40 | with open(filename) as f: | ||
41 | for i, line in enumerate(f): | ||
42 | if(line == ''): continue | ||
43 | state_codes.append(int(line)) | ||
44 | return state_codes | ||
45 | # | ||
46 | # take a matrix as input | ||
47 | # return the sample array | ||
48 | # | ||
49 | def getsample(dataMatrix): | ||
50 | data = [] | ||
51 | value = dataMatrix[0, :] | ||
52 | count = dataMatrix[1, :] | ||
53 | for i, v in enumerate(value): | ||
54 | for x in range(0, int(count[i])): | ||
55 | data.append(v) | ||
56 | return data | ||
57 | |||
58 | def reproduceSample(values, counts): | ||
59 | arr = np.array([values, counts]) | ||
60 | return getsample(arr) | ||
61 | |||
62 | # | ||
63 | # take an array of filenames as input | ||
64 | # return the samples of outdegree, na, mpc | ||
65 | # | ||
66 | def getmetrics(filename): | ||
67 | contents = readcsvfile(filename) | ||
68 | outdegree_sample = reproduceSample(contents[constants.OUT_DEGREE_VALUE], contents[constants.OUT_DEGREE_COUNT]) | ||
69 | na_sample = reproduceSample(contents[constants.NA_VALUE], contents[constants.NA_COUNT]) | ||
70 | mpc_sample = reproduceSample(contents[constants.MPC_VALUE], contents[constants.MPC_COUNT]) | ||
71 | return contents,outdegree_sample, na_sample, mpc_sample | ||
72 | |||
73 | # | ||
74 | # read number of files in the given path RANDOMLY | ||
75 | # | ||
76 | def readmultiplefiles(dirName, numberOfFiles, shouldShuffle = True): | ||
77 | list_of_files = glob.glob(dirName + '*.csv') # create the list of file | ||
78 | if shouldShuffle: | ||
79 | random.shuffle(list_of_files) | ||
80 | #if the number of files is out of bound then just give the whole list | ||
81 | file_names = list_of_files[:numberOfFiles] if numberOfFiles > len(list_of_files) else list_of_files | ||
82 | # print(file_names) | ||
83 | return file_names | ||
84 | |||
85 | |||
86 | def plotlines(x, y, ax): | ||
87 | l1, = ax.plot(x, y) | ||
88 | |||
89 | |||
90 | def testgetsamplesfromfiles(): | ||
91 | files = readmultiplefiles('../statistics/viatraOutput/', 2) | ||
92 | for file in files: | ||
93 | getmetrics(file) | ||
94 | |||
95 | def probability(data): | ||
96 | sum = np.sum(data) | ||
97 | probabilityList = [] | ||
98 | for d in data: | ||
99 | p = d/sum | ||
100 | probabilityList.append(p) | ||
101 | a = np.array(probabilityList) | ||
102 | return a | ||
103 | |||
104 | |||
105 | def cumulativeProbability(p): | ||
106 | cdf = np.cumsum(p) | ||
107 | return cdf | ||
108 | |||
109 | |||
110 | def plot(): | ||
111 | fig, ax = plt.subplots() | ||
112 | fig, ax1 = plt.subplots() | ||
113 | fig, ax2 = plt.subplots() | ||
114 | fig, ax3 = plt.subplots() | ||
115 | fig, ax4 = plt.subplots() | ||
116 | fig, ax5 = plt.subplots() | ||
117 | list_of_files = readmultiplefiles('../statistics/iatraOutput/') | ||
118 | for file_name in list_of_files: | ||
119 | contents = readcsvfile(file_name) | ||
120 | outdegree = [contents[constants.OUT_DEGREE_VALUE], contents[constants.OUT_DEGREE_COUNT]] | ||
121 | na = [contents[constants.NA_VALUE], contents[constants.NA_COUNT]] | ||
122 | mpc = [contents[constants.MPC_VALUE], contents[constants.MPC_COUNT]] | ||
123 | outV = outdegree[0, :] | ||
124 | outC = outdegree[1, :] | ||
125 | outP = probability(outC) | ||
126 | outCumP = cumulativeProbability(outP) | ||
127 | plotlines(outV, outP, ax) | ||
128 | naV = na[0, :] | ||
129 | naC = na[1, :] | ||
130 | naP = probability(naC) | ||
131 | naCumP = cumulativeProbability(naP) | ||
132 | plotlines(naV, naP, ax1) | ||
133 | mpcV = mpc[0, :] | ||
134 | mpcC = mpc[1, :] | ||
135 | mpcP = probability(mpcC) | ||
136 | mpcCumP = cumulativeProbability(mpcP) | ||
137 | plotlines(mpcV, mpcP, ax2) | ||
138 | plotlines(outV, outCumP, ax3) | ||
139 | plotlines(naV, naCumP, ax4) | ||
140 | plotlines(mpcV, mpcCumP, ax5) | ||
141 | ax.set_xlabel('ourdegree') | ||
142 | ax.set_ylabel('pdf') | ||
143 | ax.grid() | ||
144 | |||
145 | ax1.set_xlabel('node activity') | ||
146 | ax1.set_ylabel('pdf') | ||
147 | ax1.grid() | ||
148 | |||
149 | ax2.set_xlabel('multiplex participation coefficient') | ||
150 | ax2.set_ylabel('pdf') | ||
151 | ax2.grid() | ||
152 | |||
153 | ax3.set_xlabel('ourdegree') | ||
154 | ax3.set_ylabel('cdf') | ||
155 | ax3.grid() | ||
156 | |||
157 | ax4.set_xlabel('node activity') | ||
158 | ax4.set_ylabel('cdf') | ||
159 | ax4.grid() | ||
160 | |||
161 | ax5.set_xlabel('multiplex participation coefficient') | ||
162 | ax5.set_ylabel('cdf') | ||
163 | ax5.grid() | ||
164 | |||
165 | plt.show() | ||
166 | |||
167 | |||
168 | # plot() | ||
169 | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/test.py b/Metrics/Metrics-Calculation/metrics_plot/src/test.py new file mode 100644 index 00000000..d1aae53a --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/src/test.py | |||
@@ -0,0 +1,35 @@ | |||
1 | from sklearn.datasets import load_digits | ||
2 | from sklearn.manifold import MDS | ||
3 | import matplotlib.pyplot as plt | ||
4 | from scipy import stats | ||
5 | import numpy as np | ||
6 | |||
7 | dist = [] | ||
8 | |||
9 | for i in range(100): | ||
10 | rvs = stats.uniform.rvs(size=500, loc=0., scale=1) | ||
11 | dist.append(rvs) | ||
12 | |||
13 | for i in range(100): | ||
14 | rvs2 = stats.powerlaw .rvs(1.66, size=500) | ||
15 | dist.append(rvs2) | ||
16 | |||
17 | matrix = np.empty((len(dist),len(dist))) | ||
18 | |||
19 | for i in range(len(dist)): | ||
20 | matrix[i,i] = 0 | ||
21 | for j in range(i+1, len(dist)): | ||
22 | value, p = stats.ks_2samp(dist[i], dist[j]) | ||
23 | matrix[i, j] = value | ||
24 | matrix[j, i] = value | ||
25 | |||
26 | embedding = MDS(n_components=2, dissimilarity='precomputed') | ||
27 | trans = embedding.fit_transform(X=matrix) | ||
28 | x = (trans[:100,0]).tolist() | ||
29 | y = (trans[:100,1]).tolist() | ||
30 | |||
31 | x2 = (trans[100:,0]).tolist() | ||
32 | y2 = (trans[100:,1]).tolist() | ||
33 | plt.plot(x, y, 'yo') | ||
34 | plt.plot(x2, y2, 'ro') | ||
35 | plt.show() | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/statistics/.gitignore b/Metrics/Metrics-Calculation/metrics_plot/statistics/.gitignore new file mode 100644 index 00000000..b3934b01 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/statistics/.gitignore | |||
@@ -0,0 +1,3 @@ | |||
1 | # ignore everything in this folder | ||
2 | * | ||
3 | !.gitignore \ No newline at end of file | ||