aboutsummaryrefslogtreecommitdiffstats
path: root/Metrics/Metrics-Calculation/metrics_plot
diff options
context:
space:
mode:
Diffstat (limited to 'Metrics/Metrics-Calculation/metrics_plot')
-rw-r--r--Metrics/Metrics-Calculation/metrics_plot/model comparison/input/.gitignore3
-rw-r--r--Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/MPC.pngbin0 -> 99670 bytes
-rw-r--r--Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Node Activity.pngbin0 -> 85981 bytes
-rw-r--r--Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Out Degree.pngbin0 -> 78151 bytes
-rw-r--r--Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py98
-rw-r--r--Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/MPC.pngbin114616 -> 0 bytes
-rw-r--r--Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/Node Activity.pngbin92967 -> 0 bytes
-rw-r--r--Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/Out Degree.pngbin118164 -> 0 bytes
-rw-r--r--Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance_with_selector.ipynb204
-rw-r--r--Metrics/Metrics-Calculation/metrics_plot/utils/GraphType.py29
-rw-r--r--Metrics/Metrics-Calculation/metrics_plot/utils/constants.py25
-rw-r--r--Metrics/Metrics-Calculation/metrics_plot/utils/readCSV.py169
12 files changed, 506 insertions, 22 deletions
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/input/.gitignore b/Metrics/Metrics-Calculation/metrics_plot/model comparison/input/.gitignore
new file mode 100644
index 00000000..b3934b01
--- /dev/null
+++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/input/.gitignore
@@ -0,0 +1,3 @@
1# ignore everything in this folder
2*
3!.gitignore \ No newline at end of file
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/MPC.png
new file mode 100644
index 00000000..e660f3da
--- /dev/null
+++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/MPC.png
Binary files differ
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Node Activity.png
new file mode 100644
index 00000000..92047e47
--- /dev/null
+++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Node Activity.png
Binary files differ
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Out Degree.png
new file mode 100644
index 00000000..dad7483f
--- /dev/null
+++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Out Degree.png
Binary files differ
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py b/Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py
new file mode 100644
index 00000000..2f39ca93
--- /dev/null
+++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py
@@ -0,0 +1,98 @@
1import os, sys
2lib_path = os.path.abspath(os.path.join('..', '..', 'utils'))
3sys.path.append(lib_path)
4import glob
5import random
6from sklearn.manifold import MDS
7import matplotlib.pyplot as plt
8from scipy import stats
9import numpy as np
10from GraphType import GraphCollection
11
12def main():
13 # read models
14 human = GraphCollection('../input/humanOutput/', 500, 'Human')
15 viatra30 = GraphCollection('../input/viatraOutput30/', 500, 'Viatra (30 nodes)')
16 # viatra60 = GraphCollection('../input/viatraOutput60/', 500, 'Viatra (60 nodes)')
17 # viatra100 = GraphCollection('../input/viatraOutput100/', 500, 'Viatra (100 nodes)')
18 # random = GraphCollection('../input/randomOutput/', 500, 'Random')
19 # alloy = GraphCollection('../input/alloyOutput/', 500, 'Alloy (30 nodes)')
20
21 models_to_compare = [human, viatra30]
22
23 # define output folder
24 outputFolder = '../output/'
25
26 #calculate metrics
27 metricStat(models_to_compare, 'Node Activity', nodeActivity, 0, outputFolder)
28 metricStat(models_to_compare, 'Out Degree', outDegree, 1, outputFolder)
29 metricStat(models_to_compare, 'MPC', mpc, 2, outputFolder)
30
31def calculateKSMatrix(dists):
32 dist = []
33
34 for i in range(len(dists)):
35 dist = dist + dists[i]
36 matrix = np.empty((len(dist),len(dist)))
37
38 for i in range(len(dist)):
39 matrix[i,i] = 0
40 for j in range(i+1, len(dist)):
41 value, p = stats.ks_2samp(dist[i], dist[j])
42 matrix[i, j] = value
43 matrix[j, i] = value
44 return matrix
45
46
47def calculateMDS(dissimilarities):
48 embedding = MDS(n_components=2, dissimilarity='precomputed')
49 trans = embedding.fit_transform(X=dissimilarities)
50 return trans
51
52def plot(graphTypes, coords, title='',index = 0, savePath = ''):
53 half_length = int(coords.shape[0] / len(graphTypes))
54 color = ['blue', 'red', 'green', 'yellow']
55 plt.figure(index, figsize=(7, 4))
56 plt.title(title)
57 for i in range(len(graphTypes)):
58 x = (coords[(i*half_length):((i+1)*half_length), 0].tolist())
59 y = (coords[(i*half_length):((i+1)*half_length), 1].tolist())
60 plt.plot(x, y, color=color[i], marker='o', label = graphTypes[i].name, linestyle='', alpha=0.7)
61 plt.legend(loc='upper right')
62 plt.savefig(fname = savePath, dpi=150)
63 #graph.show()
64
65def mkdir_p(mypath):
66 '''Creates a directory. equivalent to using mkdir -p on the command line'''
67
68 from errno import EEXIST
69 from os import makedirs,path
70
71 try:
72 makedirs(mypath)
73 except OSError as exc: # Python >2.5
74 if exc.errno == EEXIST and path.isdir(mypath):
75 pass
76 else: raise
77
78def metricStat(graphTypes, metricName, metric, graphIndex, outputFolder):
79 metrics = []
80 for graph in graphTypes:
81 metrics.append(metric(graph))
82 outputFolder = outputFolder + graph.name + '-'
83 print('calculate' + metricName +' for ' + outputFolder)
84 mkdir_p(outputFolder)
85 out_d_coords = calculateMDS(calculateKSMatrix(metrics))
86 plot(graphTypes, out_d_coords, metricName, graphIndex,outputFolder + '/'+ metricName+'.png')
87
88def nodeActivity(graphType):
89 return graphType.nas
90
91def outDegree(graphType):
92 return graphType.out_ds
93
94def mpc(graphType):
95 return graphType.mpcs
96
97if __name__ == '__main__':
98 main() \ No newline at end of file
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/MPC.png
deleted file mode 100644
index d819aad5..00000000
--- a/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/MPC.png
+++ /dev/null
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
deleted file mode 100644
index 4b3b187e..00000000
--- a/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/Node Activity.png
+++ /dev/null
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
deleted file mode 100644
index d8e01f6e..00000000
--- a/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/Out Degree.png
+++ /dev/null
Binary files differ
diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance_with_selector.ipynb b/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance_with_selector.ipynb
index e5868da0..a0b0ad8d 100644
--- a/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance_with_selector.ipynb
+++ b/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance_with_selector.ipynb
@@ -16,7 +16,7 @@
16 }, 16 },
17 { 17 {
18 "cell_type": "code", 18 "cell_type": "code",
19 "execution_count": 2, 19 "execution_count": 1,
20 "metadata": {}, 20 "metadata": {},
21 "outputs": [], 21 "outputs": [],
22 "source": [ 22 "source": [
@@ -48,7 +48,7 @@
48 }, 48 },
49 { 49 {
50 "cell_type": "code", 50 "cell_type": "code",
51 "execution_count": 3, 51 "execution_count": 2,
52 "metadata": {}, 52 "metadata": {},
53 "outputs": [], 53 "outputs": [],
54 "source": [ 54 "source": [
@@ -78,7 +78,7 @@
78 }, 78 },
79 { 79 {
80 "cell_type": "code", 80 "cell_type": "code",
81 "execution_count": 4, 81 "execution_count": 3,
82 "metadata": {}, 82 "metadata": {},
83 "outputs": [], 83 "outputs": [],
84 "source": [ 84 "source": [
@@ -108,7 +108,7 @@
108 }, 108 },
109 { 109 {
110 "cell_type": "code", 110 "cell_type": "code",
111 "execution_count": 5, 111 "execution_count": 4,
112 "metadata": {}, 112 "metadata": {},
113 "outputs": [], 113 "outputs": [],
114 "source": [ 114 "source": [
@@ -139,7 +139,7 @@
139 }, 139 },
140 { 140 {
141 "cell_type": "code", 141 "cell_type": "code",
142 "execution_count": 6, 142 "execution_count": 5,
143 "metadata": {}, 143 "metadata": {},
144 "outputs": [], 144 "outputs": [],
145 "source": [ 145 "source": [
@@ -149,7 +149,7 @@
149 }, 149 },
150 { 150 {
151 "cell_type": "code", 151 "cell_type": "code",
152 "execution_count": 7, 152 "execution_count": 6,
153 "metadata": {}, 153 "metadata": {},
154 "outputs": [], 154 "outputs": [],
155 "source": [ 155 "source": [
@@ -163,7 +163,7 @@
163 }, 163 },
164 { 164 {
165 "cell_type": "code", 165 "cell_type": "code",
166 "execution_count": 8, 166 "execution_count": 7,
167 "metadata": {}, 167 "metadata": {},
168 "outputs": [], 168 "outputs": [],
169 "source": [ 169 "source": [
@@ -200,7 +200,8 @@
200 "# Read generated models\n", 200 "# Read generated models\n",
201 "viatra_no_con_stats = readStats('../statistics/viatra_nocon_output/', 5000)\n", 201 "viatra_no_con_stats = readStats('../statistics/viatra_nocon_output/', 5000)\n",
202 "viatra_con_stats = readStats('../statistics/viatra_con_output/',5000)\n", 202 "viatra_con_stats = readStats('../statistics/viatra_con_output/',5000)\n",
203 "random_stats = readStats('../statistics/random_output/',5000)" 203 "random_stats = readStats('../statistics/random_output/',5000)\n",
204 "con_viatra_stats = readStats('../statistics/controled_viatra/',300)"
204 ] 205 ]
205 }, 206 },
206 { 207 {
@@ -218,7 +219,8 @@
218 "source": [ 219 "source": [
219 "viatra_no_con_dic = calDistanceDic(viatra_no_con_stats, human_rep)\n", 220 "viatra_no_con_dic = calDistanceDic(viatra_no_con_stats, human_rep)\n",
220 "viatra_con_dic = calDistanceDic(viatra_con_stats, human_rep)\n", 221 "viatra_con_dic = calDistanceDic(viatra_con_stats, human_rep)\n",
221 "random_dic = calDistanceDic(random_stats, human_rep)" 222 "random_dic = calDistanceDic(random_stats, human_rep)\n",
223 "con_viatra_dic = calDistanceDic(con_viatra_stats, human_rep)"
222 ] 224 ]
223 }, 225 },
224 { 226 {
@@ -255,7 +257,7 @@
255 { 257 {
256 "data": { 258 "data": {
257 "application/vnd.jupyter.widget-view+json": { 259 "application/vnd.jupyter.widget-view+json": {
258 "model_id": "1bdc31418d894783b36cc79c60251f00", 260 "model_id": "868a437468d24144926f1390cbf2acb8",
259 "version_major": 2, 261 "version_major": 2,
260 "version_minor": 0 262 "version_minor": 0
261 }, 263 },
@@ -291,7 +293,7 @@
291 { 293 {
292 "data": { 294 "data": {
293 "application/vnd.jupyter.widget-view+json": { 295 "application/vnd.jupyter.widget-view+json": {
294 "model_id": "78565a0ec3d740908fcea753387cfc3e", 296 "model_id": "e8b74fe96a45445f8062468ddf2597bf",
295 "version_major": 2, 297 "version_major": 2,
296 "version_minor": 0 298 "version_minor": 0
297 }, 299 },
@@ -327,7 +329,7 @@
327 { 329 {
328 "data": { 330 "data": {
329 "application/vnd.jupyter.widget-view+json": { 331 "application/vnd.jupyter.widget-view+json": {
330 "model_id": "4392eb19fe1844c4affeb62f9ba9163b", 332 "model_id": "c6e7e31f454a48169dac12c8aac70eef",
331 "version_major": 2, 333 "version_major": 2,
332 "version_minor": 0 334 "version_minor": 0
333 }, 335 },
@@ -363,7 +365,7 @@
363 { 365 {
364 "data": { 366 "data": {
365 "application/vnd.jupyter.widget-view+json": { 367 "application/vnd.jupyter.widget-view+json": {
366 "model_id": "c667f0f9dcd5494f81d95c64ad900612", 368 "model_id": "cebc359548f74cc8b7540ecc3876c9ee",
367 "version_major": 2, 369 "version_major": 2,
368 "version_minor": 0 370 "version_minor": 0
369 }, 371 },
@@ -399,7 +401,7 @@
399 { 401 {
400 "data": { 402 "data": {
401 "application/vnd.jupyter.widget-view+json": { 403 "application/vnd.jupyter.widget-view+json": {
402 "model_id": "991d8d2bfc644c82a9b079615900dc4d", 404 "model_id": "682beae42eef4676b11b6fe23127a44e",
403 "version_major": 2, 405 "version_major": 2,
404 "version_minor": 0 406 "version_minor": 0
405 }, 407 },
@@ -435,7 +437,7 @@
435 { 437 {
436 "data": { 438 "data": {
437 "application/vnd.jupyter.widget-view+json": { 439 "application/vnd.jupyter.widget-view+json": {
438 "model_id": "be65f39c2fae4c84a1d6908f3b70a86e", 440 "model_id": "6893b8c6e03441f89fc35bf784992ae9",
439 "version_major": 2, 441 "version_major": 2,
440 "version_minor": 0 442 "version_minor": 0
441 }, 443 },
@@ -471,7 +473,7 @@
471 { 473 {
472 "data": { 474 "data": {
473 "application/vnd.jupyter.widget-view+json": { 475 "application/vnd.jupyter.widget-view+json": {
474 "model_id": "1de0db5b5c8d46de958f6b43144dac54", 476 "model_id": "ff0e1991c69a4d77a40f57225f90295a",
475 "version_major": 2, 477 "version_major": 2,
476 "version_minor": 0 478 "version_minor": 0
477 }, 479 },
@@ -501,13 +503,13 @@
501 }, 503 },
502 { 504 {
503 "cell_type": "code", 505 "cell_type": "code",
504 "execution_count": 20, 506 "execution_count": 19,
505 "metadata": {}, 507 "metadata": {},
506 "outputs": [ 508 "outputs": [
507 { 509 {
508 "data": { 510 "data": {
509 "application/vnd.jupyter.widget-view+json": { 511 "application/vnd.jupyter.widget-view+json": {
510 "model_id": "6f8fa855125b4beca603abbf801412ac", 512 "model_id": "838570f20bed4d8d9c618305984d19ef",
511 "version_major": 2, 513 "version_major": 2,
512 "version_minor": 0 514 "version_minor": 0
513 }, 515 },
@@ -524,7 +526,7 @@
524 "<function __main__.plot_out_degree(lines)>" 526 "<function __main__.plot_out_degree(lines)>"
525 ] 527 ]
526 }, 528 },
527 "execution_count": 20, 529 "execution_count": 19,
528 "metadata": {}, 530 "metadata": {},
529 "output_type": "execute_result" 531 "output_type": "execute_result"
530 } 532 }
@@ -537,13 +539,13 @@
537 }, 539 },
538 { 540 {
539 "cell_type": "code", 541 "cell_type": "code",
540 "execution_count": 23, 542 "execution_count": 20,
541 "metadata": {}, 543 "metadata": {},
542 "outputs": [ 544 "outputs": [
543 { 545 {
544 "data": { 546 "data": {
545 "application/vnd.jupyter.widget-view+json": { 547 "application/vnd.jupyter.widget-view+json": {
546 "model_id": "b4ed2adb29004908a3799bc91bf0662b", 548 "model_id": "f4825f6257a74bce9dd22aac8a98effa",
547 "version_major": 2, 549 "version_major": 2,
548 "version_minor": 0 550 "version_minor": 0
549 }, 551 },
@@ -560,7 +562,7 @@
560 "<function __main__.plot_out_degree(lines)>" 562 "<function __main__.plot_out_degree(lines)>"
561 ] 563 ]
562 }, 564 },
563 "execution_count": 23, 565 "execution_count": 20,
564 "metadata": {}, 566 "metadata": {},
565 "output_type": "execute_result" 567 "output_type": "execute_result"
566 } 568 }
@@ -573,6 +575,164 @@
573 }, 575 },
574 { 576 {
575 "cell_type": "code", 577 "cell_type": "code",
578 "execution_count": 54,
579 "metadata": {},
580 "outputs": [],
581 "source": [
582 "con_viatra_stats = readStats('../statistics/controled_viatra/',5000)\n",
583 "con_viatra_dic = calDistanceDic(con_viatra_stats, human_rep)"
584 ]
585 },
586 {
587 "cell_type": "markdown",
588 "metadata": {},
589 "source": [
590 "## Trajectories for controlled viatra solver"
591 ]
592 },
593 {
594 "cell_type": "code",
595 "execution_count": 56,
596 "metadata": {},
597 "outputs": [],
598 "source": [
599 "filenames = reader.readmultiplefiles('../statistics/controled_viatra/trajectories/', 25, False)\n",
600 "trajectories = {}\n",
601 "for name in filenames:\n",
602 " trajectories[name] = reader.readTrajectory(name)\n",
603 "\n",
604 "w = widgets.SelectMultiple(\n",
605 " options = trajectories,\n",
606 " value = [trajectories[filenames[0]]],\n",
607 " description='Trajectory:',\n",
608 " disabled=False,\n",
609 ")"
610 ]
611 },
612 {
613 "cell_type": "code",
614 "execution_count": 57,
615 "metadata": {},
616 "outputs": [
617 {
618 "data": {
619 "application/vnd.jupyter.widget-view+json": {
620 "model_id": "4b60ae3859e343299badf29272f67d21",
621 "version_major": 2,
622 "version_minor": 0
623 },
624 "text/plain": [
625 "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/controled_…"
626 ]
627 },
628 "metadata": {},
629 "output_type": "display_data"
630 },
631 {
632 "data": {
633 "text/plain": [
634 "<function __main__.plot_out_degree(lines)>"
635 ]
636 },
637 "execution_count": 57,
638 "metadata": {},
639 "output_type": "execute_result"
640 }
641 ],
642 "source": [
643 "def plot_out_degree(lines):\n",
644 " plot(con_viatra_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out_degree')\n",
645 "interact(plot_out_degree, lines=w)"
646 ]
647 },
648 {
649 "cell_type": "code",
650 "execution_count": 58,
651 "metadata": {},
652 "outputs": [
653 {
654 "data": {
655 "application/vnd.jupyter.widget-view+json": {
656 "model_id": "8e7965d793a146d4bbc268554262eb58",
657 "version_major": 2,
658 "version_minor": 0
659 },
660 "text/plain": [
661 "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/controled_…"
662 ]
663 },
664 "metadata": {},
665 "output_type": "display_data"
666 },
667 {
668 "data": {
669 "text/plain": [
670 "<function __main__.plot_na(lines)>"
671 ]
672 },
673 "execution_count": 58,
674 "metadata": {},
675 "output_type": "execute_result"
676 }
677 ],
678 "source": [
679 "def plot_na(lines):\n",
680 " plot(con_viatra_dic, lines, 0, lambda a: a.na_distance, colors, 'Node Activity')\n",
681 "interact(plot_na, lines=w)"
682 ]
683 },
684 {
685 "cell_type": "code",
686 "execution_count": 59,
687 "metadata": {},
688 "outputs": [
689 {
690 "data": {
691 "application/vnd.jupyter.widget-view+json": {
692 "model_id": "55a1209d0b924a39b4729228e81ee3ab",
693 "version_major": 2,
694 "version_minor": 0
695 },
696 "text/plain": [
697 "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/controled_…"
698 ]
699 },
700 "metadata": {},
701 "output_type": "display_data"
702 },
703 {
704 "data": {
705 "text/plain": [
706 "<function __main__.plot_mpc(lines)>"
707 ]
708 },
709 "execution_count": 59,
710 "metadata": {},
711 "output_type": "execute_result"
712 }
713 ],
714 "source": [
715 "def plot_mpc(lines):\n",
716 " plot(con_viatra_dic, lines, 0, lambda a: a.mpc_distance, colors, 'mpc')\n",
717 "interact(plot_mpc, lines=w)"
718 ]
719 },
720 {
721 "cell_type": "code",
722 "execution_count": null,
723 "metadata": {},
724 "outputs": [],
725 "source": []
726 },
727 {
728 "cell_type": "code",
729 "execution_count": null,
730 "metadata": {},
731 "outputs": [],
732 "source": []
733 },
734 {
735 "cell_type": "code",
576 "execution_count": null, 736 "execution_count": null,
577 "metadata": {}, 737 "metadata": {},
578 "outputs": [], 738 "outputs": [],
diff --git a/Metrics/Metrics-Calculation/metrics_plot/utils/GraphType.py b/Metrics/Metrics-Calculation/metrics_plot/utils/GraphType.py
new file mode 100644
index 00000000..13754e80
--- /dev/null
+++ b/Metrics/Metrics-Calculation/metrics_plot/utils/GraphType.py
@@ -0,0 +1,29 @@
1import readCSV as reader
2import constants
3import numpy as np
4
5# graph stats for a collection of graphs
6class 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 print(len(self.out_ds))
21
22#Graph stat for one graph
23class GraphStat:
24 # init with teh file name of the stat
25 def __init__(self, filename):
26 contents, self.out_d, self.na, self.mpc = reader.getmetrics(filename)
27 self.num_nodes = np.array(contents[constants.NUMBER_NODES])
28 if constants.STATE_ID in contents:
29 self.id = (contents[constants.STATE_ID])[0]
diff --git a/Metrics/Metrics-Calculation/metrics_plot/utils/constants.py b/Metrics/Metrics-Calculation/metrics_plot/utils/constants.py
new file mode 100644
index 00000000..58ca7549
--- /dev/null
+++ b/Metrics/Metrics-Calculation/metrics_plot/utils/constants.py
@@ -0,0 +1,25 @@
1NUMBER_EDGE_TYPES = 'Number of Edge types'
2
3NUMBER_NODES = 'Number Of Nodes'
4
5OUT_DEGREE_COUNT = 'OutDegreeCount'
6
7OUT_DEGREE_VALUE = 'OutDegreeValue'
8
9NA_COUNT = 'NACount'
10
11NA_VALUE = 'NAValue'
12
13MPC_VALUE = 'MPCValue'
14
15MPC_COUNT = 'MPCCount'
16
17METAMODEL = 'Meta Mode'
18
19STATE_ID = 'State Id'
20
21HUMAN_OUT_D_REP = '../statistics/humanOutput\R_20158_run_1.csv'
22
23HUMAN_MPC_REP = '../statistics/humanOutput\R_2015246_run_1.csv'
24
25HUMAN_NA_REP = '../statistics/humanOutput\R_2016176_run_1.csv'
diff --git a/Metrics/Metrics-Calculation/metrics_plot/utils/readCSV.py b/Metrics/Metrics-Calculation/metrics_plot/utils/readCSV.py
new file mode 100644
index 00000000..e0402519
--- /dev/null
+++ b/Metrics/Metrics-Calculation/metrics_plot/utils/readCSV.py
@@ -0,0 +1,169 @@
1import numpy as np
2import matplotlib.pyplot as plt
3from scipy import stats
4import glob
5import random
6import 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#
12def 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
33def checkAndReshape(arr):
34 if len(arr.shape) < 2:
35 arr = np.reshape(arr, (arr.shape[0],1))
36 return arr
37
38def 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#
49def 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
58def 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#
66def 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#
76def readmultiplefiles(dirName, maxNumberOfFiles, 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[:maxNumberOfFiles]
82 # print(file_names)
83 return file_names
84
85
86def plotlines(x, y, ax):
87 l1, = ax.plot(x, y)
88
89
90def testgetsamplesfromfiles():
91 files = readmultiplefiles('../statistics/viatraOutput/', 2)
92 for file in files:
93 getmetrics(file)
94
95def 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
105def cumulativeProbability(p):
106 cdf = np.cumsum(p)
107 return cdf
108
109
110def 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