diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/metrics_distance_with_selector.ipynb')
-rw-r--r-- | Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/metrics_distance_with_selector.ipynb | 955 |
1 files changed, 955 insertions, 0 deletions
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 | } | ||