From bb6bb8c279e0db324efa11b28eb5d77d175aa8a9 Mon Sep 17 00:00:00 2001 From: 20001LastOrder Date: Wed, 5 Jun 2019 14:26:39 -0400 Subject: clean up metric directory --- .../output/Human-Viatra (30 nodes)-/MPC.png | Bin 99670 -> 0 bytes .../Human-Viatra (30 nodes)-/Node Activity.png | Bin 85981 -> 0 bytes .../output/Human-Viatra (30 nodes)-/Out Degree.png | Bin 78151 -> 0 bytes .../MPC.png | Bin 0 -> 29675 bytes .../Node Activity.png | Bin 0 -> 32871 bytes .../Out Degree.png | Bin 0 -> 87131 bytes .../output/Human-Viatra (30 nodes)-Random-/MPC.png | Bin 0 -> 127107 bytes .../Node Activity.png | Bin 0 -> 118735 bytes .../Human-Viatra (30 nodes)-Random-/Out Degree.png | Bin 0 -> 116864 bytes .../MPC.png | Bin 0 -> 85397 bytes .../Node Activity.png | Bin 0 -> 87774 bytes .../Out Degree.png | Bin 0 -> 95122 bytes .../MPC.png | Bin 0 -> 171018 bytes .../Node Activity.png | Bin 0 -> 114184 bytes .../Out Degree.png | Bin 0 -> 139638 bytes .../output/real vs viatra vs alloy/MPC.png | Bin 0 -> 97403 bytes .../real vs viatra vs alloy/Node Activity.png | Bin 0 -> 88084 bytes .../output/real vs viatra vs alloy/Out Degree.png | Bin 0 -> 87391 bytes .../model_evolve_comparison/input/.gitignore | 3 + .../controled_viatra_with_mpc/Node Activity.jpg | Bin 0 -> 491184 bytes .../output/controled_viatra_with_mpc/mpc.jpg | Bin 0 -> 478870 bytes .../controled_viatra_with_mpc/out_degree.jpg | Bin 0 -> 403591 bytes .../output/random_emf/mpc.jpg | Bin 0 -> 393999 bytes .../output/random_emf/node activity.jpg | Bin 0 -> 373785 bytes .../output/random_emf/out degree.jpg | Bin 0 -> 271040 bytes .../random_emf_instantiator/Node Activity.jpg | Bin 0 -> 209185 bytes .../output/random_emf_instantiator/mpc.jpg | Bin 0 -> 159590 bytes .../output/random_emf_instantiator/out_degree.jpg | Bin 0 -> 200160 bytes .../output/viatra_constraints/MPC.jpg | Bin 0 -> 513832 bytes .../output/viatra_constraints/node activity.jpg | Bin 0 -> 513922 bytes .../output/viatra_constraints/out degree.jpg | Bin 0 -> 506046 bytes .../output/viatra_no_constraints/MPC.jpg | Bin 0 -> 581498 bytes .../output/viatra_no_constraints/node activity.jpg | Bin 0 -> 566190 bytes .../output/viatra_no_constraints/out degree.jpg | Bin 0 -> 534577 bytes .../src/metrics_distance.ipynb | 481 +++++++++++ .../src/metrics_distance_with_selector.ipynb | 955 +++++++++++++++++++++ .../src/representative_selector .ipynb | 336 ++++++++ .../MPC.png | Bin 29675 -> 0 bytes .../Node Activity.png | Bin 32871 -> 0 bytes .../Out Degree.png | Bin 87131 -> 0 bytes .../output/Human-Viatra (30 nodes)-Random-/MPC.png | Bin 127107 -> 0 bytes .../Node Activity.png | Bin 118735 -> 0 bytes .../Human-Viatra (30 nodes)-Random-/Out Degree.png | Bin 116864 -> 0 bytes .../MPC.png | Bin 85397 -> 0 bytes .../Node Activity.png | Bin 87774 -> 0 bytes .../Out Degree.png | Bin 95122 -> 0 bytes .../MPC.png | Bin 171018 -> 0 bytes .../Node Activity.png | Bin 114184 -> 0 bytes .../Out Degree.png | Bin 139638 -> 0 bytes .../output/real vs viatra vs alloy/MPC.png | Bin 97403 -> 0 bytes .../real vs viatra vs alloy/Node Activity.png | Bin 88084 -> 0 bytes .../output/real vs viatra vs alloy/Out Degree.png | Bin 87391 -> 0 bytes .../metrics_plot/src/GraphType.py | 28 - .../metrics_plot/src/average_ks_plot.py | 62 -- .../metrics_plot/src/constants.py | 25 - .../metrics_plot/src/metrics_distance.ipynb | 481 ----------- .../src/metrics_distance_with_selector.ipynb | 763 ---------------- .../metrics_plot/src/plot_ks_stats.py | 90 -- .../metrics_plot/src/readCSV.py | 169 ---- .../src/representative_selector .ipynb | 262 ------ .../Metrics-Calculation/metrics_plot/src/test.py | 32 - .../metrics_plot/statistics/.gitignore | 3 - .../metrics_plot/utils/constants.py | 6 +- 63 files changed, 1778 insertions(+), 1918 deletions(-) delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/MPC.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Node Activity.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Out Degree.png create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/MPC.png create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Node Activity.png create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Out Degree.png create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/MPC.png create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/Node Activity.png create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/Out Degree.png create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/MPC.png create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Node Activity.png create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Out Degree.png create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/MPC.png create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Node Activity.png create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Out Degree.png create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/MPC.png create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/Node Activity.png create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/Out Degree.png create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/input/.gitignore create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/controled_viatra_with_mpc/Node Activity.jpg create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/controled_viatra_with_mpc/mpc.jpg create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/controled_viatra_with_mpc/out_degree.jpg create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf/mpc.jpg create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf/node activity.jpg create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf/out degree.jpg create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf_instantiator/Node Activity.jpg create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf_instantiator/mpc.jpg create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf_instantiator/out_degree.jpg create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_constraints/MPC.jpg create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_constraints/node activity.jpg create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_constraints/out degree.jpg create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_no_constraints/MPC.jpg create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_no_constraints/node activity.jpg create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_no_constraints/out degree.jpg create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/metrics_distance.ipynb create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/metrics_distance_with_selector.ipynb create mode 100644 Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/representative_selector .ipynb delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/MPC.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Node Activity.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Out Degree.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/MPC.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/Node Activity.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/Out Degree.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/MPC.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Node Activity.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Out Degree.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/MPC.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Node Activity.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Out Degree.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/MPC.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/Node Activity.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/Out Degree.png delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/src/GraphType.py delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/src/average_ks_plot.py delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/src/constants.py delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance.ipynb delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance_with_selector.ipynb delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/src/plot_ks_stats.py delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/src/readCSV.py delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/src/representative_selector .ipynb delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/src/test.py delete mode 100644 Metrics/Metrics-Calculation/metrics_plot/statistics/.gitignore (limited to 'Metrics/Metrics-Calculation') 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 deleted file mode 100644 index e660f3da..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/MPC.png and /dev/null 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 deleted file mode 100644 index 92047e47..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Node Activity.png and /dev/null 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 deleted file mode 100644 index dad7483f..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Out Degree.png and /dev/null differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/MPC.png new file mode 100644 index 00000000..cd2af5ce Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/MPC.png differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Node Activity.png new file mode 100644 index 00000000..2ce3672b Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Node Activity.png differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Out Degree.png new file mode 100644 index 00000000..d4d9afe1 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Out Degree.png differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/MPC.png new file mode 100644 index 00000000..8d76fed9 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/MPC.png differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/Node Activity.png new file mode 100644 index 00000000..daa7929a Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/Node Activity.png differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/Out Degree.png new file mode 100644 index 00000000..e56b1b6e Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/Out Degree.png differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/MPC.png new file mode 100644 index 00000000..8705cee2 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/MPC.png differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Node Activity.png new file mode 100644 index 00000000..bdab3741 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Node Activity.png differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Out Degree.png new file mode 100644 index 00000000..e4269f6e Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Out Degree.png differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/MPC.png new file mode 100644 index 00000000..e4b6b527 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/MPC.png differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Node Activity.png new file mode 100644 index 00000000..e067ad66 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Node Activity.png differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Out Degree.png new file mode 100644 index 00000000..9b89e4f9 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Out Degree.png differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/MPC.png new file mode 100644 index 00000000..4f189578 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/MPC.png differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/Node Activity.png new file mode 100644 index 00000000..add3c0f8 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/Node Activity.png differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/Out Degree.png new file mode 100644 index 00000000..f4717a1a Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/Out Degree.png differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/input/.gitignore b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/input/.gitignore new file mode 100644 index 00000000..b3934b01 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/input/.gitignore @@ -0,0 +1,3 @@ +# ignore everything in this folder +* +!.gitignore \ No newline at end of file diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/controled_viatra_with_mpc/Node Activity.jpg b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/controled_viatra_with_mpc/Node Activity.jpg new file mode 100644 index 00000000..d2dbd970 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/controled_viatra_with_mpc/Node Activity.jpg differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/controled_viatra_with_mpc/mpc.jpg b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/controled_viatra_with_mpc/mpc.jpg new file mode 100644 index 00000000..3ca2e0bc Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/controled_viatra_with_mpc/mpc.jpg differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/controled_viatra_with_mpc/out_degree.jpg b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/controled_viatra_with_mpc/out_degree.jpg new file mode 100644 index 00000000..5b623374 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/controled_viatra_with_mpc/out_degree.jpg differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf/mpc.jpg b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf/mpc.jpg new file mode 100644 index 00000000..7a744ea6 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf/mpc.jpg differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf/node activity.jpg b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf/node activity.jpg new file mode 100644 index 00000000..dfcc973e Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf/node activity.jpg differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf/out degree.jpg b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf/out degree.jpg new file mode 100644 index 00000000..b3f4f912 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf/out degree.jpg differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf_instantiator/Node Activity.jpg b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf_instantiator/Node Activity.jpg new file mode 100644 index 00000000..f0d09211 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf_instantiator/Node Activity.jpg differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf_instantiator/mpc.jpg b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf_instantiator/mpc.jpg new file mode 100644 index 00000000..94b070d4 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf_instantiator/mpc.jpg differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf_instantiator/out_degree.jpg b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf_instantiator/out_degree.jpg new file mode 100644 index 00000000..8d0151fa Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf_instantiator/out_degree.jpg differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_constraints/MPC.jpg b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_constraints/MPC.jpg new file mode 100644 index 00000000..b10d97e6 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_constraints/MPC.jpg differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_constraints/node activity.jpg b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_constraints/node activity.jpg new file mode 100644 index 00000000..e41c998b Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_constraints/node activity.jpg differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_constraints/out degree.jpg b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_constraints/out degree.jpg new file mode 100644 index 00000000..d2776bc8 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_constraints/out degree.jpg differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_no_constraints/MPC.jpg b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_no_constraints/MPC.jpg new file mode 100644 index 00000000..19feb5e8 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_no_constraints/MPC.jpg differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_no_constraints/node activity.jpg b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_no_constraints/node activity.jpg new file mode 100644 index 00000000..bc7a83fc Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_no_constraints/node activity.jpg differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_no_constraints/out degree.jpg b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_no_constraints/out degree.jpg new file mode 100644 index 00000000..13094840 Binary files /dev/null and b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_no_constraints/out degree.jpg differ 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 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Compare Metrics Distances to The Human Models" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [], + "source": [ + "from GraphType import GraphStat\n", + "from GraphType import GraphCollection\n", + "from scipy import stats\n", + "from ipywidgets import interact, fixed, interactive\n", + "import readCSV as reader\n", + "import ipywidgets as widgets\n", + "import matplotlib.pyplot as plt\n", + "import random\n", + "import numpy as np\n", + "import constants\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Classes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Record the average distances of different metrics for a model to the human models " + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [], + "source": [ + "class GraphDistance:\n", + " #init with a graph stat and a collection of graph stats\n", + " def __init__(self, graphStat, collection):\n", + " self.graph = graphStat\n", + " self.collection = collection\n", + " self.out_d_distance = average_ks_distance(collection.out_ds, graphStat.out_d)\n", + " self.na_distance = average_ks_distance(collection.nas, graphStat.na)\n", + " self.mpc_distance = average_ks_distance(collection.mpcs, graphStat.mpc)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Methods" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Calculate the average ks distance" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [], + "source": [ + "def average_ks_distance(targets, sample):\n", + " distance = 0.0\n", + " for target in targets:\n", + " value, p = stats.ks_2samp(target, sample)\n", + " distance += value\n", + " distance = distance / len(targets)\n", + " return distance\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, + "source": [ + "* Find the median ks distance of the same number of nodes" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, + "outputs": [], + "source": [ + "def find_median(x, metric_distances):\n", + " distance_dic = {}\n", + " for index, num_of_nodes in enumerate(x):\n", + " if num_of_nodes[0] not in distance_dic:\n", + " distance_dic[num_of_nodes[0]] = []\n", + " distance_dic[num_of_nodes[0]].append(metric_distances[index])\n", + " median_x = []\n", + " y = []\n", + " for num_of_nodes, distances in distance_dic.items():\n", + " median_x.append(num_of_nodes)\n", + " y.append(np.median(distances))\n", + " order = np.argsort(median_x)\n", + " median_x = np.array(median_x)[order]\n", + " median_y = np.array(y)[order]\n", + " return median_x, median_y\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Plot Diagram" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [], + "source": [ + "# metric_selector: GraphDistance -> float\n", + "def plot(infos, lines, id, metric_selector,colors, title):\n", + " metric_distances = retrive_info_from_list(metric_selector, list(infos.values()))\n", + " x = retrive_info_from_list(lambda a : a.graph.num_nodes, list(infos.values()))\n", + " graph = plt.figure(id,figsize=(18, 10))\n", + " plt.title(title)\n", + " plt.plot(x, metric_distances, color='red', linestyle='', marker='o',alpha=0.7)\n", + " #plot ks distance median\n", + " median_x, median_y = find_median(x, metric_distances)\n", + " plt.plot(median_x, median_y, color='black',marker='o')\n", + " for i in range(0, len(lines)):\n", + " line_infos = retrive_info_from_list(lambda a: infos[a], lines[i])\n", + " line_y = retrive_info_from_list(metric_selector, line_infos)\n", + " line_x = retrive_info_from_list(lambda a : a.graph.num_nodes, line_infos)\n", + " plt.plot(line_x, line_y, marker='o', color=colors[i])\n", + " #graph.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Retrieve information from a list " + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [], + "source": [ + "def retrive_info_from_list(selector, distances):\n", + " return list(map(selector, distances))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Read Models" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [], + "source": [ + "human = GraphCollection('../statistics/humanOutput/', 300, 'Human', True)\n", + "file_names = reader.readmultiplefiles('../statistics/viatraEvolve/', 1000, False)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Calculate Distances" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [], + "source": [ + "# Progress Widge\n", + "w2 = widgets.FloatProgress(\n", + " value=0,\n", + " min=0,\n", + " max=1.0,\n", + " step=0.1,\n", + " description='Loading Files...:',\n", + " bar_style='info',\n", + " orientation='horizontal'\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "ca7932bce2a741afaff6b919042c42b0", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "FloatProgress(value=0.0, bar_style='info', description='Loading Files...:', max=1.0)" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "infos = []\n", + "# read all files\n", + "counter = 0.0\n", + "size = len(file_names)\n", + "#display progress bar\n", + "display(w2)\n", + "for name in file_names:\n", + " infos.append(GraphStat(name))\n", + "\n", + "info_dic = {}\n", + "for info in infos:\n", + " w2.value = (counter/size)\n", + " counter+=1\n", + " info = GraphDistance(info, human)\n", + " info_dic[info.graph.id] = info" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Plot Graphs" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* widget for select trajectory" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [], + "source": [ + "filenames = reader.readmultiplefiles('../statistics/trajectories/', 10, False)\n", + "trajectories = {}\n", + "for name in filenames:\n", + " trajectories[name] = reader.readTrajectory(name)\n", + "\n", + "w = widgets.SelectMultiple(\n", + " options = trajectories,\n", + " value = [trajectories[filenames[0]]],\n", + " description='Trajectory:',\n", + " disabled=False,\n", + ")\n", + "\n", + "#generate random color for each line\n", + "colors = []\n", + "\n", + "for i in range(0, len(trajectories)):\n", + " color = \"#%06x\" % random.randint(0, 0xFFFFFF)\n", + " colors.append(color)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Out Degree" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "08da62cb0c3f4e6e9591c7dc811d27cc", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(SelectMultiple(description='Trajectory:', index=(1,), options={'../statistics/trajectori…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_out_degree(lines):\n", + " plot(info_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree')\n", + "interact(plot_out_degree, lines=w)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Node Activity" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "a708f43645a24bd2b15b53ea12c7d88f", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(SelectMultiple(description='Trajectory:', index=(1,), options={'../statistics/trajectori…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_na(lines):\n", + " plot(info_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity')\n", + "interact(plot_na, lines=w)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### MPC" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "124a0cb0ebfb4225bf4ced24c09032f7", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(SelectMultiple(description='Trajectory:', index=(1,), options={'../statistics/trajectori…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_out_degree(lines):\n", + " plot(info_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC')\n", + "interact(plot_out_degree, lines=w)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "for name in file_names:\n", + " contents = reader.readcsvfile(name)\n", + " if(contents['State Id'][0] == 1032396643):\n", + " print(name)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + }, + "pycharm": { + "stem_cell": { + "cell_type": "raw", + "metadata": { + "collapsed": false + }, + "source": [] + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} 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 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Measuremments with Representative" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import os, sys\n", + "lib_path = os.path.abspath(os.path.join('..', '..', 'utils'))\n", + "sys.path.append(lib_path)\n", + "from GraphType import GraphStat\n", + "from GraphType import GraphCollection\n", + "from scipy import stats\n", + "from ipywidgets import interact, fixed, interactive\n", + "import readCSV as reader\n", + "import ipywidgets as widgets\n", + "import matplotlib.pyplot as plt\n", + "import random\n", + "import numpy as np\n", + "import constants\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Classes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Record the distances of different metrics using a representative" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "class GraphDistanceWithRep:\n", + " #init with a graph stat and a collection of graph stats\n", + " def __init__(self, graphStat, rep):\n", + " self.graph = graphStat\n", + " self.rep = rep\n", + " self.out_d_distance, _ = stats.ks_2samp(graphStat.out_d, rep.out_d)\n", + " self.na_distance,_ = stats.ks_2samp(graphStat.na, rep.na)\n", + " self.mpc_distance,_ = stats.ks_2samp(graphStat.mpc, rep.mpc)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Methods\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Find the median ks distance of the same number of nodes" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "def find_median(x, metric_distances):\n", + " distance_dic = {}\n", + " for index, num_of_nodes in enumerate(x):\n", + " if num_of_nodes[0] not in distance_dic:\n", + " distance_dic[num_of_nodes[0]] = []\n", + " distance_dic[num_of_nodes[0]].append(metric_distances[index])\n", + " median_x = []\n", + " y = []\n", + " for num_of_nodes, distances in distance_dic.items():\n", + " median_x.append(num_of_nodes)\n", + " y.append(np.median(distances))\n", + " order = np.argsort(median_x)\n", + " median_x = np.array(median_x)[order]\n", + " median_y = np.array(y)[order]\n", + " return median_x, median_y\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Plot Diagram" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [], + "source": [ + "# metric_selector: GraphDistance -> float\n", + "def plot(infos, lines, id, metric_selector,colors, title, foldername):\n", + " metric_distances = retrive_info_from_list(metric_selector, list(infos.values()))\n", + " x = retrive_info_from_list(lambda a : a.graph.num_nodes, list(infos.values()))\n", + " graph = plt.figure(id,figsize=(18, 10))\n", + " plt.title(title)\n", + " plt.plot(x, metric_distances, color='red', linestyle='', marker='o',alpha=0.7)\n", + " #plot ks distance median\n", + " median_x, median_y = find_median(x, metric_distances)\n", + " plt.plot(median_x, median_y, color='black',marker='o')\n", + " for i in range(0, len(lines)):\n", + " line_infos = retrive_info_from_list(lambda a: infos[a], lines[i])\n", + " line_y = retrive_info_from_list(metric_selector, line_infos)\n", + " line_x = retrive_info_from_list(lambda a : a.graph.num_nodes, line_infos)\n", + " plt.plot(line_x, line_y, marker='o', color=colors[i])\n", + " mkdir_p(foldername)\n", + " plt.savefig(fname = foldername+title+'.jpg', dpi=150)\n", + " #graph.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Retrieve information from a list " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "def retrive_info_from_list(selector, distances):\n", + " return list(map(selector, distances))" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "def readStats(path, numModels):\n", + " names = reader.readmultiplefiles(path, numModels, False)\n", + " stats = []\n", + " for name in names:\n", + " stats.append(GraphStat(name))\n", + " return stats" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "def calDistanceDic(stats, rep):\n", + " dic = {}\n", + " for info in stats:\n", + " info = GraphDistanceWithRep(info, rep)\n", + " dic[info.graph.id] = info\n", + " return dic" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "def createRandomColors(size):\n", + " #generate random color for each line\n", + " colors = []\n", + "\n", + " for i in range(0, size):\n", + " color = \"#%06x\" % random.randint(0, 0xFFFFFF)\n", + " colors.append(color)\n", + " return colors" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [], + "source": [ + "def createSelectionWidge(options):\n", + " w = widgets.SelectMultiple(\n", + " options = options,\n", + " value = [],\n", + " description='Trajectory:',\n", + " disabled=False,\n", + " )\n", + " return w" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [], + "source": [ + "def mkdir_p(mypath):\n", + " '''Creates a directory. equivalent to using mkdir -p on the command line'''\n", + "\n", + " from errno import EEXIST\n", + " from os import makedirs,path\n", + "\n", + " try:\n", + " makedirs(mypath)\n", + " except OSError as exc: # Python >2.5\n", + " if exc.errno == EEXIST and path.isdir(mypath):\n", + " pass\n", + " else: raise" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Metrics During GenerationPlots" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Read Human Representatives" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [], + "source": [ + "### Read Models\n", + "#read representative\n", + "human_rep = GraphStat(constants.HUMAN_OUT_D_REP)\n", + "human_na = GraphStat(constants.HUMAN_NA_REP)\n", + "human_mpc = GraphStat(constants.HUMAN_MPC_REP)\n", + "\n", + "# assign rep distributions to human_rep\n", + "human_rep.na = human_na.na\n", + "human_rep.mpc = human_mpc.mpc" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Viatra No Constraint" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "# Read generated models\n", + "viatra_no_con_stats = readStats('../input/viatra_nocon_output/', 5000)\n", + "viatra_no_con_dic = calDistanceDic(viatra_no_con_stats, human_rep)" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [], + "source": [ + "filenames = reader.readmultiplefiles('../input/viatra_nocon_output/trajectories/', 15, False)\n", + "trajectories = {}\n", + "for name in filenames:\n", + " trajectories[name] = reader.readTrajectory(name)\n", + "w = createSelectionWidge(trajectories)\n", + "colors = createRandomColors(len(trajectories))" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "9519be563fbc41c28921c77ef6481b17", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_out_degree(lines):\n", + " plot(viatra_no_con_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree', '../output/viatra_no_constraints/')\n", + "interact(plot_out_degree, lines=w)" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "c896725e542c4bf8a1bc76ba66819b20", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 78, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_out_na(lines):\n", + " plot(viatra_no_con_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity', '../output/viatra_no_constraints/')\n", + "interact(plot_out_na, lines=w)" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "880410d675624545ab73977a463bb5c9", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 79, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_out_mpc(lines):\n", + " plot(viatra_no_con_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC', '../output/viatra_no_constraints/')\n", + "interact(plot_out_mpc, lines=w)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Viatra with constraints" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [], + "source": [ + "viatra_con_stats = readStats('../input/viatra_con_output/',5000)\n", + "viatra_con_dic = calDistanceDic(viatra_con_stats, human_rep)\n", + "\n", + "# trajectories and colors\n", + "trajectories = {}\n", + "w = createSelectionWidge(trajectories)\n", + "colors = createRandomColors(len(trajectories))" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "0d04d6db770a49f4a160ff55cc7131f6", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_out_degree(lines):\n", + " plot(viatra_con_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree', '../output/viatra_constraints/')\n", + "interact(plot_out_degree, lines=[[]])" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "96eebad1f6274d79ad377c8c54b44615", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_na(lines):\n", + " plot(viatra_con_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity', '../output/viatra_constraints/')\n", + "interact(plot_na, lines=[[]])" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "4fc2714a3cd3440daf5014bb4b942b9a", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_mpc(lines):\n", + " plot(viatra_con_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC', '../output/viatra_constraints/')\n", + "interact(plot_mpc, lines=[[]])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Controlled RandomEMF" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [], + "source": [ + "random_emf_stats = readStats('../input/random_emf_output/',5000)\n", + "random_emf_dic = calDistanceDic(random_emf_stats, human_rep)\n", + "\n", + "# trajectories and colors\n", + "trajectories = {}\n", + "w = createSelectionWidge(trajectories)\n", + "colors = createRandomColors(len(trajectories))" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "4401931533b5497f864f146d7b4dcd3c", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_out_degree(lines):\n", + " plot(random_emf_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree', '../output/random_emf/')\n", + "interact(plot_out_degree, lines=[[]])" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "fb7bdedff841420bb8f817013f565020", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_node_activity(lines):\n", + " plot(random_emf_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity', '../output/random_emf/')\n", + "interact(plot_node_activity, lines=[[]])" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "6b0c349c4a3b4813825513f739ea30da", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_mpc(lines):\n", + " plot(random_emf_dic, lines, 0, lambda a: a.mpc_distance, colors, 'mpc', '../output/random_emf/')\n", + "interact(plot_mpc, lines=[[]])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Controlled Viatra with MPC" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": {}, + "outputs": [], + "source": [ + "con_viatra_stats = readStats('../input/controled_viatra_mpc/',5000)\n", + "con_viatra_dic = calDistanceDic(con_viatra_stats, human_rep)\n", + "\n", + "# trajectories and colors\n", + "trajectories = {}\n", + "w = createSelectionWidge(trajectories)\n", + "colors = createRandomColors(len(trajectories))" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "b76901ba9d44433984032e0dc5679fa9", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_out_degree(lines):\n", + " plot(con_viatra_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out_degree', '../output/controled_viatra_with_mpc/')\n", + "interact(plot_out_degree, lines=w)" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "9e0d61e29b02467cb52618860a1bde7f", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_na(lines):\n", + " plot(con_viatra_dic, lines, 0, lambda a: a.na_distance, colors, 'Node Activity', '../output/controled_viatra_with_mpc/')\n", + "interact(plot_na, lines=w)" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "70074805fee44a1aa5b9ccb3770b5c0c", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_mpc(lines):\n", + " plot(con_viatra_dic, lines, 0, lambda a: a.mpc_distance, colors, 'mpc', '../output/controled_viatra_with_mpc/')\n", + "interact(plot_mpc, lines=w)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## (Pseudo) Random EMF instantiator" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": {}, + "outputs": [], + "source": [ + "random_emf_stats = readStats('../input/real_random_output/',5000)\n", + "random_emf_dic = calDistanceDic(random_emf_stats, human_rep)\n", + "\n", + "# trajectories and colors\n", + "trajectories = {}\n", + "w = createSelectionWidge(trajectories)\n", + "colors = createRandomColors(len(trajectories))" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "912ba2fdfd7c46848065f174aa6177e0", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_out_degree(lines):\n", + " plot(random_emf_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out_degree', '../output/random_emf_instantiator/')\n", + "interact(plot_out_degree, lines=w)" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "0ba621dd0e7d4957aaff2cf209bba165", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_na(lines):\n", + " plot(random_emf_dic, lines, 0, lambda a: a.na_distance, colors, 'Node Activity', '../output/random_emf_instantiator/')\n", + "interact(plot_na, lines=w)" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "d432bbae1c6f48c3acd1767f2e2b13c7", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def plot_mpc(lines):\n", + " plot(random_emf_dic, lines, 0, lambda a: a.mpc_distance, colors, 'mpc', '../output/random_emf_instantiator/')\n", + "interact(plot_mpc, lines=w)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} 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 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Use K-medoid algorithm to find the suitable human model representitives" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import os, sys\n", + "lib_path = os.path.abspath(os.path.join('..', '..', 'utils'))\n", + "sys.path.append(lib_path)\n", + "from GraphType import GraphStat\n", + "import readCSV as reader\n", + "from scipy import stats\n", + "from ipywidgets import interact, fixed, interactive\n", + "import ipywidgets as widgets\n", + "from pyclustering.cluster.kmedoids import kmedoids\n", + "from pyclustering.utils.metric import distance_metric, type_metric\n", + "import random" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Define a new distance metric" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "def ks_value(dest1, dest2):\n", + " value, p = stats.ks_2samp(dest1, dest2)\n", + " return value\n", + "\n", + "\n", + "ks_metric = distance_metric(type_metric.USER_DEFINED, func=ks_value)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Read Human Models" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1253" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Progress Widge\n", + "w = widgets.FloatProgress(\n", + " value=0,\n", + " min=0,\n", + " max=1.0,\n", + " step=0.1,\n", + " description='Loading Files...:',\n", + " bar_style='info',\n", + " orientation='horizontal'\n", + ")\n", + "\n", + "\n", + "humanFiles = reader.readmultiplefiles('../input/humanOutput/', 1300, False)\n", + "modelToFileName = {}\n", + "for name in humanFiles:\n", + " modelToFileName[GraphStat(name)] = name\n", + "\n", + "models = list(modelToFileName.keys())\n", + "len(humanFiles)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Find Representative by K-medroid for different dists on GraphStat" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Returns the index of the representative" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "def findRep(graphStats, func):\n", + " out_ds = list(map(func, models))\n", + "\n", + " #choose a random starting point\n", + " start_index = random.randint(0, len(out_ds))\n", + "\n", + " # start with one initial metrid [start_index]\n", + " outdegree_kmedoid = kmedoids(out_ds, [start_index], metric=ks_metric)\n", + "\n", + " outdegree_kmedoid.process()\n", + " centoids = outdegree_kmedoid.get_medoids()\n", + " return centoids[0]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Find representative for out degree" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* the rep found is ../input/humanOutput\\R_20158_run_1.csv\n", + "* the average distance between it and others is 0.05515988287586802" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "../input/humanOutput\\R_20158_run_1.csv\n", + "../input/humanOutput\\R_20158_run_1.csv\n" + ] + } + ], + "source": [ + "od_rep_index = findRep(models, lambda m: m.out_d)\n", + "print(list(modelToFileName.values())[od_rep_index])\n", + "od_rep_model = models[od_rep_index]\n", + "print(modelToFileName[od_rep_model])\n" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.05515988287586802\n" + ] + } + ], + "source": [ + "total_distance = 0\n", + "count = 0\n", + "for model in models:\n", + " total_distance += ks_value(od_rep_model.out_d, model.out_d)\n", + "print(total_distance / len(models))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Find Representative for node activities" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* the rep found is ../input/humanOutput\\R_2016176_run_1.csv\n", + "* the average distance between it and others is 0.05275267434589047" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "../input/humanOutput\\R_2016176_run_1.csv\n", + "../input/humanOutput\\R_2016176_run_1.csv\n" + ] + } + ], + "source": [ + "total_distance = 0\n", + "for model in models:\n", + " total_distance += ks_value(od_rep_model.mpc, model.mpc)\n", + "print(total_distance / len(models))" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.05275267434589047\n" + ] + } + ], + "source": [ + "total_distance = 0\n", + "count = 0\n", + "for model in models:\n", + " total_distance += ks_value(od_rep_model.na, model.na)\n", + "print(total_distance / len(models))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Find Representative for MPC" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* the rep found is ../input/humanOutput\\R_2015246_run_1.csv\n", + "* the average distance between it and others is 0.08556632702185384" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "../input/humanOutput\\R_2015246_run_1.csv\n", + "../input/humanOutput\\R_2015246_run_1.csv\n" + ] + } + ], + "source": [ + "mpc_rep_index = findRep(models, lambda m: m.mpc)\n", + "print(list(modelToFileName.values())[mpc_rep_index])\n", + "mpc_rep_model = models[mpc_rep_index]\n", + "print(modelToFileName[mpc_rep_model])" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.08556632702185384\n" + ] + } + ], + "source": [ + "total_distance = 0\n", + "count = 0\n", + "for model in models:\n", + " total_distance += ks_value(od_rep_model.mpc, model.mpc)\n", + "print(total_distance / len(models))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/MPC.png deleted file mode 100644 index cd2af5ce..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/MPC.png and /dev/null differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Node Activity.png deleted file mode 100644 index 2ce3672b..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Node Activity.png and /dev/null differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Out Degree.png deleted file mode 100644 index d4d9afe1..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Out Degree.png and /dev/null differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/MPC.png deleted file mode 100644 index 8d76fed9..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/MPC.png and /dev/null differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/Node Activity.png deleted file mode 100644 index daa7929a..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/Node Activity.png and /dev/null differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/Out Degree.png deleted file mode 100644 index e56b1b6e..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-/Out Degree.png and /dev/null differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/MPC.png deleted file mode 100644 index 8705cee2..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/MPC.png and /dev/null differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Node Activity.png deleted file mode 100644 index bdab3741..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Node Activity.png and /dev/null differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Out Degree.png deleted file mode 100644 index e4269f6e..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Out Degree.png and /dev/null differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/MPC.png deleted file mode 100644 index e4b6b527..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/MPC.png and /dev/null differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Node Activity.png deleted file mode 100644 index e067ad66..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Node Activity.png and /dev/null differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Out Degree.png deleted file mode 100644 index 9b89e4f9..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Out Degree.png and /dev/null differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/MPC.png deleted file mode 100644 index 4f189578..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/MPC.png and /dev/null differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/Node Activity.png deleted file mode 100644 index add3c0f8..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/Node Activity.png and /dev/null differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/Out Degree.png deleted file mode 100644 index f4717a1a..00000000 Binary files a/Metrics/Metrics-Calculation/metrics_plot/output/real vs viatra vs alloy/Out Degree.png and /dev/null differ diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/GraphType.py b/Metrics/Metrics-Calculation/metrics_plot/src/GraphType.py deleted file mode 100644 index eb35aba3..00000000 --- a/Metrics/Metrics-Calculation/metrics_plot/src/GraphType.py +++ /dev/null @@ -1,28 +0,0 @@ -import readCSV as reader -import constants -import numpy as np - -# graph stats for a collection of graphs -class GraphCollection: - - # init with path contrain files and number of files to read reader is imported from (readCSV) - def __init__(self, path, number, name, shouldShuffle = True): - self.out_ds = [] - self.nas = [] - self.mpcs = [] - self.name = name - models = reader.readmultiplefiles(path, number, shouldShuffle) - for i in range(len(models)): - contents, out_d, na, mpc = reader.getmetrics(models[i]) - self.out_ds.append(out_d) - self.nas.append(na) - self.mpcs.append(mpc) - -#Graph stat for one graph -class GraphStat: - # init with teh file name of the stat - def __init__(self, filename): - contents, self.out_d, self.na, self.mpc = reader.getmetrics(filename) - self.num_nodes = np.array(contents[constants.NUMBER_NODES]) - if constants.STATE_ID in contents: - self.id = (contents[constants.STATE_ID])[0] diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/average_ks_plot.py b/Metrics/Metrics-Calculation/metrics_plot/src/average_ks_plot.py deleted file mode 100644 index e949a729..00000000 --- a/Metrics/Metrics-Calculation/metrics_plot/src/average_ks_plot.py +++ /dev/null @@ -1,62 +0,0 @@ -from GraphType import GraphStat -from GraphType import GraphCollection -from scipy import stats -import readCSV as reader -import matplotlib.pyplot as plt - -class GraphDistance: - #init with a graph stat and a collection of graph stats - def __init__(self, graphStat, collection): - self.graph = graphStat - self.collection = collection - print('calculating for %d' %(self.graph.id)) - self.out_d_distance = average_ks_distance(collection.out_ds, graphStat.out_d) - self.na_distance = average_ks_distance(collection.nas, graphStat.na) - self.mpc_distance = average_ks_distance(collection.mpcs, graphStat.mpc) - -def average_ks_distance(targets, sample): - distance = 0.0 - for target in targets: - value, p = stats.ks_2samp(target, sample) - distance += value - - distance = distance / len(targets) - return distance - -# metric_selector: GraphDistance -> float -def plot(infos, lines, id, metric_selector, title): - metric_distances = retrive_info_from_list(metric_selector, list(infos.values())) - x = retrive_info_from_list(lambda a : a.graph.num_nodes, list(infos.values)) - graph = plt.figure(id) - plt.title(title) - - for line in lines: - line_infos = retrive_info_from_list(lambda a: infos[a], line) - line_y = retrive_info_from_list(metric_selector, line_infos) - line_x = retrive_info_from_list(lambda a : a.graph.num_nodes, list(infos.values)) - plt.plot(line_x, line_y, color='blue') - plt.plot(x, metric_distances, color='red', linestyle='', marker='o',alpha=0.7) - graph.show() - -def retrive_info_from_list(selector, distances): - return list(map(selector, list(infos.values))) - -human = GraphCollection('../statistics/humanOutput/', 300, 'Human') -file_names = reader.readmultiplefiles('../statistics/viatraEvolve/', 500, False) - -infos = [] -# read all files -for name in file_names: - infos.append(GraphStat(name)) - -infos = list(map(lambda s: GraphDistance(s, human), infos)) - -info_dic = {} -for info in infos: - info_dic[info.graph.id] = info - -plot(info_dic, [[1,2,3,4,5,6,7,8,9,10]], 0, lambda a: a.out_d_distance, 'out degree') -# plot(info_dic, 1, lambda a: a.na_distance, 'node activity') -# plot(info_dic, 2, lambda a: a.mpc_distance, 'mpc') - -input() \ No newline at end of file diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/constants.py b/Metrics/Metrics-Calculation/metrics_plot/src/constants.py deleted file mode 100644 index 803bae2e..00000000 --- a/Metrics/Metrics-Calculation/metrics_plot/src/constants.py +++ /dev/null @@ -1,25 +0,0 @@ -NUMBER_EDGE_TYPES = 'Number of Edge types' - -NUMBER_NODES = 'Number Of Nodes' - -OUT_DEGREE_COUNT = 'OutDegreeCount' - -OUT_DEGREE_VALUE = 'OutDegreeValue' - -NA_COUNT = 'NACount' - -NA_VALUE = 'NAValue' - -MPC_VALUE = 'MPCValue' - -MPC_COUNT = 'MPCCount' - -METAMODEL = 'Meta Mode' - -STATE_ID = 'State Id' - -HUMAN_OUT_D_REP = '../statistics/humanOutput/R_20158_run_1.csv' - -HUMAN_MPC_REP = '../statistics/humanOutput/R_2015246_run_1.csv' - -HUMAN_NA_REP = '../statistics/humanOutput/R_2016176_run_1.csv' diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance.ipynb b/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance.ipynb deleted file mode 100644 index 550e3978..00000000 --- a/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance.ipynb +++ /dev/null @@ -1,481 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Compare Metrics Distances to The Human Models" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Imports" - ] - }, - { - "cell_type": "code", - "execution_count": 48, - "metadata": {}, - "outputs": [], - "source": [ - "from GraphType import GraphStat\n", - "from GraphType import GraphCollection\n", - "from scipy import stats\n", - "from ipywidgets import interact, fixed, interactive\n", - "import readCSV as reader\n", - "import ipywidgets as widgets\n", - "import matplotlib.pyplot as plt\n", - "import random\n", - "import numpy as np\n", - "import constants\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Classes" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* Record the average distances of different metrics for a model to the human models " - ] - }, - { - "cell_type": "code", - "execution_count": 49, - "metadata": {}, - "outputs": [], - "source": [ - "class GraphDistance:\n", - " #init with a graph stat and a collection of graph stats\n", - " def __init__(self, graphStat, collection):\n", - " self.graph = graphStat\n", - " self.collection = collection\n", - " self.out_d_distance = average_ks_distance(collection.out_ds, graphStat.out_d)\n", - " self.na_distance = average_ks_distance(collection.nas, graphStat.na)\n", - " self.mpc_distance = average_ks_distance(collection.mpcs, graphStat.mpc)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Methods" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* Calculate the average ks distance" - ] - }, - { - "cell_type": "code", - "execution_count": 50, - "metadata": {}, - "outputs": [], - "source": [ - "def average_ks_distance(targets, sample):\n", - " distance = 0.0\n", - " for target in targets:\n", - " value, p = stats.ks_2samp(target, sample)\n", - " distance += value\n", - " distance = distance / len(targets)\n", - " return distance\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "pycharm": { - "name": "#%% md\n" - } - }, - "source": [ - "* Find the median ks distance of the same number of nodes" - ] - }, - { - "cell_type": "code", - "execution_count": 51, - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [], - "source": [ - "def find_median(x, metric_distances):\n", - " distance_dic = {}\n", - " for index, num_of_nodes in enumerate(x):\n", - " if num_of_nodes[0] not in distance_dic:\n", - " distance_dic[num_of_nodes[0]] = []\n", - " distance_dic[num_of_nodes[0]].append(metric_distances[index])\n", - " median_x = []\n", - " y = []\n", - " for num_of_nodes, distances in distance_dic.items():\n", - " median_x.append(num_of_nodes)\n", - " y.append(np.median(distances))\n", - " order = np.argsort(median_x)\n", - " median_x = np.array(median_x)[order]\n", - " median_y = np.array(y)[order]\n", - " return median_x, median_y\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* Plot Diagram" - ] - }, - { - "cell_type": "code", - "execution_count": 52, - "metadata": {}, - "outputs": [], - "source": [ - "# metric_selector: GraphDistance -> float\n", - "def plot(infos, lines, id, metric_selector,colors, title):\n", - " metric_distances = retrive_info_from_list(metric_selector, list(infos.values()))\n", - " x = retrive_info_from_list(lambda a : a.graph.num_nodes, list(infos.values()))\n", - " graph = plt.figure(id,figsize=(18, 10))\n", - " plt.title(title)\n", - " plt.plot(x, metric_distances, color='red', linestyle='', marker='o',alpha=0.7)\n", - " #plot ks distance median\n", - " median_x, median_y = find_median(x, metric_distances)\n", - " plt.plot(median_x, median_y, color='black',marker='o')\n", - " for i in range(0, len(lines)):\n", - " line_infos = retrive_info_from_list(lambda a: infos[a], lines[i])\n", - " line_y = retrive_info_from_list(metric_selector, line_infos)\n", - " line_x = retrive_info_from_list(lambda a : a.graph.num_nodes, line_infos)\n", - " plt.plot(line_x, line_y, marker='o', color=colors[i])\n", - " #graph.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* Retrieve information from a list " - ] - }, - { - "cell_type": "code", - "execution_count": 53, - "metadata": {}, - "outputs": [], - "source": [ - "def retrive_info_from_list(selector, distances):\n", - " return list(map(selector, distances))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Read Models" - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "metadata": {}, - "outputs": [], - "source": [ - "human = GraphCollection('../statistics/humanOutput/', 300, 'Human', True)\n", - "file_names = reader.readmultiplefiles('../statistics/viatraEvolve/', 1000, False)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Calculate Distances" - ] - }, - { - "cell_type": "code", - "execution_count": 55, - "metadata": {}, - "outputs": [], - "source": [ - "# Progress Widge\n", - "w2 = widgets.FloatProgress(\n", - " value=0,\n", - " min=0,\n", - " max=1.0,\n", - " step=0.1,\n", - " description='Loading Files...:',\n", - " bar_style='info',\n", - " orientation='horizontal'\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 56, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "ca7932bce2a741afaff6b919042c42b0", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "FloatProgress(value=0.0, bar_style='info', description='Loading Files...:', max=1.0)" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "infos = []\n", - "# read all files\n", - "counter = 0.0\n", - "size = len(file_names)\n", - "#display progress bar\n", - "display(w2)\n", - "for name in file_names:\n", - " infos.append(GraphStat(name))\n", - "\n", - "info_dic = {}\n", - "for info in infos:\n", - " w2.value = (counter/size)\n", - " counter+=1\n", - " info = GraphDistance(info, human)\n", - " info_dic[info.graph.id] = info" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Plot Graphs" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* widget for select trajectory" - ] - }, - { - "cell_type": "code", - "execution_count": 57, - "metadata": {}, - "outputs": [], - "source": [ - "filenames = reader.readmultiplefiles('../statistics/trajectories/', 10, False)\n", - "trajectories = {}\n", - "for name in filenames:\n", - " trajectories[name] = reader.readTrajectory(name)\n", - "\n", - "w = widgets.SelectMultiple(\n", - " options = trajectories,\n", - " value = [trajectories[filenames[0]]],\n", - " description='Trajectory:',\n", - " disabled=False,\n", - ")\n", - "\n", - "#generate random color for each line\n", - "colors = []\n", - "\n", - "for i in range(0, len(trajectories)):\n", - " color = \"#%06x\" % random.randint(0, 0xFFFFFF)\n", - " colors.append(color)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Out Degree" - ] - }, - { - "cell_type": "code", - "execution_count": 63, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "08da62cb0c3f4e6e9591c7dc811d27cc", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(SelectMultiple(description='Trajectory:', index=(1,), options={'../statistics/trajectori…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 63, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def plot_out_degree(lines):\n", - " plot(info_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree')\n", - "interact(plot_out_degree, lines=w)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Node Activity" - ] - }, - { - "cell_type": "code", - "execution_count": 64, - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "a708f43645a24bd2b15b53ea12c7d88f", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(SelectMultiple(description='Trajectory:', index=(1,), options={'../statistics/trajectori…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 64, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def plot_na(lines):\n", - " plot(info_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity')\n", - "interact(plot_na, lines=w)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### MPC" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 65, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "124a0cb0ebfb4225bf4ced24c09032f7", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(SelectMultiple(description='Trajectory:', index=(1,), options={'../statistics/trajectori…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 65, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def plot_out_degree(lines):\n", - " plot(info_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC')\n", - "interact(plot_out_degree, lines=w)" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [], - "source": [ - "for name in file_names:\n", - " contents = reader.readcsvfile(name)\n", - " if(contents['State Id'][0] == 1032396643):\n", - " print(name)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.3" - }, - "pycharm": { - "stem_cell": { - "cell_type": "raw", - "metadata": { - "collapsed": false - }, - "source": [] - } - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} 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 deleted file mode 100644 index a0b0ad8d..00000000 --- a/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance_with_selector.ipynb +++ /dev/null @@ -1,763 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Measuremments with Representative" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Imports" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from GraphType import GraphStat\n", - "from GraphType import GraphCollection\n", - "from scipy import stats\n", - "from ipywidgets import interact, fixed, interactive\n", - "import readCSV as reader\n", - "import ipywidgets as widgets\n", - "import matplotlib.pyplot as plt\n", - "import random\n", - "import numpy as np\n", - "import constants\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Classes" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* Record the distances of different metrics using a representative" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "class GraphDistanceWithRep:\n", - " #init with a graph stat and a collection of graph stats\n", - " def __init__(self, graphStat, rep):\n", - " self.graph = graphStat\n", - " self.rep = rep\n", - " self.out_d_distance, _ = stats.ks_2samp(graphStat.out_d, rep.out_d)\n", - " self.na_distance,_ = stats.ks_2samp(graphStat.na, rep.na)\n", - " self.mpc_distance,_ = stats.ks_2samp(graphStat.mpc, rep.mpc)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Methods\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* Find the median ks distance of the same number of nodes" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "def find_median(x, metric_distances):\n", - " distance_dic = {}\n", - " for index, num_of_nodes in enumerate(x):\n", - " if num_of_nodes[0] not in distance_dic:\n", - " distance_dic[num_of_nodes[0]] = []\n", - " distance_dic[num_of_nodes[0]].append(metric_distances[index])\n", - " median_x = []\n", - " y = []\n", - " for num_of_nodes, distances in distance_dic.items():\n", - " median_x.append(num_of_nodes)\n", - " y.append(np.median(distances))\n", - " order = np.argsort(median_x)\n", - " median_x = np.array(median_x)[order]\n", - " median_y = np.array(y)[order]\n", - " return median_x, median_y\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* Plot Diagram" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "# metric_selector: GraphDistance -> float\n", - "def plot(infos, lines, id, metric_selector,colors, title):\n", - " metric_distances = retrive_info_from_list(metric_selector, list(infos.values()))\n", - " x = retrive_info_from_list(lambda a : a.graph.num_nodes, list(infos.values()))\n", - " graph = plt.figure(id,figsize=(18, 10))\n", - " plt.title(title)\n", - " plt.plot(x, metric_distances, color='red', linestyle='', marker='o',alpha=0.7)\n", - " #plot ks distance median\n", - " median_x, median_y = find_median(x, metric_distances)\n", - " plt.plot(median_x, median_y, color='black',marker='o')\n", - " for i in range(0, len(lines)):\n", - " line_infos = retrive_info_from_list(lambda a: infos[a], lines[i])\n", - " line_y = retrive_info_from_list(metric_selector, line_infos)\n", - " line_x = retrive_info_from_list(lambda a : a.graph.num_nodes, line_infos)\n", - " plt.plot(line_x, line_y, marker='o', color=colors[i])\n", - " #graph.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* Retrieve information from a list " - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "def retrive_info_from_list(selector, distances):\n", - " return list(map(selector, distances))" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "def readStats(path, numModels):\n", - " names = reader.readmultiplefiles(path, numModels, False)\n", - " stats = []\n", - " for name in names:\n", - " stats.append(GraphStat(name))\n", - " return stats" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "def calDistanceDic(stats, rep):\n", - " dic = {}\n", - " for info in stats:\n", - " info = GraphDistanceWithRep(info, rep)\n", - " dic[info.graph.id] = info\n", - " return dic" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Read Models" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [], - "source": [ - "### Read Models\n", - "#read representative\n", - "human_rep = GraphStat(constants.HUMAN_OUT_D_REP)\n", - "human_na = GraphStat(constants.HUMAN_NA_REP)\n", - "human_mpc = GraphStat(constants.HUMAN_MPC_REP)\n", - "\n", - "# assign rep distributions to human_rep\n", - "human_rep.na = human_na.na\n", - "human_rep.mpc = human_mpc.mpc\n", - "# Read generated models\n", - "viatra_no_con_stats = readStats('../statistics/viatra_nocon_output/', 5000)\n", - "viatra_con_stats = readStats('../statistics/viatra_con_output/',5000)\n", - "random_stats = readStats('../statistics/random_output/',5000)\n", - "con_viatra_stats = readStats('../statistics/controled_viatra/',300)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## calculate distribution distantces" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [], - "source": [ - "viatra_no_con_dic = calDistanceDic(viatra_no_con_stats, human_rep)\n", - "viatra_con_dic = calDistanceDic(viatra_con_stats, human_rep)\n", - "random_dic = calDistanceDic(random_stats, human_rep)\n", - "con_viatra_dic = calDistanceDic(con_viatra_stats, human_rep)" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [ - "filenames = reader.readmultiplefiles('../statistics/viatra_nocon_output/trajectories/', 15, False)\n", - "trajectories = {}\n", - "for name in filenames:\n", - " trajectories[name] = reader.readTrajectory(name)\n", - "\n", - "w = widgets.SelectMultiple(\n", - " options = trajectories,\n", - " value = [trajectories[filenames[0]]],\n", - " description='Trajectory:',\n", - " disabled=False,\n", - ")\n", - "\n", - "#generate random color for each line\n", - "colors = []\n", - "\n", - "for i in range(0, len(trajectories)):\n", - " color = \"#%06x\" % random.randint(0, 0xFFFFFF)\n", - " colors.append(color)" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "868a437468d24144926f1390cbf2acb8", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/viatra_noc…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def plot_out_degree(lines):\n", - " plot(viatra_no_con_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree')\n", - "interact(plot_out_degree, lines=w)" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "e8b74fe96a45445f8062468ddf2597bf", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/viatra_noc…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def plot_out_na(lines):\n", - " plot(viatra_no_con_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity')\n", - "interact(plot_out_na, lines=w)" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "c6e7e31f454a48169dac12c8aac70eef", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/viatra_noc…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def plot_out_mpc(lines):\n", - " plot(viatra_no_con_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC')\n", - "interact(plot_out_mpc, lines=w)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "cebc359548f74cc8b7540ecc3876c9ee", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def plot_out_degree(lines):\n", - " plot(viatra_con_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree')\n", - "interact(plot_out_degree, lines=[[]])" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "682beae42eef4676b11b6fe23127a44e", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def plot_na(lines):\n", - " plot(viatra_con_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity')\n", - "interact(plot_na, lines=[[]])" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "6893b8c6e03441f89fc35bf784992ae9", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def plot_mpc(lines):\n", - " plot(viatra_con_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC')\n", - "interact(plot_mpc, lines=[[]])" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "ff0e1991c69a4d77a40f57225f90295a", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def plot_out_degree(lines):\n", - " plot(random_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree')\n", - "interact(plot_out_degree, lines=[[]])" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "838570f20bed4d8d9c618305984d19ef", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def plot_out_degree(lines):\n", - " plot(random_dic, lines, 0, lambda a: a.na_distance, colors, 'out degree')\n", - "interact(plot_out_degree, lines=[[]])" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "f4825f6257a74bce9dd22aac8a98effa", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def plot_out_degree(lines):\n", - " plot(random_dic, lines, 0, lambda a: a.mpc_distance, colors, 'out degree')\n", - "interact(plot_out_degree, lines=[[]])" - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "metadata": {}, - "outputs": [], - "source": [ - "con_viatra_stats = readStats('../statistics/controled_viatra/',5000)\n", - "con_viatra_dic = calDistanceDic(con_viatra_stats, human_rep)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Trajectories for controlled viatra solver" - ] - }, - { - "cell_type": "code", - "execution_count": 56, - "metadata": {}, - "outputs": [], - "source": [ - "filenames = reader.readmultiplefiles('../statistics/controled_viatra/trajectories/', 25, False)\n", - "trajectories = {}\n", - "for name in filenames:\n", - " trajectories[name] = reader.readTrajectory(name)\n", - "\n", - "w = widgets.SelectMultiple(\n", - " options = trajectories,\n", - " value = [trajectories[filenames[0]]],\n", - " description='Trajectory:',\n", - " disabled=False,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 57, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "4b60ae3859e343299badf29272f67d21", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/controled_…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 57, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def plot_out_degree(lines):\n", - " plot(con_viatra_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out_degree')\n", - "interact(plot_out_degree, lines=w)" - ] - }, - { - "cell_type": "code", - "execution_count": 58, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "8e7965d793a146d4bbc268554262eb58", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/controled_…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 58, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def plot_na(lines):\n", - " plot(con_viatra_dic, lines, 0, lambda a: a.na_distance, colors, 'Node Activity')\n", - "interact(plot_na, lines=w)" - ] - }, - { - "cell_type": "code", - "execution_count": 59, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "55a1209d0b924a39b4729228e81ee3ab", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/controled_…" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 59, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def plot_mpc(lines):\n", - " plot(con_viatra_dic, lines, 0, lambda a: a.mpc_distance, colors, 'mpc')\n", - "interact(plot_mpc, lines=w)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.3" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/plot_ks_stats.py b/Metrics/Metrics-Calculation/metrics_plot/src/plot_ks_stats.py deleted file mode 100644 index ad72a4a1..00000000 --- a/Metrics/Metrics-Calculation/metrics_plot/src/plot_ks_stats.py +++ /dev/null @@ -1,90 +0,0 @@ -import glob -import random -from sklearn.manifold import MDS -import matplotlib.pyplot as plt -from scipy import stats -import numpy as np -from GraphType import GraphCollection - -def calculateKSMatrix(dists): - dist = [] - - for i in range(len(dists)): - dist = dist + dists[i] - matrix = np.empty((len(dist),len(dist))) - - for i in range(len(dist)): - matrix[i,i] = 0 - for j in range(i+1, len(dist)): - value, p = stats.ks_2samp(dist[i], dist[j]) - matrix[i, j] = value - matrix[j, i] = value - return matrix - - -def calculateMDS(dissimilarities): - embedding = MDS(n_components=2, dissimilarity='precomputed') - trans = embedding.fit_transform(X=dissimilarities) - return trans - -def plot(graphTypes, coords, title='',index = 0, savePath = ''): - half_length = int(coords.shape[0] / len(graphTypes)) - color = ['blue', 'red', 'green', 'yellow'] - lineStyle = ['', '-'] - plt.figure(index, figsize=(7, 4)) - plt.title(title) - for i in range(len(graphTypes)): - x = (coords[(i*half_length):((i+1)*half_length), 0].tolist()) - y = (coords[(i*half_length):((i+1)*half_length), 1].tolist()) - plt.plot(x, y, color=color[i], marker='o', label = graphTypes[i].name, linestyle=lineStyle[i], alpha=0.7) - plt.legend(loc='upper right') - plt.savefig(fname = savePath, dpi=150) - #graph.show() - -def mkdir_p(mypath): - '''Creates a directory. equivalent to using mkdir -p on the command line''' - - from errno import EEXIST - from os import makedirs,path - - try: - makedirs(mypath) - except OSError as exc: # Python >2.5 - if exc.errno == EEXIST and path.isdir(mypath): - pass - else: raise - -def metricStat(graphTypes, metricName, metric, graphIndex): - metrics = [] - foldName = '../output/' - for graph in graphTypes: - metrics.append(metric(graph)) - foldName = foldName + graph.name + '-' - print('calculate' + metricName +' for ' + foldName) - mkdir_p(foldName) - out_d_coords = calculateMDS(calculateKSMatrix(metrics)) - plot(graphTypes, out_d_coords, metricName, graphIndex,foldName + '/'+ metricName+'.png') - -def nodeActivity(graphType): - return graphType.nas - -def outDegree(graphType): - return graphType.out_ds - -def mpc(graphType): - return graphType.mpcs - - -# read models -human = GraphCollection('../statistics/humanOutput/', 500, 'Human') -# viatra30 = GraphCollection('../statistics/viatraOutput30/', 500, 'Viatra (30 nodes)') -# viatra60 = GraphCollection('../statistics/viatraOutput60/', 500, 'Viatra (60 nodes)') -# viatra100 = GraphCollection('../statistics/viatraOutput100/', 500, 'Viatra (100 nodes)') -# random = GraphCollection('../statistics/randomOutput/', 500, 'Random') -# alloy = GraphCollection('../statistics/alloyOutput/', 500, 'Alloy (30 nodes)') -viatraEvolve = GraphCollection('../statistics/viatraEvolve/', 130, 'viatraEvolve', shouldShuffle = False) - -#calculate metrics -metricStat([human, viatraEvolve], 'Node Activity', nodeActivity, 0) -metricStat([human, viatraEvolve], 'Out Degree', outDegree, 1) -metricStat([human, viatraEvolve], 'MPC', mpc, 2) \ No newline at end of file diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/readCSV.py b/Metrics/Metrics-Calculation/metrics_plot/src/readCSV.py deleted file mode 100644 index e0402519..00000000 --- a/Metrics/Metrics-Calculation/metrics_plot/src/readCSV.py +++ /dev/null @@ -1,169 +0,0 @@ -import numpy as np -import matplotlib.pyplot as plt -from scipy import stats -import glob -import random -import constants - -# -# read csvfile returns outdegree, node activity, mpc -# as matrix with the first row of values and second row of count -# -def readcsvfile(filename): - - contents = {} - with open(filename) as f: - for i, line in enumerate(f): - arr = line.split(',') - # if there is no element in the line, continue - if len(line) < 0: continue - # else check for contents - # if it is MPC then use float - if arr[0] == constants.MPC_VALUE: - contents[constants.MPC_VALUE] = list(map(float, arr[1:])) - # meta models are string - elif(arr[0] == constants.METAMODEL): - contents[constants.METAMODEL] = arr[1:] - # all other contants are integer - else: - contents[arr[0]] = list(map(int, arr[1:])) - f.close() - return contents - -def checkAndReshape(arr): - if len(arr.shape) < 2: - arr = np.reshape(arr, (arr.shape[0],1)) - return arr - -def readTrajectory(filename): - state_codes = [] - with open(filename) as f: - for i, line in enumerate(f): - if(line == ''): continue - state_codes.append(int(line)) - return state_codes -# -# take a matrix as input -# return the sample array -# -def getsample(dataMatrix): - data = [] - value = dataMatrix[0, :] - count = dataMatrix[1, :] - for i, v in enumerate(value): - for x in range(0, int(count[i])): - data.append(v) - return data - -def reproduceSample(values, counts): - arr = np.array([values, counts]) - return getsample(arr) - -# -# take an array of filenames as input -# return the samples of outdegree, na, mpc -# -def getmetrics(filename): - contents = readcsvfile(filename) - outdegree_sample = reproduceSample(contents[constants.OUT_DEGREE_VALUE], contents[constants.OUT_DEGREE_COUNT]) - na_sample = reproduceSample(contents[constants.NA_VALUE], contents[constants.NA_COUNT]) - mpc_sample = reproduceSample(contents[constants.MPC_VALUE], contents[constants.MPC_COUNT]) - return contents,outdegree_sample, na_sample, mpc_sample - -# -# read number of files in the given path RANDOMLY -# -def readmultiplefiles(dirName, maxNumberOfFiles, shouldShuffle = True): - list_of_files = glob.glob(dirName + '*.csv') # create the list of file - if shouldShuffle: - random.shuffle(list_of_files) - #if the number of files is out of bound then just give the whole list - file_names = list_of_files[:maxNumberOfFiles] - # print(file_names) - return file_names - - -def plotlines(x, y, ax): - l1, = ax.plot(x, y) - - -def testgetsamplesfromfiles(): - files = readmultiplefiles('../statistics/viatraOutput/', 2) - for file in files: - getmetrics(file) - -def probability(data): - sum = np.sum(data) - probabilityList = [] - for d in data: - p = d/sum - probabilityList.append(p) - a = np.array(probabilityList) - return a - - -def cumulativeProbability(p): - cdf = np.cumsum(p) - return cdf - - -def plot(): - fig, ax = plt.subplots() - fig, ax1 = plt.subplots() - fig, ax2 = plt.subplots() - fig, ax3 = plt.subplots() - fig, ax4 = plt.subplots() - fig, ax5 = plt.subplots() - list_of_files = readmultiplefiles('../statistics/iatraOutput/') - for file_name in list_of_files: - contents = readcsvfile(file_name) - outdegree = [contents[constants.OUT_DEGREE_VALUE], contents[constants.OUT_DEGREE_COUNT]] - na = [contents[constants.NA_VALUE], contents[constants.NA_COUNT]] - mpc = [contents[constants.MPC_VALUE], contents[constants.MPC_COUNT]] - outV = outdegree[0, :] - outC = outdegree[1, :] - outP = probability(outC) - outCumP = cumulativeProbability(outP) - plotlines(outV, outP, ax) - naV = na[0, :] - naC = na[1, :] - naP = probability(naC) - naCumP = cumulativeProbability(naP) - plotlines(naV, naP, ax1) - mpcV = mpc[0, :] - mpcC = mpc[1, :] - mpcP = probability(mpcC) - mpcCumP = cumulativeProbability(mpcP) - plotlines(mpcV, mpcP, ax2) - plotlines(outV, outCumP, ax3) - plotlines(naV, naCumP, ax4) - plotlines(mpcV, mpcCumP, ax5) - ax.set_xlabel('ourdegree') - ax.set_ylabel('pdf') - ax.grid() - - ax1.set_xlabel('node activity') - ax1.set_ylabel('pdf') - ax1.grid() - - ax2.set_xlabel('multiplex participation coefficient') - ax2.set_ylabel('pdf') - ax2.grid() - - ax3.set_xlabel('ourdegree') - ax3.set_ylabel('cdf') - ax3.grid() - - ax4.set_xlabel('node activity') - ax4.set_ylabel('cdf') - ax4.grid() - - ax5.set_xlabel('multiplex participation coefficient') - ax5.set_ylabel('cdf') - ax5.grid() - - plt.show() - - -# plot() - diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/representative_selector .ipynb b/Metrics/Metrics-Calculation/metrics_plot/src/representative_selector .ipynb deleted file mode 100644 index 4886c215..00000000 --- a/Metrics/Metrics-Calculation/metrics_plot/src/representative_selector .ipynb +++ /dev/null @@ -1,262 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Use K-medoid algorithm to find the suitable human model representitives" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Imports" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from GraphType import GraphStat\n", - "import readCSV as reader\n", - "from scipy import stats\n", - "from ipywidgets import interact, fixed, interactive\n", - "import ipywidgets as widgets\n", - "from pyclustering.cluster.kmedoids import kmedoids\n", - "from pyclustering.utils.metric import distance_metric, type_metric\n", - "import random" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Define a new distance metric" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "def ks_value(dest1, dest2):\n", - " value, p = stats.ks_2samp(dest1, dest2)\n", - " return value\n", - "\n", - "\n", - "ks_metric = distance_metric(type_metric.USER_DEFINED, func=ks_value)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Read Human Models" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "1253" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Progress Widge\n", - "w = widgets.FloatProgress(\n", - " value=0,\n", - " min=0,\n", - " max=1.0,\n", - " step=0.1,\n", - " description='Loading Files...:',\n", - " bar_style='info',\n", - " orientation='horizontal'\n", - ")\n", - "\n", - "\n", - "humanFiles = reader.readmultiplefiles('../statistics/humanOutput/', 1300, False)\n", - "modelToFileName = {}\n", - "for name in humanFiles:\n", - " modelToFileName[GraphStat(name)] = name\n", - "\n", - "models = list(modelToFileName.keys())\n", - "len(humanFiles)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Find Representative by K-medroid for different dists on GraphStat" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* Returns the index of the representative" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "def findRep(graphStats, func):\n", - " out_ds = list(map(func, models))\n", - "\n", - " #choose a random starting point\n", - " start_index = random.randint(0, len(out_ds))\n", - "\n", - " # start with one initial metrid [start_index]\n", - " outdegree_kmedoid = kmedoids(out_ds, [start_index], metric=ks_metric)\n", - "\n", - " outdegree_kmedoid.process()\n", - " centoids = outdegree_kmedoid.get_medoids()\n", - " return centoids[0]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Find representative for out degree" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "../statistics/humanOutput\\R_20158_run_1.csv\n", - "../statistics/humanOutput\\R_20158_run_1.csv\n" - ] - } - ], - "source": [ - "od_rep_index = findRep(models, lambda m: m.out_d)\n", - "print(list(modelToFileName.values())[od_rep_index])\n", - "od_rep_model = models[od_rep_index]\n", - "print(modelToFileName[od_rep_model])\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Find Representative for node activities" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'na_rep_index' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mna_rp_index\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfindRep\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmodels\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mlambda\u001b[0m \u001b[0mm\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mm\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mna\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmodelToFileName\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mna_rep_index\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[0mna_rep_model\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmodels\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mna_rep_index\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmodelToFileName\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mna_rep_model\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mNameError\u001b[0m: name 'na_rep_index' is not defined" - ] - } - ], - "source": [ - "na_rep_index = findRep(models, lambda m: m.na)\n", - "print(list(modelToFileName.values())[na_rep_index])\n", - "na_rep_model = models[na_rep_index]\n", - "print(modelToFileName[na_rep_model])" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "../statistics/humanOutput\\R_2016176_run_1.csv\n", - "../statistics/humanOutput\\R_2016176_run_1.csv\n" - ] - } - ], - "source": [ - "print(list(modelToFileName.values())[na_rp_index])\n", - "na_rep_model = models[na_rp_index]\n", - "print(modelToFileName[na_rep_model])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Find Representative for MPC" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "../statistics/humanOutput\\R_2015246_run_1.csv\n", - "../statistics/humanOutput\\R_2015246_run_1.csv\n" - ] - } - ], - "source": [ - "mpc_rep_index = findRep(models, lambda m: m.mpc)\n", - "print(list(modelToFileName.values())[mpc_rep_index])\n", - "mpc_rep_model = models[mpc_rep_index]\n", - "print(modelToFileName[mpc_rep_model])" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.3" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/test.py b/Metrics/Metrics-Calculation/metrics_plot/src/test.py deleted file mode 100644 index 0212cc2a..00000000 --- a/Metrics/Metrics-Calculation/metrics_plot/src/test.py +++ /dev/null @@ -1,32 +0,0 @@ -from pyclustering.cluster.kmedoids import kmedoids -from pyclustering.utils import read_sample -from pyclustering.samples.definitions import FCPS_SAMPLES -from pyclustering.utils.metric import distance_metric, type_metric -import matplotlib.pyplot as plt - -# metric = distance_metric(type_metric.MINKOWSKI, degree=2) -# print(metric([1,1], [2,2])) - -# Load list of points for cluster analysis. -sample = [[1,1,1], [2,2,2],[3,3,3]] - -# Set random initial medoids. -initial_medoids = [1, 1 ,1] -# Create instance of K-Medoids algorithm. -kmedoids_instance = kmedoids(sample, initial_medoids) -# Run cluster analysis and obtain results. -kmedoids_instance.process() -centoids = kmedoids_instance.get_medoids() -clusters = kmedoids_instance.get_clusters() -# Show allocated clusters. -for cluster_id in range(len(clusters)): - for index in clusters[cluster_id]: - if(cluster_id == 0): - plt.plot(sample[index][0], sample[index][1], 'ro') - print(sample[index][0]) - else: - plt.plot(sample[index][0], sample[index][1], 'bo') - -plt.plot(sample[centoids[0]][0], sample[centoids[0]][1], 'bo') -# plt.plot(sample[centoids[1]][0], sample[centoids[1]][1], 'ro') -plt.show() \ No newline at end of file diff --git a/Metrics/Metrics-Calculation/metrics_plot/statistics/.gitignore b/Metrics/Metrics-Calculation/metrics_plot/statistics/.gitignore deleted file mode 100644 index b3934b01..00000000 --- a/Metrics/Metrics-Calculation/metrics_plot/statistics/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# ignore everything in this folder -* -!.gitignore \ No newline at end of file diff --git a/Metrics/Metrics-Calculation/metrics_plot/utils/constants.py b/Metrics/Metrics-Calculation/metrics_plot/utils/constants.py index 58ca7549..ce9d4255 100644 --- a/Metrics/Metrics-Calculation/metrics_plot/utils/constants.py +++ b/Metrics/Metrics-Calculation/metrics_plot/utils/constants.py @@ -18,8 +18,8 @@ METAMODEL = 'Meta Mode' STATE_ID = 'State Id' -HUMAN_OUT_D_REP = '../statistics/humanOutput\R_20158_run_1.csv' +HUMAN_OUT_D_REP = '../input/humanOutput/R_20158_run_1.csv' -HUMAN_MPC_REP = '../statistics/humanOutput\R_2015246_run_1.csv' +HUMAN_MPC_REP = '../input/humanOutput/R_2015246_run_1.csv' -HUMAN_NA_REP = '../statistics/humanOutput\R_2016176_run_1.csv' +HUMAN_NA_REP = '../input/humanOutput/R_2016176_run_1.csv' -- cgit v1.2.3-54-g00ecf