aboutsummaryrefslogtreecommitdiffstats
path: root/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src
diff options
context:
space:
mode:
Diffstat (limited to 'Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src')
-rw-r--r--Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/metrics_distance.ipynb481
-rw-r--r--Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/metrics_distance_with_selector.ipynb955
-rw-r--r--Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/representative_selector .ipynb336
3 files changed, 1772 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/metrics_distance.ipynb b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/metrics_distance.ipynb
new file mode 100644
index 00000000..550e3978
--- /dev/null
+++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/metrics_distance.ipynb
@@ -0,0 +1,481 @@
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": 48,
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 "import numpy as np\n",
32 "import constants\n"
33 ]
34 },
35 {
36 "cell_type": "markdown",
37 "metadata": {},
38 "source": [
39 "### Classes"
40 ]
41 },
42 {
43 "cell_type": "markdown",
44 "metadata": {},
45 "source": [
46 "* Record the average distances of different metrics for a model to the human models "
47 ]
48 },
49 {
50 "cell_type": "code",
51 "execution_count": 49,
52 "metadata": {},
53 "outputs": [],
54 "source": [
55 "class GraphDistance:\n",
56 " #init with a graph stat and a collection of graph stats\n",
57 " def __init__(self, graphStat, collection):\n",
58 " self.graph = graphStat\n",
59 " self.collection = collection\n",
60 " self.out_d_distance = average_ks_distance(collection.out_ds, graphStat.out_d)\n",
61 " self.na_distance = average_ks_distance(collection.nas, graphStat.na)\n",
62 " self.mpc_distance = average_ks_distance(collection.mpcs, graphStat.mpc)"
63 ]
64 },
65 {
66 "cell_type": "markdown",
67 "metadata": {},
68 "source": [
69 "### Methods"
70 ]
71 },
72 {
73 "cell_type": "markdown",
74 "metadata": {},
75 "source": [
76 "* Calculate the average ks distance"
77 ]
78 },
79 {
80 "cell_type": "code",
81 "execution_count": 50,
82 "metadata": {},
83 "outputs": [],
84 "source": [
85 "def average_ks_distance(targets, sample):\n",
86 " distance = 0.0\n",
87 " for target in targets:\n",
88 " value, p = stats.ks_2samp(target, sample)\n",
89 " distance += value\n",
90 " distance = distance / len(targets)\n",
91 " return distance\n"
92 ]
93 },
94 {
95 "cell_type": "markdown",
96 "metadata": {
97 "pycharm": {
98 "name": "#%% md\n"
99 }
100 },
101 "source": [
102 "* Find the median ks distance of the same number of nodes"
103 ]
104 },
105 {
106 "cell_type": "code",
107 "execution_count": 51,
108 "metadata": {
109 "pycharm": {
110 "name": "#%%\n"
111 }
112 },
113 "outputs": [],
114 "source": [
115 "def find_median(x, metric_distances):\n",
116 " distance_dic = {}\n",
117 " for index, num_of_nodes in enumerate(x):\n",
118 " if num_of_nodes[0] not in distance_dic:\n",
119 " distance_dic[num_of_nodes[0]] = []\n",
120 " distance_dic[num_of_nodes[0]].append(metric_distances[index])\n",
121 " median_x = []\n",
122 " y = []\n",
123 " for num_of_nodes, distances in distance_dic.items():\n",
124 " median_x.append(num_of_nodes)\n",
125 " y.append(np.median(distances))\n",
126 " order = np.argsort(median_x)\n",
127 " median_x = np.array(median_x)[order]\n",
128 " median_y = np.array(y)[order]\n",
129 " return median_x, median_y\n"
130 ]
131 },
132 {
133 "cell_type": "markdown",
134 "metadata": {},
135 "source": [
136 "* Plot Diagram"
137 ]
138 },
139 {
140 "cell_type": "code",
141 "execution_count": 52,
142 "metadata": {},
143 "outputs": [],
144 "source": [
145 "# metric_selector: GraphDistance -> float\n",
146 "def plot(infos, lines, id, metric_selector,colors, title):\n",
147 " metric_distances = retrive_info_from_list(metric_selector, list(infos.values()))\n",
148 " x = retrive_info_from_list(lambda a : a.graph.num_nodes, list(infos.values()))\n",
149 " graph = plt.figure(id,figsize=(18, 10))\n",
150 " plt.title(title)\n",
151 " plt.plot(x, metric_distances, color='red', linestyle='', marker='o',alpha=0.7)\n",
152 " #plot ks distance median\n",
153 " median_x, median_y = find_median(x, metric_distances)\n",
154 " plt.plot(median_x, median_y, color='black',marker='o')\n",
155 " for i in range(0, len(lines)):\n",
156 " line_infos = retrive_info_from_list(lambda a: infos[a], lines[i])\n",
157 " line_y = retrive_info_from_list(metric_selector, line_infos)\n",
158 " line_x = retrive_info_from_list(lambda a : a.graph.num_nodes, line_infos)\n",
159 " plt.plot(line_x, line_y, marker='o', color=colors[i])\n",
160 " #graph.show()"
161 ]
162 },
163 {
164 "cell_type": "markdown",
165 "metadata": {},
166 "source": [
167 "* Retrieve information from a list "
168 ]
169 },
170 {
171 "cell_type": "code",
172 "execution_count": 53,
173 "metadata": {},
174 "outputs": [],
175 "source": [
176 "def retrive_info_from_list(selector, distances):\n",
177 " return list(map(selector, distances))"
178 ]
179 },
180 {
181 "cell_type": "markdown",
182 "metadata": {},
183 "source": [
184 "### Read Models"
185 ]
186 },
187 {
188 "cell_type": "code",
189 "execution_count": 54,
190 "metadata": {},
191 "outputs": [],
192 "source": [
193 "human = GraphCollection('../statistics/humanOutput/', 300, 'Human', True)\n",
194 "file_names = reader.readmultiplefiles('../statistics/viatraEvolve/', 1000, False)"
195 ]
196 },
197 {
198 "cell_type": "markdown",
199 "metadata": {},
200 "source": [
201 "### Calculate Distances"
202 ]
203 },
204 {
205 "cell_type": "code",
206 "execution_count": 55,
207 "metadata": {},
208 "outputs": [],
209 "source": [
210 "# Progress Widge\n",
211 "w2 = widgets.FloatProgress(\n",
212 " value=0,\n",
213 " min=0,\n",
214 " max=1.0,\n",
215 " step=0.1,\n",
216 " description='Loading Files...:',\n",
217 " bar_style='info',\n",
218 " orientation='horizontal'\n",
219 ")"
220 ]
221 },
222 {
223 "cell_type": "code",
224 "execution_count": 56,
225 "metadata": {},
226 "outputs": [
227 {
228 "data": {
229 "application/vnd.jupyter.widget-view+json": {
230 "model_id": "ca7932bce2a741afaff6b919042c42b0",
231 "version_major": 2,
232 "version_minor": 0
233 },
234 "text/plain": [
235 "FloatProgress(value=0.0, bar_style='info', description='Loading Files...:', max=1.0)"
236 ]
237 },
238 "metadata": {},
239 "output_type": "display_data"
240 }
241 ],
242 "source": [
243 "infos = []\n",
244 "# read all files\n",
245 "counter = 0.0\n",
246 "size = len(file_names)\n",
247 "#display progress bar\n",
248 "display(w2)\n",
249 "for name in file_names:\n",
250 " infos.append(GraphStat(name))\n",
251 "\n",
252 "info_dic = {}\n",
253 "for info in infos:\n",
254 " w2.value = (counter/size)\n",
255 " counter+=1\n",
256 " info = GraphDistance(info, human)\n",
257 " info_dic[info.graph.id] = info"
258 ]
259 },
260 {
261 "cell_type": "markdown",
262 "metadata": {},
263 "source": [
264 "#### Plot Graphs"
265 ]
266 },
267 {
268 "cell_type": "markdown",
269 "metadata": {},
270 "source": [
271 "* widget for select trajectory"
272 ]
273 },
274 {
275 "cell_type": "code",
276 "execution_count": 57,
277 "metadata": {},
278 "outputs": [],
279 "source": [
280 "filenames = reader.readmultiplefiles('../statistics/trajectories/', 10, False)\n",
281 "trajectories = {}\n",
282 "for name in filenames:\n",
283 " trajectories[name] = reader.readTrajectory(name)\n",
284 "\n",
285 "w = widgets.SelectMultiple(\n",
286 " options = trajectories,\n",
287 " value = [trajectories[filenames[0]]],\n",
288 " description='Trajectory:',\n",
289 " disabled=False,\n",
290 ")\n",
291 "\n",
292 "#generate random color for each line\n",
293 "colors = []\n",
294 "\n",
295 "for i in range(0, len(trajectories)):\n",
296 " color = \"#%06x\" % random.randint(0, 0xFFFFFF)\n",
297 " colors.append(color)"
298 ]
299 },
300 {
301 "cell_type": "markdown",
302 "metadata": {},
303 "source": [
304 "#### Out Degree"
305 ]
306 },
307 {
308 "cell_type": "code",
309 "execution_count": 63,
310 "metadata": {},
311 "outputs": [
312 {
313 "data": {
314 "application/vnd.jupyter.widget-view+json": {
315 "model_id": "08da62cb0c3f4e6e9591c7dc811d27cc",
316 "version_major": 2,
317 "version_minor": 0
318 },
319 "text/plain": [
320 "interactive(children=(SelectMultiple(description='Trajectory:', index=(1,), options={'../statistics/trajectori…"
321 ]
322 },
323 "metadata": {},
324 "output_type": "display_data"
325 },
326 {
327 "data": {
328 "text/plain": [
329 "<function __main__.plot_out_degree(lines)>"
330 ]
331 },
332 "execution_count": 63,
333 "metadata": {},
334 "output_type": "execute_result"
335 }
336 ],
337 "source": [
338 "def plot_out_degree(lines):\n",
339 " plot(info_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree')\n",
340 "interact(plot_out_degree, lines=w)"
341 ]
342 },
343 {
344 "cell_type": "markdown",
345 "metadata": {},
346 "source": [
347 "#### Node Activity"
348 ]
349 },
350 {
351 "cell_type": "code",
352 "execution_count": 64,
353 "metadata": {
354 "scrolled": true
355 },
356 "outputs": [
357 {
358 "data": {
359 "application/vnd.jupyter.widget-view+json": {
360 "model_id": "a708f43645a24bd2b15b53ea12c7d88f",
361 "version_major": 2,
362 "version_minor": 0
363 },
364 "text/plain": [
365 "interactive(children=(SelectMultiple(description='Trajectory:', index=(1,), options={'../statistics/trajectori…"
366 ]
367 },
368 "metadata": {},
369 "output_type": "display_data"
370 },
371 {
372 "data": {
373 "text/plain": [
374 "<function __main__.plot_na(lines)>"
375 ]
376 },
377 "execution_count": 64,
378 "metadata": {},
379 "output_type": "execute_result"
380 }
381 ],
382 "source": [
383 "def plot_na(lines):\n",
384 " plot(info_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity')\n",
385 "interact(plot_na, lines=w)"
386 ]
387 },
388 {
389 "cell_type": "markdown",
390 "metadata": {},
391 "source": [
392 "#### MPC"
393 ]
394 },
395 {
396 "cell_type": "code",
397 "execution_count": null,
398 "metadata": {},
399 "outputs": [],
400 "source": []
401 },
402 {
403 "cell_type": "code",
404 "execution_count": 65,
405 "metadata": {},
406 "outputs": [
407 {
408 "data": {
409 "application/vnd.jupyter.widget-view+json": {
410 "model_id": "124a0cb0ebfb4225bf4ced24c09032f7",
411 "version_major": 2,
412 "version_minor": 0
413 },
414 "text/plain": [
415 "interactive(children=(SelectMultiple(description='Trajectory:', index=(1,), options={'../statistics/trajectori…"
416 ]
417 },
418 "metadata": {},
419 "output_type": "display_data"
420 },
421 {
422 "data": {
423 "text/plain": [
424 "<function __main__.plot_out_degree(lines)>"
425 ]
426 },
427 "execution_count": 65,
428 "metadata": {},
429 "output_type": "execute_result"
430 }
431 ],
432 "source": [
433 "def plot_out_degree(lines):\n",
434 " plot(info_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC')\n",
435 "interact(plot_out_degree, lines=w)"
436 ]
437 },
438 {
439 "cell_type": "code",
440 "execution_count": 19,
441 "metadata": {},
442 "outputs": [],
443 "source": [
444 "for name in file_names:\n",
445 " contents = reader.readcsvfile(name)\n",
446 " if(contents['State Id'][0] == 1032396643):\n",
447 " print(name)"
448 ]
449 }
450 ],
451 "metadata": {
452 "kernelspec": {
453 "display_name": "Python 3",
454 "language": "python",
455 "name": "python3"
456 },
457 "language_info": {
458 "codemirror_mode": {
459 "name": "ipython",
460 "version": 3
461 },
462 "file_extension": ".py",
463 "mimetype": "text/x-python",
464 "name": "python",
465 "nbconvert_exporter": "python",
466 "pygments_lexer": "ipython3",
467 "version": "3.7.3"
468 },
469 "pycharm": {
470 "stem_cell": {
471 "cell_type": "raw",
472 "metadata": {
473 "collapsed": false
474 },
475 "source": []
476 }
477 }
478 },
479 "nbformat": 4,
480 "nbformat_minor": 2
481}
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/metrics_distance_with_selector.ipynb b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/metrics_distance_with_selector.ipynb
new file mode 100644
index 00000000..4c7fecb3
--- /dev/null
+++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/metrics_distance_with_selector.ipynb
@@ -0,0 +1,955 @@
1{
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "# Measuremments with Representative"
8 ]
9 },
10 {
11 "cell_type": "markdown",
12 "metadata": {},
13 "source": [
14 "### Imports"
15 ]
16 },
17 {
18 "cell_type": "code",
19 "execution_count": 2,
20 "metadata": {},
21 "outputs": [],
22 "source": [
23 "import os, sys\n",
24 "lib_path = os.path.abspath(os.path.join('..', '..', 'utils'))\n",
25 "sys.path.append(lib_path)\n",
26 "from GraphType import GraphStat\n",
27 "from GraphType import GraphCollection\n",
28 "from scipy import stats\n",
29 "from ipywidgets import interact, fixed, interactive\n",
30 "import readCSV as reader\n",
31 "import ipywidgets as widgets\n",
32 "import matplotlib.pyplot as plt\n",
33 "import random\n",
34 "import numpy as np\n",
35 "import constants\n"
36 ]
37 },
38 {
39 "cell_type": "markdown",
40 "metadata": {},
41 "source": [
42 "### Classes"
43 ]
44 },
45 {
46 "cell_type": "markdown",
47 "metadata": {},
48 "source": [
49 "* Record the distances of different metrics using a representative"
50 ]
51 },
52 {
53 "cell_type": "code",
54 "execution_count": 3,
55 "metadata": {},
56 "outputs": [],
57 "source": [
58 "class GraphDistanceWithRep:\n",
59 " #init with a graph stat and a collection of graph stats\n",
60 " def __init__(self, graphStat, rep):\n",
61 " self.graph = graphStat\n",
62 " self.rep = rep\n",
63 " self.out_d_distance, _ = stats.ks_2samp(graphStat.out_d, rep.out_d)\n",
64 " self.na_distance,_ = stats.ks_2samp(graphStat.na, rep.na)\n",
65 " self.mpc_distance,_ = stats.ks_2samp(graphStat.mpc, rep.mpc)\n"
66 ]
67 },
68 {
69 "cell_type": "markdown",
70 "metadata": {},
71 "source": [
72 "### Methods\n"
73 ]
74 },
75 {
76 "cell_type": "markdown",
77 "metadata": {},
78 "source": [
79 "* Find the median ks distance of the same number of nodes"
80 ]
81 },
82 {
83 "cell_type": "code",
84 "execution_count": 4,
85 "metadata": {},
86 "outputs": [],
87 "source": [
88 "def find_median(x, metric_distances):\n",
89 " distance_dic = {}\n",
90 " for index, num_of_nodes in enumerate(x):\n",
91 " if num_of_nodes[0] not in distance_dic:\n",
92 " distance_dic[num_of_nodes[0]] = []\n",
93 " distance_dic[num_of_nodes[0]].append(metric_distances[index])\n",
94 " median_x = []\n",
95 " y = []\n",
96 " for num_of_nodes, distances in distance_dic.items():\n",
97 " median_x.append(num_of_nodes)\n",
98 " y.append(np.median(distances))\n",
99 " order = np.argsort(median_x)\n",
100 " median_x = np.array(median_x)[order]\n",
101 " median_y = np.array(y)[order]\n",
102 " return median_x, median_y\n"
103 ]
104 },
105 {
106 "cell_type": "markdown",
107 "metadata": {},
108 "source": [
109 "* Plot Diagram"
110 ]
111 },
112 {
113 "cell_type": "code",
114 "execution_count": 38,
115 "metadata": {},
116 "outputs": [],
117 "source": [
118 "# metric_selector: GraphDistance -> float\n",
119 "def plot(infos, lines, id, metric_selector,colors, title, foldername):\n",
120 " metric_distances = retrive_info_from_list(metric_selector, list(infos.values()))\n",
121 " x = retrive_info_from_list(lambda a : a.graph.num_nodes, list(infos.values()))\n",
122 " graph = plt.figure(id,figsize=(18, 10))\n",
123 " plt.title(title)\n",
124 " plt.plot(x, metric_distances, color='red', linestyle='', marker='o',alpha=0.7)\n",
125 " #plot ks distance median\n",
126 " median_x, median_y = find_median(x, metric_distances)\n",
127 " plt.plot(median_x, median_y, color='black',marker='o')\n",
128 " for i in range(0, len(lines)):\n",
129 " line_infos = retrive_info_from_list(lambda a: infos[a], lines[i])\n",
130 " line_y = retrive_info_from_list(metric_selector, line_infos)\n",
131 " line_x = retrive_info_from_list(lambda a : a.graph.num_nodes, line_infos)\n",
132 " plt.plot(line_x, line_y, marker='o', color=colors[i])\n",
133 " mkdir_p(foldername)\n",
134 " plt.savefig(fname = foldername+title+'.jpg', dpi=150)\n",
135 " #graph.show()"
136 ]
137 },
138 {
139 "cell_type": "markdown",
140 "metadata": {},
141 "source": [
142 "* Retrieve information from a list "
143 ]
144 },
145 {
146 "cell_type": "code",
147 "execution_count": 6,
148 "metadata": {},
149 "outputs": [],
150 "source": [
151 "def retrive_info_from_list(selector, distances):\n",
152 " return list(map(selector, distances))"
153 ]
154 },
155 {
156 "cell_type": "code",
157 "execution_count": 7,
158 "metadata": {},
159 "outputs": [],
160 "source": [
161 "def readStats(path, numModels):\n",
162 " names = reader.readmultiplefiles(path, numModels, False)\n",
163 " stats = []\n",
164 " for name in names:\n",
165 " stats.append(GraphStat(name))\n",
166 " return stats"
167 ]
168 },
169 {
170 "cell_type": "code",
171 "execution_count": 8,
172 "metadata": {},
173 "outputs": [],
174 "source": [
175 "def calDistanceDic(stats, rep):\n",
176 " dic = {}\n",
177 " for info in stats:\n",
178 " info = GraphDistanceWithRep(info, rep)\n",
179 " dic[info.graph.id] = info\n",
180 " return dic"
181 ]
182 },
183 {
184 "cell_type": "code",
185 "execution_count": 25,
186 "metadata": {},
187 "outputs": [],
188 "source": [
189 "def createRandomColors(size):\n",
190 " #generate random color for each line\n",
191 " colors = []\n",
192 "\n",
193 " for i in range(0, size):\n",
194 " color = \"#%06x\" % random.randint(0, 0xFFFFFF)\n",
195 " colors.append(color)\n",
196 " return colors"
197 ]
198 },
199 {
200 "cell_type": "code",
201 "execution_count": 43,
202 "metadata": {},
203 "outputs": [],
204 "source": [
205 "def createSelectionWidge(options):\n",
206 " w = widgets.SelectMultiple(\n",
207 " options = options,\n",
208 " value = [],\n",
209 " description='Trajectory:',\n",
210 " disabled=False,\n",
211 " )\n",
212 " return w"
213 ]
214 },
215 {
216 "cell_type": "code",
217 "execution_count": 33,
218 "metadata": {},
219 "outputs": [],
220 "source": [
221 "def mkdir_p(mypath):\n",
222 " '''Creates a directory. equivalent to using mkdir -p on the command line'''\n",
223 "\n",
224 " from errno import EEXIST\n",
225 " from os import makedirs,path\n",
226 "\n",
227 " try:\n",
228 " makedirs(mypath)\n",
229 " except OSError as exc: # Python >2.5\n",
230 " if exc.errno == EEXIST and path.isdir(mypath):\n",
231 " pass\n",
232 " else: raise"
233 ]
234 },
235 {
236 "cell_type": "markdown",
237 "metadata": {},
238 "source": [
239 "## Metrics During GenerationPlots"
240 ]
241 },
242 {
243 "cell_type": "markdown",
244 "metadata": {},
245 "source": [
246 "### Read Human Representatives"
247 ]
248 },
249 {
250 "cell_type": "code",
251 "execution_count": 42,
252 "metadata": {},
253 "outputs": [],
254 "source": [
255 "### Read Models\n",
256 "#read representative\n",
257 "human_rep = GraphStat(constants.HUMAN_OUT_D_REP)\n",
258 "human_na = GraphStat(constants.HUMAN_NA_REP)\n",
259 "human_mpc = GraphStat(constants.HUMAN_MPC_REP)\n",
260 "\n",
261 "# assign rep distributions to human_rep\n",
262 "human_rep.na = human_na.na\n",
263 "human_rep.mpc = human_mpc.mpc"
264 ]
265 },
266 {
267 "cell_type": "markdown",
268 "metadata": {},
269 "source": [
270 "## Viatra No Constraint"
271 ]
272 },
273 {
274 "cell_type": "code",
275 "execution_count": 15,
276 "metadata": {},
277 "outputs": [],
278 "source": [
279 "# Read generated models\n",
280 "viatra_no_con_stats = readStats('../input/viatra_nocon_output/', 5000)\n",
281 "viatra_no_con_dic = calDistanceDic(viatra_no_con_stats, human_rep)"
282 ]
283 },
284 {
285 "cell_type": "code",
286 "execution_count": 46,
287 "metadata": {},
288 "outputs": [],
289 "source": [
290 "filenames = reader.readmultiplefiles('../input/viatra_nocon_output/trajectories/', 15, False)\n",
291 "trajectories = {}\n",
292 "for name in filenames:\n",
293 " trajectories[name] = reader.readTrajectory(name)\n",
294 "w = createSelectionWidge(trajectories)\n",
295 "colors = createRandomColors(len(trajectories))"
296 ]
297 },
298 {
299 "cell_type": "code",
300 "execution_count": 77,
301 "metadata": {},
302 "outputs": [
303 {
304 "data": {
305 "application/vnd.jupyter.widget-view+json": {
306 "model_id": "9519be563fbc41c28921c77ef6481b17",
307 "version_major": 2,
308 "version_minor": 0
309 },
310 "text/plain": [
311 "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…"
312 ]
313 },
314 "metadata": {},
315 "output_type": "display_data"
316 },
317 {
318 "data": {
319 "text/plain": [
320 "<function __main__.plot_out_degree(lines)>"
321 ]
322 },
323 "execution_count": 77,
324 "metadata": {},
325 "output_type": "execute_result"
326 }
327 ],
328 "source": [
329 "def plot_out_degree(lines):\n",
330 " plot(viatra_no_con_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree', '../output/viatra_no_constraints/')\n",
331 "interact(plot_out_degree, lines=w)"
332 ]
333 },
334 {
335 "cell_type": "code",
336 "execution_count": 78,
337 "metadata": {},
338 "outputs": [
339 {
340 "data": {
341 "application/vnd.jupyter.widget-view+json": {
342 "model_id": "c896725e542c4bf8a1bc76ba66819b20",
343 "version_major": 2,
344 "version_minor": 0
345 },
346 "text/plain": [
347 "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…"
348 ]
349 },
350 "metadata": {},
351 "output_type": "display_data"
352 },
353 {
354 "data": {
355 "text/plain": [
356 "<function __main__.plot_out_na(lines)>"
357 ]
358 },
359 "execution_count": 78,
360 "metadata": {},
361 "output_type": "execute_result"
362 }
363 ],
364 "source": [
365 "def plot_out_na(lines):\n",
366 " plot(viatra_no_con_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity', '../output/viatra_no_constraints/')\n",
367 "interact(plot_out_na, lines=w)"
368 ]
369 },
370 {
371 "cell_type": "code",
372 "execution_count": 79,
373 "metadata": {},
374 "outputs": [
375 {
376 "data": {
377 "application/vnd.jupyter.widget-view+json": {
378 "model_id": "880410d675624545ab73977a463bb5c9",
379 "version_major": 2,
380 "version_minor": 0
381 },
382 "text/plain": [
383 "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…"
384 ]
385 },
386 "metadata": {},
387 "output_type": "display_data"
388 },
389 {
390 "data": {
391 "text/plain": [
392 "<function __main__.plot_out_mpc(lines)>"
393 ]
394 },
395 "execution_count": 79,
396 "metadata": {},
397 "output_type": "execute_result"
398 }
399 ],
400 "source": [
401 "def plot_out_mpc(lines):\n",
402 " plot(viatra_no_con_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC', '../output/viatra_no_constraints/')\n",
403 "interact(plot_out_mpc, lines=w)"
404 ]
405 },
406 {
407 "cell_type": "markdown",
408 "metadata": {},
409 "source": [
410 "## Viatra with constraints"
411 ]
412 },
413 {
414 "cell_type": "code",
415 "execution_count": 50,
416 "metadata": {},
417 "outputs": [],
418 "source": [
419 "viatra_con_stats = readStats('../input/viatra_con_output/',5000)\n",
420 "viatra_con_dic = calDistanceDic(viatra_con_stats, human_rep)\n",
421 "\n",
422 "# trajectories and colors\n",
423 "trajectories = {}\n",
424 "w = createSelectionWidge(trajectories)\n",
425 "colors = createRandomColors(len(trajectories))"
426 ]
427 },
428 {
429 "cell_type": "code",
430 "execution_count": 51,
431 "metadata": {},
432 "outputs": [
433 {
434 "data": {
435 "application/vnd.jupyter.widget-view+json": {
436 "model_id": "0d04d6db770a49f4a160ff55cc7131f6",
437 "version_major": 2,
438 "version_minor": 0
439 },
440 "text/plain": [
441 "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…"
442 ]
443 },
444 "metadata": {},
445 "output_type": "display_data"
446 },
447 {
448 "data": {
449 "text/plain": [
450 "<function __main__.plot_out_degree(lines)>"
451 ]
452 },
453 "execution_count": 51,
454 "metadata": {},
455 "output_type": "execute_result"
456 }
457 ],
458 "source": [
459 "def plot_out_degree(lines):\n",
460 " plot(viatra_con_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree', '../output/viatra_constraints/')\n",
461 "interact(plot_out_degree, lines=[[]])"
462 ]
463 },
464 {
465 "cell_type": "code",
466 "execution_count": 52,
467 "metadata": {},
468 "outputs": [
469 {
470 "data": {
471 "application/vnd.jupyter.widget-view+json": {
472 "model_id": "96eebad1f6274d79ad377c8c54b44615",
473 "version_major": 2,
474 "version_minor": 0
475 },
476 "text/plain": [
477 "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…"
478 ]
479 },
480 "metadata": {},
481 "output_type": "display_data"
482 },
483 {
484 "data": {
485 "text/plain": [
486 "<function __main__.plot_na(lines)>"
487 ]
488 },
489 "execution_count": 52,
490 "metadata": {},
491 "output_type": "execute_result"
492 }
493 ],
494 "source": [
495 "def plot_na(lines):\n",
496 " plot(viatra_con_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity', '../output/viatra_constraints/')\n",
497 "interact(plot_na, lines=[[]])"
498 ]
499 },
500 {
501 "cell_type": "code",
502 "execution_count": 53,
503 "metadata": {},
504 "outputs": [
505 {
506 "data": {
507 "application/vnd.jupyter.widget-view+json": {
508 "model_id": "4fc2714a3cd3440daf5014bb4b942b9a",
509 "version_major": 2,
510 "version_minor": 0
511 },
512 "text/plain": [
513 "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…"
514 ]
515 },
516 "metadata": {},
517 "output_type": "display_data"
518 },
519 {
520 "data": {
521 "text/plain": [
522 "<function __main__.plot_mpc(lines)>"
523 ]
524 },
525 "execution_count": 53,
526 "metadata": {},
527 "output_type": "execute_result"
528 }
529 ],
530 "source": [
531 "def plot_mpc(lines):\n",
532 " plot(viatra_con_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC', '../output/viatra_constraints/')\n",
533 "interact(plot_mpc, lines=[[]])"
534 ]
535 },
536 {
537 "cell_type": "markdown",
538 "metadata": {},
539 "source": [
540 "## Controlled RandomEMF"
541 ]
542 },
543 {
544 "cell_type": "code",
545 "execution_count": 59,
546 "metadata": {},
547 "outputs": [],
548 "source": [
549 "random_emf_stats = readStats('../input/random_emf_output/',5000)\n",
550 "random_emf_dic = calDistanceDic(random_emf_stats, human_rep)\n",
551 "\n",
552 "# trajectories and colors\n",
553 "trajectories = {}\n",
554 "w = createSelectionWidge(trajectories)\n",
555 "colors = createRandomColors(len(trajectories))"
556 ]
557 },
558 {
559 "cell_type": "code",
560 "execution_count": 60,
561 "metadata": {},
562 "outputs": [
563 {
564 "data": {
565 "application/vnd.jupyter.widget-view+json": {
566 "model_id": "4401931533b5497f864f146d7b4dcd3c",
567 "version_major": 2,
568 "version_minor": 0
569 },
570 "text/plain": [
571 "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…"
572 ]
573 },
574 "metadata": {},
575 "output_type": "display_data"
576 },
577 {
578 "data": {
579 "text/plain": [
580 "<function __main__.plot_out_degree(lines)>"
581 ]
582 },
583 "execution_count": 60,
584 "metadata": {},
585 "output_type": "execute_result"
586 }
587 ],
588 "source": [
589 "def plot_out_degree(lines):\n",
590 " plot(random_emf_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree', '../output/random_emf/')\n",
591 "interact(plot_out_degree, lines=[[]])"
592 ]
593 },
594 {
595 "cell_type": "code",
596 "execution_count": 61,
597 "metadata": {},
598 "outputs": [
599 {
600 "data": {
601 "application/vnd.jupyter.widget-view+json": {
602 "model_id": "fb7bdedff841420bb8f817013f565020",
603 "version_major": 2,
604 "version_minor": 0
605 },
606 "text/plain": [
607 "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…"
608 ]
609 },
610 "metadata": {},
611 "output_type": "display_data"
612 },
613 {
614 "data": {
615 "text/plain": [
616 "<function __main__.plot_node_activity(lines)>"
617 ]
618 },
619 "execution_count": 61,
620 "metadata": {},
621 "output_type": "execute_result"
622 }
623 ],
624 "source": [
625 "def plot_node_activity(lines):\n",
626 " plot(random_emf_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity', '../output/random_emf/')\n",
627 "interact(plot_node_activity, lines=[[]])"
628 ]
629 },
630 {
631 "cell_type": "code",
632 "execution_count": 62,
633 "metadata": {},
634 "outputs": [
635 {
636 "data": {
637 "application/vnd.jupyter.widget-view+json": {
638 "model_id": "6b0c349c4a3b4813825513f739ea30da",
639 "version_major": 2,
640 "version_minor": 0
641 },
642 "text/plain": [
643 "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…"
644 ]
645 },
646 "metadata": {},
647 "output_type": "display_data"
648 },
649 {
650 "data": {
651 "text/plain": [
652 "<function __main__.plot_mpc(lines)>"
653 ]
654 },
655 "execution_count": 62,
656 "metadata": {},
657 "output_type": "execute_result"
658 }
659 ],
660 "source": [
661 "def plot_mpc(lines):\n",
662 " plot(random_emf_dic, lines, 0, lambda a: a.mpc_distance, colors, 'mpc', '../output/random_emf/')\n",
663 "interact(plot_mpc, lines=[[]])"
664 ]
665 },
666 {
667 "cell_type": "markdown",
668 "metadata": {},
669 "source": [
670 "## Controlled Viatra with MPC"
671 ]
672 },
673 {
674 "cell_type": "code",
675 "execution_count": 67,
676 "metadata": {},
677 "outputs": [],
678 "source": [
679 "con_viatra_stats = readStats('../input/controled_viatra_mpc/',5000)\n",
680 "con_viatra_dic = calDistanceDic(con_viatra_stats, human_rep)\n",
681 "\n",
682 "# trajectories and colors\n",
683 "trajectories = {}\n",
684 "w = createSelectionWidge(trajectories)\n",
685 "colors = createRandomColors(len(trajectories))"
686 ]
687 },
688 {
689 "cell_type": "code",
690 "execution_count": 74,
691 "metadata": {},
692 "outputs": [
693 {
694 "data": {
695 "application/vnd.jupyter.widget-view+json": {
696 "model_id": "b76901ba9d44433984032e0dc5679fa9",
697 "version_major": 2,
698 "version_minor": 0
699 },
700 "text/plain": [
701 "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…"
702 ]
703 },
704 "metadata": {},
705 "output_type": "display_data"
706 },
707 {
708 "data": {
709 "text/plain": [
710 "<function __main__.plot_out_degree(lines)>"
711 ]
712 },
713 "execution_count": 74,
714 "metadata": {},
715 "output_type": "execute_result"
716 }
717 ],
718 "source": [
719 "def plot_out_degree(lines):\n",
720 " plot(con_viatra_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out_degree', '../output/controled_viatra_with_mpc/')\n",
721 "interact(plot_out_degree, lines=w)"
722 ]
723 },
724 {
725 "cell_type": "code",
726 "execution_count": 75,
727 "metadata": {},
728 "outputs": [
729 {
730 "data": {
731 "application/vnd.jupyter.widget-view+json": {
732 "model_id": "9e0d61e29b02467cb52618860a1bde7f",
733 "version_major": 2,
734 "version_minor": 0
735 },
736 "text/plain": [
737 "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…"
738 ]
739 },
740 "metadata": {},
741 "output_type": "display_data"
742 },
743 {
744 "data": {
745 "text/plain": [
746 "<function __main__.plot_na(lines)>"
747 ]
748 },
749 "execution_count": 75,
750 "metadata": {},
751 "output_type": "execute_result"
752 }
753 ],
754 "source": [
755 "def plot_na(lines):\n",
756 " plot(con_viatra_dic, lines, 0, lambda a: a.na_distance, colors, 'Node Activity', '../output/controled_viatra_with_mpc/')\n",
757 "interact(plot_na, lines=w)"
758 ]
759 },
760 {
761 "cell_type": "code",
762 "execution_count": 76,
763 "metadata": {},
764 "outputs": [
765 {
766 "data": {
767 "application/vnd.jupyter.widget-view+json": {
768 "model_id": "70074805fee44a1aa5b9ccb3770b5c0c",
769 "version_major": 2,
770 "version_minor": 0
771 },
772 "text/plain": [
773 "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…"
774 ]
775 },
776 "metadata": {},
777 "output_type": "display_data"
778 },
779 {
780 "data": {
781 "text/plain": [
782 "<function __main__.plot_mpc(lines)>"
783 ]
784 },
785 "execution_count": 76,
786 "metadata": {},
787 "output_type": "execute_result"
788 }
789 ],
790 "source": [
791 "def plot_mpc(lines):\n",
792 " plot(con_viatra_dic, lines, 0, lambda a: a.mpc_distance, colors, 'mpc', '../output/controled_viatra_with_mpc/')\n",
793 "interact(plot_mpc, lines=w)"
794 ]
795 },
796 {
797 "cell_type": "markdown",
798 "metadata": {},
799 "source": [
800 "## (Pseudo) Random EMF instantiator"
801 ]
802 },
803 {
804 "cell_type": "code",
805 "execution_count": 80,
806 "metadata": {},
807 "outputs": [],
808 "source": [
809 "random_emf_stats = readStats('../input/real_random_output/',5000)\n",
810 "random_emf_dic = calDistanceDic(random_emf_stats, human_rep)\n",
811 "\n",
812 "# trajectories and colors\n",
813 "trajectories = {}\n",
814 "w = createSelectionWidge(trajectories)\n",
815 "colors = createRandomColors(len(trajectories))"
816 ]
817 },
818 {
819 "cell_type": "code",
820 "execution_count": 82,
821 "metadata": {},
822 "outputs": [
823 {
824 "data": {
825 "application/vnd.jupyter.widget-view+json": {
826 "model_id": "912ba2fdfd7c46848065f174aa6177e0",
827 "version_major": 2,
828 "version_minor": 0
829 },
830 "text/plain": [
831 "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…"
832 ]
833 },
834 "metadata": {},
835 "output_type": "display_data"
836 },
837 {
838 "data": {
839 "text/plain": [
840 "<function __main__.plot_out_degree(lines)>"
841 ]
842 },
843 "execution_count": 82,
844 "metadata": {},
845 "output_type": "execute_result"
846 }
847 ],
848 "source": [
849 "def plot_out_degree(lines):\n",
850 " plot(random_emf_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out_degree', '../output/random_emf_instantiator/')\n",
851 "interact(plot_out_degree, lines=w)"
852 ]
853 },
854 {
855 "cell_type": "code",
856 "execution_count": 83,
857 "metadata": {},
858 "outputs": [
859 {
860 "data": {
861 "application/vnd.jupyter.widget-view+json": {
862 "model_id": "0ba621dd0e7d4957aaff2cf209bba165",
863 "version_major": 2,
864 "version_minor": 0
865 },
866 "text/plain": [
867 "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…"
868 ]
869 },
870 "metadata": {},
871 "output_type": "display_data"
872 },
873 {
874 "data": {
875 "text/plain": [
876 "<function __main__.plot_na(lines)>"
877 ]
878 },
879 "execution_count": 83,
880 "metadata": {},
881 "output_type": "execute_result"
882 }
883 ],
884 "source": [
885 "def plot_na(lines):\n",
886 " plot(random_emf_dic, lines, 0, lambda a: a.na_distance, colors, 'Node Activity', '../output/random_emf_instantiator/')\n",
887 "interact(plot_na, lines=w)"
888 ]
889 },
890 {
891 "cell_type": "code",
892 "execution_count": 84,
893 "metadata": {},
894 "outputs": [
895 {
896 "data": {
897 "application/vnd.jupyter.widget-view+json": {
898 "model_id": "d432bbae1c6f48c3acd1767f2e2b13c7",
899 "version_major": 2,
900 "version_minor": 0
901 },
902 "text/plain": [
903 "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…"
904 ]
905 },
906 "metadata": {},
907 "output_type": "display_data"
908 },
909 {
910 "data": {
911 "text/plain": [
912 "<function __main__.plot_mpc(lines)>"
913 ]
914 },
915 "execution_count": 84,
916 "metadata": {},
917 "output_type": "execute_result"
918 }
919 ],
920 "source": [
921 "def plot_mpc(lines):\n",
922 " plot(random_emf_dic, lines, 0, lambda a: a.mpc_distance, colors, 'mpc', '../output/random_emf_instantiator/')\n",
923 "interact(plot_mpc, lines=w)"
924 ]
925 },
926 {
927 "cell_type": "code",
928 "execution_count": null,
929 "metadata": {},
930 "outputs": [],
931 "source": []
932 }
933 ],
934 "metadata": {
935 "kernelspec": {
936 "display_name": "Python 3",
937 "language": "python",
938 "name": "python3"
939 },
940 "language_info": {
941 "codemirror_mode": {
942 "name": "ipython",
943 "version": 3
944 },
945 "file_extension": ".py",
946 "mimetype": "text/x-python",
947 "name": "python",
948 "nbconvert_exporter": "python",
949 "pygments_lexer": "ipython3",
950 "version": "3.7.3"
951 }
952 },
953 "nbformat": 4,
954 "nbformat_minor": 2
955}
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/representative_selector .ipynb b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/representative_selector .ipynb
new file mode 100644
index 00000000..9653b2a0
--- /dev/null
+++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/representative_selector .ipynb
@@ -0,0 +1,336 @@
1{
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "## Use K-medoid algorithm to find the suitable human model representitives"
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 "import os, sys\n",
24 "lib_path = os.path.abspath(os.path.join('..', '..', 'utils'))\n",
25 "sys.path.append(lib_path)\n",
26 "from GraphType import GraphStat\n",
27 "import readCSV as reader\n",
28 "from scipy import stats\n",
29 "from ipywidgets import interact, fixed, interactive\n",
30 "import ipywidgets as widgets\n",
31 "from pyclustering.cluster.kmedoids import kmedoids\n",
32 "from pyclustering.utils.metric import distance_metric, type_metric\n",
33 "import random"
34 ]
35 },
36 {
37 "cell_type": "markdown",
38 "metadata": {},
39 "source": [
40 "### Define a new distance metric"
41 ]
42 },
43 {
44 "cell_type": "code",
45 "execution_count": 2,
46 "metadata": {},
47 "outputs": [],
48 "source": [
49 "def ks_value(dest1, dest2):\n",
50 " value, p = stats.ks_2samp(dest1, dest2)\n",
51 " return value\n",
52 "\n",
53 "\n",
54 "ks_metric = distance_metric(type_metric.USER_DEFINED, func=ks_value)"
55 ]
56 },
57 {
58 "cell_type": "markdown",
59 "metadata": {},
60 "source": [
61 "### Read Human Models"
62 ]
63 },
64 {
65 "cell_type": "code",
66 "execution_count": 4,
67 "metadata": {},
68 "outputs": [
69 {
70 "data": {
71 "text/plain": [
72 "1253"
73 ]
74 },
75 "execution_count": 4,
76 "metadata": {},
77 "output_type": "execute_result"
78 }
79 ],
80 "source": [
81 "# Progress Widge\n",
82 "w = widgets.FloatProgress(\n",
83 " value=0,\n",
84 " min=0,\n",
85 " max=1.0,\n",
86 " step=0.1,\n",
87 " description='Loading Files...:',\n",
88 " bar_style='info',\n",
89 " orientation='horizontal'\n",
90 ")\n",
91 "\n",
92 "\n",
93 "humanFiles = reader.readmultiplefiles('../input/humanOutput/', 1300, False)\n",
94 "modelToFileName = {}\n",
95 "for name in humanFiles:\n",
96 " modelToFileName[GraphStat(name)] = name\n",
97 "\n",
98 "models = list(modelToFileName.keys())\n",
99 "len(humanFiles)"
100 ]
101 },
102 {
103 "cell_type": "markdown",
104 "metadata": {},
105 "source": [
106 "### Find Representative by K-medroid for different dists on GraphStat"
107 ]
108 },
109 {
110 "cell_type": "markdown",
111 "metadata": {},
112 "source": [
113 "* Returns the index of the representative"
114 ]
115 },
116 {
117 "cell_type": "code",
118 "execution_count": 5,
119 "metadata": {},
120 "outputs": [],
121 "source": [
122 "def findRep(graphStats, func):\n",
123 " out_ds = list(map(func, models))\n",
124 "\n",
125 " #choose a random starting point\n",
126 " start_index = random.randint(0, len(out_ds))\n",
127 "\n",
128 " # start with one initial metrid [start_index]\n",
129 " outdegree_kmedoid = kmedoids(out_ds, [start_index], metric=ks_metric)\n",
130 "\n",
131 " outdegree_kmedoid.process()\n",
132 " centoids = outdegree_kmedoid.get_medoids()\n",
133 " return centoids[0]"
134 ]
135 },
136 {
137 "cell_type": "markdown",
138 "metadata": {},
139 "source": [
140 "### Find representative for out degree"
141 ]
142 },
143 {
144 "cell_type": "markdown",
145 "metadata": {},
146 "source": [
147 "* the rep found is ../input/humanOutput\\R_20158_run_1.csv\n",
148 "* the average distance between it and others is 0.05515988287586802"
149 ]
150 },
151 {
152 "cell_type": "code",
153 "execution_count": 6,
154 "metadata": {},
155 "outputs": [
156 {
157 "name": "stdout",
158 "output_type": "stream",
159 "text": [
160 "../input/humanOutput\\R_20158_run_1.csv\n",
161 "../input/humanOutput\\R_20158_run_1.csv\n"
162 ]
163 }
164 ],
165 "source": [
166 "od_rep_index = findRep(models, lambda m: m.out_d)\n",
167 "print(list(modelToFileName.values())[od_rep_index])\n",
168 "od_rep_model = models[od_rep_index]\n",
169 "print(modelToFileName[od_rep_model])\n"
170 ]
171 },
172 {
173 "cell_type": "code",
174 "execution_count": 19,
175 "metadata": {},
176 "outputs": [
177 {
178 "name": "stdout",
179 "output_type": "stream",
180 "text": [
181 "0.05515988287586802\n"
182 ]
183 }
184 ],
185 "source": [
186 "total_distance = 0\n",
187 "count = 0\n",
188 "for model in models:\n",
189 " total_distance += ks_value(od_rep_model.out_d, model.out_d)\n",
190 "print(total_distance / len(models))"
191 ]
192 },
193 {
194 "cell_type": "markdown",
195 "metadata": {},
196 "source": [
197 "### Find Representative for node activities"
198 ]
199 },
200 {
201 "cell_type": "markdown",
202 "metadata": {},
203 "source": [
204 "* the rep found is ../input/humanOutput\\R_2016176_run_1.csv\n",
205 "* the average distance between it and others is 0.05275267434589047"
206 ]
207 },
208 {
209 "cell_type": "code",
210 "execution_count": 7,
211 "metadata": {},
212 "outputs": [
213 {
214 "name": "stdout",
215 "output_type": "stream",
216 "text": [
217 "../input/humanOutput\\R_2016176_run_1.csv\n",
218 "../input/humanOutput\\R_2016176_run_1.csv\n"
219 ]
220 }
221 ],
222 "source": [
223 "total_distance = 0\n",
224 "for model in models:\n",
225 " total_distance += ks_value(od_rep_model.mpc, model.mpc)\n",
226 "print(total_distance / len(models))"
227 ]
228 },
229 {
230 "cell_type": "code",
231 "execution_count": 18,
232 "metadata": {},
233 "outputs": [
234 {
235 "name": "stdout",
236 "output_type": "stream",
237 "text": [
238 "0.05275267434589047\n"
239 ]
240 }
241 ],
242 "source": [
243 "total_distance = 0\n",
244 "count = 0\n",
245 "for model in models:\n",
246 " total_distance += ks_value(od_rep_model.na, model.na)\n",
247 "print(total_distance / len(models))"
248 ]
249 },
250 {
251 "cell_type": "markdown",
252 "metadata": {},
253 "source": [
254 "### Find Representative for MPC"
255 ]
256 },
257 {
258 "cell_type": "markdown",
259 "metadata": {},
260 "source": [
261 "* the rep found is ../input/humanOutput\\R_2015246_run_1.csv\n",
262 "* the average distance between it and others is 0.08556632702185384"
263 ]
264 },
265 {
266 "cell_type": "code",
267 "execution_count": 8,
268 "metadata": {},
269 "outputs": [
270 {
271 "name": "stdout",
272 "output_type": "stream",
273 "text": [
274 "../input/humanOutput\\R_2015246_run_1.csv\n",
275 "../input/humanOutput\\R_2015246_run_1.csv\n"
276 ]
277 }
278 ],
279 "source": [
280 "mpc_rep_index = findRep(models, lambda m: m.mpc)\n",
281 "print(list(modelToFileName.values())[mpc_rep_index])\n",
282 "mpc_rep_model = models[mpc_rep_index]\n",
283 "print(modelToFileName[mpc_rep_model])"
284 ]
285 },
286 {
287 "cell_type": "code",
288 "execution_count": 20,
289 "metadata": {},
290 "outputs": [
291 {
292 "name": "stdout",
293 "output_type": "stream",
294 "text": [
295 "0.08556632702185384\n"
296 ]
297 }
298 ],
299 "source": [
300 "total_distance = 0\n",
301 "count = 0\n",
302 "for model in models:\n",
303 " total_distance += ks_value(od_rep_model.mpc, model.mpc)\n",
304 "print(total_distance / len(models))"
305 ]
306 },
307 {
308 "cell_type": "code",
309 "execution_count": null,
310 "metadata": {},
311 "outputs": [],
312 "source": []
313 }
314 ],
315 "metadata": {
316 "kernelspec": {
317 "display_name": "Python 3",
318 "language": "python",
319 "name": "python3"
320 },
321 "language_info": {
322 "codemirror_mode": {
323 "name": "ipython",
324 "version": 3
325 },
326 "file_extension": ".py",
327 "mimetype": "text/x-python",
328 "name": "python",
329 "nbconvert_exporter": "python",
330 "pygments_lexer": "ipython3",
331 "version": "3.7.3"
332 }
333 },
334 "nbformat": 4,
335 "nbformat_minor": 2
336}