diff options
author | 2019-05-29 09:55:30 -0400 | |
---|---|---|
committer | 2019-05-29 09:55:30 -0400 | |
commit | a1322f1dc5f6ea53712093f75e7c36d01074f669 (patch) | |
tree | 27a6551c7d4a958fa2e924234c8b6a7a2d7604e7 /Metrics/Metrics-Calculation/metrics_plot/src/Metrics Comparison .ipynb | |
parent | added plot median ks distance line (diff) | |
download | VIATRA-Generator-a1322f1dc5f6ea53712093f75e7c36d01074f669.tar.gz VIATRA-Generator-a1322f1dc5f6ea53712093f75e7c36d01074f669.tar.zst VIATRA-Generator-a1322f1dc5f6ea53712093f75e7c36d01074f669.zip |
metric plot based on chosen rep with k-medoid method
Diffstat (limited to 'Metrics/Metrics-Calculation/metrics_plot/src/Metrics Comparison .ipynb')
-rw-r--r-- | Metrics/Metrics-Calculation/metrics_plot/src/Metrics Comparison .ipynb | 217 |
1 files changed, 0 insertions, 217 deletions
diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/Metrics Comparison .ipynb b/Metrics/Metrics-Calculation/metrics_plot/src/Metrics Comparison .ipynb deleted file mode 100644 index 04af8773..00000000 --- a/Metrics/Metrics-Calculation/metrics_plot/src/Metrics Comparison .ipynb +++ /dev/null | |||
@@ -1,217 +0,0 @@ | |||
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": 14, | ||
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": 15, | ||
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": 16, | ||
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": 17, | ||
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": 18, | ||
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": 19, | ||
119 | "metadata": {}, | ||
120 | "outputs": [ | ||
121 | { | ||
122 | "ename": "ValueError", | ||
123 | "evalue": "too many values to unpack (expected 3)", | ||
124 | "output_type": "error", | ||
125 | "traceback": [ | ||
126 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | ||
127 | "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", | ||
128 | "\u001b[1;32m<ipython-input-19-c45dfc2a26c6>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mhuman\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mGraphType\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'../statistics/humanOutput/'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m300\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[0mviatra30\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mGraphType\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'../statistics/viatraOutput30/'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m300\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mviatra100\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mGraphType\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'../statistics/viatraOutput100/'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m300\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mrandom\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mGraphType\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'../statistics/randomOutput/'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m300\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0malloy\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mGraphType\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'../statistics/alloyOutput/'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m300\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | ||
129 | "\u001b[1;32m<ipython-input-18-556621ada738>\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, path, number)\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[0mmodels\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mreader\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreadmultiplefiles\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnumber\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmodels\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[1;32m---> 10\u001b[1;33m \u001b[0mout_d\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mna\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmpc\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mreader\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetmetrics\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmodels\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 11\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mout_ds\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mout_d\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnas\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mna\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | ||
130 | "\u001b[1;31mValueError\u001b[0m: too many values to unpack (expected 3)" | ||
131 | ] | ||
132 | } | ||
133 | ], | ||
134 | "source": [ | ||
135 | "human = GraphType('../statistics/humanOutput/', 300)\n", | ||
136 | "viatra30 = GraphType('../statistics/viatraOutput30/', 300)\n", | ||
137 | "viatra100 = GraphType('../statistics/viatraOutput100/', 300)\n", | ||
138 | "random = GraphType('../statistics/randomOutput/', 300)\n", | ||
139 | "alloy = GraphType('../statistics/alloyOutput/', 300)" | ||
140 | ] | ||
141 | }, | ||
142 | { | ||
143 | "cell_type": "markdown", | ||
144 | "metadata": {}, | ||
145 | "source": [ | ||
146 | "* outdegree comparison for human, Viatra30, and alloy" | ||
147 | ] | ||
148 | }, | ||
149 | { | ||
150 | "cell_type": "code", | ||
151 | "execution_count": 20, | ||
152 | "metadata": {}, | ||
153 | "outputs": [ | ||
154 | { | ||
155 | "ename": "NameError", | ||
156 | "evalue": "name 'viatra30' is not defined", | ||
157 | "output_type": "error", | ||
158 | "traceback": [ | ||
159 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | ||
160 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", | ||
161 | "\u001b[1;32m<ipython-input-20-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", | ||
162 | "\u001b[1;31mNameError\u001b[0m: name 'viatra30' is not defined" | ||
163 | ] | ||
164 | } | ||
165 | ], | ||
166 | "source": [ | ||
167 | "out_d_coords = calculateMDS(calculateKSMatrix([viatra30.out_ds, alloy.out_ds, human.out_ds]))\n", | ||
168 | "plot(['Viatra (30 nodes)', 'Alloy (30 nodes)' , 'Human'], out_d_coords,0, 'Out Degree')" | ||
169 | ] | ||
170 | }, | ||
171 | { | ||
172 | "cell_type": "markdown", | ||
173 | "metadata": {}, | ||
174 | "source": [ | ||
175 | "* outdegree comparison for human, Viatra30, and alloy" | ||
176 | ] | ||
177 | }, | ||
178 | { | ||
179 | "cell_type": "code", | ||
180 | "execution_count": null, | ||
181 | "metadata": {}, | ||
182 | "outputs": [], | ||
183 | "source": [ | ||
184 | "out_d_coords = calculateMDS(calculateKSMatrix([viatra30.nas, alloy.nas, human.nas]))\n", | ||
185 | "plot(['Viatra (30 nodes)', 'Alloy (30 nodes)' , 'Human'], out_d_coords,0, 'Node Activity')" | ||
186 | ] | ||
187 | }, | ||
188 | { | ||
189 | "cell_type": "code", | ||
190 | "execution_count": null, | ||
191 | "metadata": {}, | ||
192 | "outputs": [], | ||
193 | "source": [] | ||
194 | } | ||
195 | ], | ||
196 | "metadata": { | ||
197 | "kernelspec": { | ||
198 | "display_name": "Python 3", | ||
199 | "language": "python", | ||
200 | "name": "python3" | ||
201 | }, | ||
202 | "language_info": { | ||
203 | "codemirror_mode": { | ||
204 | "name": "ipython", | ||
205 | "version": 3 | ||
206 | }, | ||
207 | "file_extension": ".py", | ||
208 | "mimetype": "text/x-python", | ||
209 | "name": "python", | ||
210 | "nbconvert_exporter": "python", | ||
211 | "pygments_lexer": "ipython3", | ||
212 | "version": "3.7.3" | ||
213 | } | ||
214 | }, | ||
215 | "nbformat": 4, | ||
216 | "nbformat_minor": 2 | ||
217 | } | ||