diff options
Diffstat (limited to 'Metrics/Metrics-Calculation')
63 files changed, 3183 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/.classpath b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/.classpath new file mode 100644 index 00000000..f4f8357b --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/.classpath | |||
@@ -0,0 +1,10 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <classpath> | ||
3 | <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
4 | <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
5 | <classpathentry kind="src" path="src"/> | ||
6 | <classpathentry kind="src" path="xtend-gen"/> | ||
7 | <classpathentry kind="lib" path="C:/Users/chenp/eclipse-workspace/VIATRA-Generator/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/lib/commons-math3-3.6.1.jar"/> | ||
8 | <classpathentry kind="lib" path="C:/Users/chenp/eclipse-workspace/VIATRA-Generator/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/lib/commons-math3-3.6.1-javadoc.jar"/> | ||
9 | <classpathentry kind="output" path="bin"/> | ||
10 | </classpath> | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/.gitignore b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/.gitignore new file mode 100644 index 00000000..317e68e2 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/.gitignore | |||
@@ -0,0 +1,6 @@ | |||
1 | /bin/ | ||
2 | bin/ | ||
3 | testInput/ | ||
4 | testOutput/ | ||
5 | xtend-gen/ | ||
6 | *.csv \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/.project b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/.project new file mode 100644 index 00000000..5154dea0 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/.project | |||
@@ -0,0 +1,34 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <projectDescription> | ||
3 | <name>ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator</name> | ||
4 | <comment></comment> | ||
5 | <projects> | ||
6 | </projects> | ||
7 | <buildSpec> | ||
8 | <buildCommand> | ||
9 | <name>org.eclipse.xtext.ui.shared.xtextBuilder</name> | ||
10 | <arguments> | ||
11 | </arguments> | ||
12 | </buildCommand> | ||
13 | <buildCommand> | ||
14 | <name>org.eclipse.jdt.core.javabuilder</name> | ||
15 | <arguments> | ||
16 | </arguments> | ||
17 | </buildCommand> | ||
18 | <buildCommand> | ||
19 | <name>org.eclipse.pde.ManifestBuilder</name> | ||
20 | <arguments> | ||
21 | </arguments> | ||
22 | </buildCommand> | ||
23 | <buildCommand> | ||
24 | <name>org.eclipse.pde.SchemaBuilder</name> | ||
25 | <arguments> | ||
26 | </arguments> | ||
27 | </buildCommand> | ||
28 | </buildSpec> | ||
29 | <natures> | ||
30 | <nature>org.eclipse.pde.PluginNature</nature> | ||
31 | <nature>org.eclipse.jdt.core.javanature</nature> | ||
32 | <nature>org.eclipse.xtext.ui.shared.xtextNature</nature> | ||
33 | </natures> | ||
34 | </projectDescription> | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/.settings/org.eclipse.jdt.core.prefs b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..0c68a61d --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/.settings/org.eclipse.jdt.core.prefs | |||
@@ -0,0 +1,7 @@ | |||
1 | eclipse.preferences.version=1 | ||
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
4 | org.eclipse.jdt.core.compiler.compliance=1.8 | ||
5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
7 | org.eclipse.jdt.core.compiler.source=1.8 | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/Inputs/.gitignore b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/Inputs/.gitignore new file mode 100644 index 00000000..17126b28 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/Inputs/.gitignore | |||
@@ -0,0 +1,4 @@ | |||
1 | # ignore everything in this folder except for this folder it self | ||
2 | |||
3 | * | ||
4 | !.gitignore \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/META-INF/MANIFEST.MF b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/META-INF/MANIFEST.MF new file mode 100644 index 00000000..da19e07c --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/META-INF/MANIFEST.MF | |||
@@ -0,0 +1,18 @@ | |||
1 | Manifest-Version: 1.0 | ||
2 | Bundle-ManifestVersion: 2 | ||
3 | Bundle-Name: Graph_metrics_calculation | ||
4 | Bundle-SymbolicName: ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator | ||
5 | Bundle-Version: 1.0.0.qualifier | ||
6 | Automatic-Module-Name: graph_metrics_calculation | ||
7 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 | ||
8 | Require-Bundle: com.google.guava, | ||
9 | org.eclipse.xtext.xbase.lib, | ||
10 | org.eclipse.xtend.lib, | ||
11 | org.eclipse.xtend.lib.macro, | ||
12 | org.eclipse.emf.ecore;bundle-version="2.17.0", | ||
13 | org.eclipse.emf.ecore.xmi;bundle-version="2.15.0", | ||
14 | hu.bme.mit.inf.dslreasoner.viatra2logic;bundle-version="1.0.0", | ||
15 | hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph;bundle-version="1.0.0", | ||
16 | hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage;bundle-version="1.0.0", | ||
17 | org.eclipse.viatra.dse;bundle-version="0.21.2" | ||
18 | Export-Package: ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/build.properties b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/build.properties new file mode 100644 index 00000000..34d2e4d2 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/build.properties | |||
@@ -0,0 +1,4 @@ | |||
1 | source.. = src/ | ||
2 | output.. = bin/ | ||
3 | bin.includes = META-INF/,\ | ||
4 | . | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/Domain.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/Domain.xtend new file mode 100644 index 00000000..8351e96b --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/Domain.xtend | |||
@@ -0,0 +1,5 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app | ||
2 | |||
3 | enum Domain{ | ||
4 | Yakinduum | ||
5 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/Main.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/Main.xtend new file mode 100644 index 00000000..cf871ead --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/Main.xtend | |||
@@ -0,0 +1,72 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.EMFGraph | ||
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io.CsvFileWriter | ||
5 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io.GraphReader | ||
6 | import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.impl.YakindummPackageImpl | ||
7 | import java.util.ArrayList | ||
8 | |||
9 | //import yakindumm2.impl.Yakindumm2PackageImpl | ||
10 | |||
11 | class Main { | ||
12 | static class RWInformation{ | ||
13 | public var String inputFolder; | ||
14 | public var String outputFolder; | ||
15 | public var int numRuns; | ||
16 | |||
17 | new(String inputFolder, String outputFolder, int numRuns){ | ||
18 | this.inputFolder = inputFolder; | ||
19 | this.outputFolder = outputFolder; | ||
20 | this.numRuns = numRuns; | ||
21 | } | ||
22 | } | ||
23 | |||
24 | def static void main(String[] args){ | ||
25 | //init model | ||
26 | YakindummPackageImpl.eINSTANCE.eClass; | ||
27 | // Yakindumm2PackageImpl.eINSTANCE.eClass; | ||
28 | //val infos = initData(); | ||
29 | |||
30 | println("Start Reading Models..."); | ||
31 | var reader = new GraphReader(YakindummPackageImpl.eINSTANCE); | ||
32 | // for(info : infos){ | ||
33 | // calculateAllModels(info.inputFolder, info.outputFolder,info.numRuns, reader); | ||
34 | // } | ||
35 | |||
36 | //human input has different package declaration | ||
37 | // reader = new GraphReader(Yakindumm2PackageImpl.eINSTANCE); | ||
38 | val human = new RWInformation("inputs/Random/", "outputs/", 1); | ||
39 | calculateAllModels(human.inputFolder, human.outputFolder,human.numRuns, reader); | ||
40 | |||
41 | |||
42 | println("finished"); | ||
43 | } | ||
44 | |||
45 | static def initData(){ | ||
46 | val infos = new ArrayList<RWInformation>(); | ||
47 | infos.add(new RWInformation("inputs/alloyInput/models/", "../plot/statistics/alloyOutput/", 20)); | ||
48 | infos.add(new RWInformation("inputs/randomInput/models/", "../plot/statistics/randomOutput/", 20)); | ||
49 | infos.add(new RWInformation("inputs/viatraInput30/", "../plot/statistics/viatraOutput30/", 20)); | ||
50 | infos.add(new RWInformation("inputs/viatraInput100/", "../plot/statistics/viatraOutput100/", 10)); | ||
51 | return infos; | ||
52 | } | ||
53 | |||
54 | static def calculateAllModels(String inputFolder, String outputFolder, int numRuns, GraphReader reader){ | ||
55 | for(var i = 1; i <= numRuns; i++){ | ||
56 | val models = new ArrayList<EMFGraph>(); | ||
57 | models.addAll(reader.readModels(inputFolder + "run" + i)); | ||
58 | for(model : models){ | ||
59 | calculateAndOutputMetrics(model, YakindummPackageImpl.eNAME, outputFolder+model.name+"_run_"+i+".csv"); | ||
60 | } | ||
61 | } | ||
62 | println("output results Ended for: " + outputFolder); | ||
63 | |||
64 | |||
65 | } | ||
66 | |||
67 | static def calculateAndOutputMetrics(EMFGraph model, String metaModel, String fileName){ | ||
68 | //println("evaluating for " + model.name); | ||
69 | model.metaModel = metaModel; | ||
70 | CsvFileWriter.write(model.evaluateAllMetrics(), fileName); | ||
71 | } | ||
72 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/PartialInterpretationMetric.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/PartialInterpretationMetric.xtend new file mode 100644 index 00000000..cdd06027 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/PartialInterpretationMetric.xtend | |||
@@ -0,0 +1,124 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.distance.KSDistance | ||
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.PartialInterpretationGraph | ||
5 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io.CsvFileWriter | ||
6 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric | ||
7 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MultiplexParticipationCoefficientMetric | ||
8 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.NodeActivityMetric | ||
9 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.OutDegreeMetric | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
11 | import java.io.File | ||
12 | import java.io.FileNotFoundException | ||
13 | import java.io.PrintWriter | ||
14 | import java.util.ArrayList | ||
15 | import java.util.List | ||
16 | import org.eclipse.emf.ecore.util.EcoreUtil | ||
17 | import org.eclipse.viatra.dse.api.Solution | ||
18 | |||
19 | class PartialInterpretationMetric { | ||
20 | var static state = 0; | ||
21 | var static KSDistance ks; | ||
22 | |||
23 | def static void initPaths(){ | ||
24 | new File("debug/metric/").mkdir(); | ||
25 | new File("debug/metric/trajectories/").mkdir(); | ||
26 | ks = new KSDistance(Domain.Yakinduum); | ||
27 | } | ||
28 | |||
29 | def static MetricDistanceGroup calculateMetricDistance(PartialInterpretation partial){ | ||
30 | val metrics = new ArrayList<Metric>(); | ||
31 | metrics.add(new OutDegreeMetric()); | ||
32 | metrics.add(new NodeActivityMetric()); | ||
33 | metrics.add(new MultiplexParticipationCoefficientMetric()); | ||
34 | |||
35 | val metricCalculator = new PartialInterpretationGraph(partial, metrics, null); | ||
36 | var metricSamples = metricCalculator.evaluateAllMetricsToSamples(); | ||
37 | |||
38 | var mpc = ks.mpcDistance(metricSamples.mpcSamples); | ||
39 | var na = ks.naDistance(metricSamples.naSamples); | ||
40 | var outDegree = ks.outDegreeDistance(metricSamples.outDegreeSamples); | ||
41 | |||
42 | return new MetricDistanceGroup(mpc, na, outDegree); | ||
43 | } | ||
44 | |||
45 | // calculate the metrics for a state | ||
46 | def static void calculateMetric(PartialInterpretation partial, String path, String currentStateId, Integer counter){ | ||
47 | val metrics = new ArrayList<Metric>(); | ||
48 | metrics.add(new OutDegreeMetric()); | ||
49 | metrics.add(new NodeActivityMetric()); | ||
50 | metrics.add(new MultiplexParticipationCoefficientMetric()); | ||
51 | |||
52 | //make dir since the folder can be none existing | ||
53 | new File(path).mkdir(); | ||
54 | val filename = path + "/state_"+currentStateId+"-"+counter+".csv"; | ||
55 | state++; | ||
56 | val metricCalculator = new PartialInterpretationGraph(partial, metrics, currentStateId); | ||
57 | |||
58 | CsvFileWriter.write(metricCalculator.evaluateAllMetrics(), filename); | ||
59 | } | ||
60 | |||
61 | def static void outputTrajectories(PartialInterpretation empty, List<Solution> solutions){ | ||
62 | for(solution : solutions){ | ||
63 | //need to copy the empty solution because the transition directly worked on the graph | ||
64 | val emptySolutionCopy = EcoreUtil.copy(empty) | ||
65 | val trajectory = solution.shortestTrajectory; | ||
66 | trajectory.modelWithEditingDomain = emptySolutionCopy | ||
67 | |||
68 | // state codes that will record the trajectory | ||
69 | val stateCodes = newArrayList() | ||
70 | |||
71 | var counter = 0 | ||
72 | //transform and record the state codes for each state | ||
73 | while(trajectory.doNextTransformation){ | ||
74 | //println(trajectory.stateCoder.createStateCode) | ||
75 | val stateId = trajectory.stateCoder.createStateCode.toString | ||
76 | val interpretation = trajectory.getModel(); | ||
77 | //calculate metrics of current state | ||
78 | calculateMetric(interpretation as PartialInterpretation, "debug/metric/output", stateId, counter) | ||
79 | stateCodes.add(stateId) | ||
80 | counter++ | ||
81 | } | ||
82 | |||
83 | |||
84 | //output the trajectory | ||
85 | try{ | ||
86 | new File("debug/metric/trajectories/").mkdir(); | ||
87 | val path = "debug/metric/trajectories/trajectory"+trajectory.stateCoder.createStateCode.toString+".csv" | ||
88 | val PrintWriter writer = new PrintWriter(new File(path)) | ||
89 | val output = new StringBuilder | ||
90 | for(stateCode : stateCodes){ | ||
91 | output.append(stateCode+'\n') | ||
92 | } | ||
93 | writer.write(output.toString()) | ||
94 | writer.close() | ||
95 | }catch(FileNotFoundException e) { | ||
96 | e.printStackTrace() | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | } | ||
101 | |||
102 | class MetricDistanceGroup{ | ||
103 | var double mpcDistance; | ||
104 | var double naDistance; | ||
105 | var double outDegreeDistance; | ||
106 | |||
107 | new(double mpcDistance, double naDistance, double outDegreeDistance){ | ||
108 | this.mpcDistance = mpcDistance; | ||
109 | this.naDistance = naDistance; | ||
110 | this.outDegreeDistance = outDegreeDistance; | ||
111 | } | ||
112 | |||
113 | def double getMPCDistance(){ | ||
114 | return this.mpcDistance | ||
115 | } | ||
116 | |||
117 | def double getNADistance(){ | ||
118 | return this.naDistance | ||
119 | } | ||
120 | |||
121 | def double getOutDegreeDistance(){ | ||
122 | return this.outDegreeDistance | ||
123 | } | ||
124 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/distance/KSDistance.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/distance/KSDistance.xtend new file mode 100644 index 00000000..1fb21529 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/distance/KSDistance.xtend | |||
@@ -0,0 +1,47 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.distance | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.Domain | ||
4 | import java.util.List | ||
5 | import org.apache.commons.math3.stat.inference.KolmogorovSmirnovTest | ||
6 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io.RepMetricsReader | ||
7 | |||
8 | class KSDistance { | ||
9 | var static ksTester = new KolmogorovSmirnovTest(); | ||
10 | var double[] mpcSamples; | ||
11 | var double[] naSamples; | ||
12 | var double[] outDegreeSamples; | ||
13 | |||
14 | new(Domain d){ | ||
15 | var metrics = RepMetricsReader.read(d); | ||
16 | mpcSamples = metrics.mpcSamples; | ||
17 | naSamples = metrics.naSamples.stream.mapToDouble([it]).toArray(); | ||
18 | outDegreeSamples = metrics.outDegreeSamples.stream.mapToDouble([it]).toArray(); | ||
19 | } | ||
20 | |||
21 | def double mpcDistance(List<Double> samples){ | ||
22 | // map list to array | ||
23 | var arr = samples.stream.mapToDouble([it]).toArray(); | ||
24 | |||
25 | //if the size of array is smaller than 2, ks distance cannot be performed, simply return 1 | ||
26 | if(arr.size < 2) return 1; | ||
27 | return ksTester.kolmogorovSmirnovStatistic(mpcSamples, arr); | ||
28 | } | ||
29 | |||
30 | def double naDistance(List<Double> samples){ | ||
31 | // map list to array | ||
32 | var arr = samples.stream.mapToDouble([it]).toArray(); | ||
33 | |||
34 | //if the size of array is smaller than 2, ks distance cannot be performed, simply return 1 | ||
35 | if(arr.size < 2) return 1; | ||
36 | return ksTester.kolmogorovSmirnovStatistic(naSamples as double[], arr); | ||
37 | } | ||
38 | |||
39 | def double outDegreeDistance(List<Double> samples){ | ||
40 | // map list to array | ||
41 | var arr = samples.stream.mapToDouble([it]).toArray(); | ||
42 | |||
43 | //if the size of array is smaller than 2, ks distance cannot be performed, simply return 1 | ||
44 | if(arr.size < 2) return 1; | ||
45 | return ksTester.kolmogorovSmirnovStatistic(outDegreeSamples, arr); | ||
46 | } | ||
47 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.xtend new file mode 100644 index 00000000..5c161f4b --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.xtend | |||
@@ -0,0 +1,106 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric | ||
4 | import java.util.ArrayList | ||
5 | import java.util.List | ||
6 | import org.eclipse.emf.common.util.EList | ||
7 | import org.eclipse.emf.ecore.EObject | ||
8 | import org.eclipse.emf.ecore.EReference | ||
9 | |||
10 | class EMFGraph extends Graph{ | ||
11 | def void init (EObject root, List<Metric> metrics, String name, List<String> referenceTypes){ | ||
12 | val otherContents = root.eAllContents.toList(); | ||
13 | otherContents.add(root); | ||
14 | init(otherContents, metrics, name, referenceTypes); | ||
15 | } | ||
16 | |||
17 | /** | ||
18 | * init the graph with all nodes and reference types in the meta model | ||
19 | * @param objects: objects in the instance model (exclude root) | ||
20 | * @param metrics: metrics to be evaluated | ||
21 | * @param name: name of the instance model | ||
22 | * @param ReferenceTypes: reference types defined in the meta model | ||
23 | */ | ||
24 | def void init(List<EObject> objects, List<Metric> metrics, String name, List<String> referenceTypes){ | ||
25 | objects.forEach[it| | ||
26 | statistic.addNode(it); | ||
27 | ] | ||
28 | |||
29 | referenceTypes.forEach[it| | ||
30 | statistic.addType(it); | ||
31 | ]; | ||
32 | |||
33 | objects.forEach[source| | ||
34 | source.eClass.EAllReferences.forEach[r| | ||
35 | //add the type first (if it is not added already) | ||
36 | //many references | ||
37 | if(r.isMany){ | ||
38 | source.getNeighbours(r).forEach[target| | ||
39 | addEdge(source, target, r); | ||
40 | ] | ||
41 | }else{ | ||
42 | //single references | ||
43 | val target = source.eGet(r) as EObject; | ||
44 | addEdge(source, target, r); | ||
45 | } | ||
46 | ] | ||
47 | ] | ||
48 | |||
49 | this.metrics = metrics; | ||
50 | this.name = name; | ||
51 | } | ||
52 | |||
53 | /** | ||
54 | * Set basic information for the output | ||
55 | */ | ||
56 | override setBasicInformation(ArrayList<ArrayList<String>> output){ | ||
57 | val metaInfo = new ArrayList<String>(); | ||
58 | metaInfo.add(META_MODEL_HEADER); | ||
59 | metaInfo.add(this.metaModel); | ||
60 | |||
61 | val edgeInfo = new ArrayList<String>(); | ||
62 | edgeInfo.add(NUM_EDGE_TYPE_HEADER); | ||
63 | edgeInfo.add(this.statistic.allTypes.size()+""); | ||
64 | |||
65 | val nodeInfo = new ArrayList<String>(); | ||
66 | nodeInfo.add(NUM_NODE_HEADER); | ||
67 | nodeInfo.add(this.statistic.allNodes.size()+""); | ||
68 | |||
69 | val stateInfo = new ArrayList<String>(); | ||
70 | stateInfo.add(STATE_ID_HEADER); | ||
71 | stateInfo.add(this.name); | ||
72 | |||
73 | |||
74 | output.add(metaInfo); | ||
75 | output.add(edgeInfo); | ||
76 | output.add(nodeInfo); | ||
77 | output.add(stateInfo); | ||
78 | } | ||
79 | |||
80 | def EList<EObject> getNeighbours(EObject o, EReference r){ | ||
81 | return (o.eGet(r, true) as EList<EObject>); | ||
82 | } | ||
83 | |||
84 | def addEdge(EObject source, EObject target, EReference r){ | ||
85 | if(target !== null && r !== null){ | ||
86 | statistic.addEdge(source, target, r.name); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | override GraphStatistic getStatistic(){ | ||
91 | return this.statistic; | ||
92 | } | ||
93 | |||
94 | override String getName(){ | ||
95 | return this.name; | ||
96 | } | ||
97 | |||
98 | def void setMetaModel(String model){ | ||
99 | this.metaModel = model; | ||
100 | } | ||
101 | |||
102 | def String getMetaModel(){ | ||
103 | return this.metaModel; | ||
104 | } | ||
105 | |||
106 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/Graph.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/Graph.xtend new file mode 100644 index 00000000..cf4aedba --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/Graph.xtend | |||
@@ -0,0 +1,61 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric | ||
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MetricSampleGroup | ||
5 | import java.util.ArrayList | ||
6 | import java.util.List | ||
7 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MultiplexParticipationCoefficientMetric | ||
8 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.NodeActivityMetric | ||
9 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.OutDegreeMetric | ||
10 | |||
11 | abstract class Graph { | ||
12 | |||
13 | protected static val String META_MODEL_HEADER = "Meta Mode" | ||
14 | protected static val String NUM_NODE_HEADER = "Number Of Nodes"; | ||
15 | protected static val String NUM_EDGE_TYPE_HEADER = "Number of Edge types"; | ||
16 | protected static val String STATE_ID_HEADER = "State Id"; | ||
17 | |||
18 | protected val statistic = new GraphStatistic(); | ||
19 | protected var List<Metric> metrics; | ||
20 | protected var String name = ""; | ||
21 | protected var String metaModel = ""; | ||
22 | |||
23 | /** | ||
24 | * evaluate all metrics for this model | ||
25 | * return the result as a two dimentional list | ||
26 | */ | ||
27 | def ArrayList<ArrayList<String>> evaluateAllMetrics(){ | ||
28 | val result = new ArrayList<ArrayList<String>>(); | ||
29 | setBasicInformation(result); | ||
30 | |||
31 | for(metric : this.metrics){ | ||
32 | val datas = metric.evaluate(this.statistic); | ||
33 | for(row : datas){ | ||
34 | result.add(new ArrayList<String>(row)); | ||
35 | } | ||
36 | } | ||
37 | return result; | ||
38 | } | ||
39 | |||
40 | def MetricSampleGroup evaluateAllMetricsToSamples(){ | ||
41 | var sample = new MetricSampleGroup(); | ||
42 | |||
43 | for(metric : this.metrics){ | ||
44 | if(metric instanceof MultiplexParticipationCoefficientMetric){ | ||
45 | sample.mpcSamples = metric.evaluateSamples(this.statistic); | ||
46 | }else if(metric instanceof NodeActivityMetric){ | ||
47 | sample.naSamples = metric.evaluateSamples(this.statistic); | ||
48 | }else if(metric instanceof OutDegreeMetric){ | ||
49 | sample.outDegreeSamples = metric.evaluateSamples(this.statistic); | ||
50 | } | ||
51 | } | ||
52 | |||
53 | return sample; | ||
54 | } | ||
55 | |||
56 | def void setBasicInformation(ArrayList<ArrayList<String>> result); | ||
57 | |||
58 | def GraphStatistic getStatistic(); | ||
59 | |||
60 | def String getName(); | ||
61 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.xtend new file mode 100644 index 00000000..7ed58094 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.xtend | |||
@@ -0,0 +1,107 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph | ||
2 | |||
3 | import com.google.common.collect.ArrayListMultimap | ||
4 | import com.google.common.collect.Multimap | ||
5 | import java.util.HashMap | ||
6 | import java.util.HashSet | ||
7 | import java.util.List | ||
8 | import org.eclipse.emf.ecore.EObject | ||
9 | |||
10 | class GraphStatistic { | ||
11 | val incomingEdges = new HashMap<String, Multimap<EObject, EObject>>; | ||
12 | val outcomingEdges = new HashMap<String, Multimap<EObject, EObject>>; | ||
13 | |||
14 | val edgeTypes = new HashSet<String>(); | ||
15 | val nodes = new HashSet<EObject>(); | ||
16 | |||
17 | /** | ||
18 | * Add an edge type to to the graph | ||
19 | * @param type: type to add | ||
20 | */ | ||
21 | def void addType(String type){ | ||
22 | if(edgeTypes.contains(type)){ | ||
23 | return; | ||
24 | } | ||
25 | edgeTypes.add(type); | ||
26 | incomingEdges.put(type, ArrayListMultimap.create()); | ||
27 | outcomingEdges.put(type, ArrayListMultimap.create()); | ||
28 | } | ||
29 | |||
30 | /** | ||
31 | * Add a node to he graph | ||
32 | * @param node: node to add | ||
33 | */ | ||
34 | def void addNode(EObject n){ | ||
35 | if(nodes.contains(n)){ | ||
36 | return; | ||
37 | } | ||
38 | |||
39 | nodes.add(n); | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * Add an edge to the graph | ||
44 | * @param source: source node | ||
45 | * @param target: target node | ||
46 | * @param type: type of the reference | ||
47 | */ | ||
48 | def void addEdge(EObject source, EObject target, String type){ | ||
49 | outcomingEdges.get(type).put(source, target); | ||
50 | incomingEdges.get(type).put(target, source); | ||
51 | } | ||
52 | |||
53 | /** | ||
54 | * calculate the out degree for an object | ||
55 | */ | ||
56 | def int outDegree(EObject o){ | ||
57 | var count = 0; | ||
58 | |||
59 | for (String type : edgeTypes){ | ||
60 | count += outcomingEdges.get(type).get(o).size(); | ||
61 | } | ||
62 | return count; | ||
63 | } | ||
64 | |||
65 | /** | ||
66 | * calculate the in degree of an object | ||
67 | */ | ||
68 | def int inDegree(EObject o){ | ||
69 | var count = 0; | ||
70 | |||
71 | for (String type : edgeTypes){ | ||
72 | count += incomingEdges.get(type).get(o).size(); | ||
73 | } | ||
74 | return count; | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * calculate the dimentional degree of a node | ||
79 | */ | ||
80 | def int dimentionalDegree(EObject o, String type){ | ||
81 | return incomingEdges.get(type).get(o).size() + outcomingEdges.get(type).get(o).size(); | ||
82 | } | ||
83 | |||
84 | /** | ||
85 | * calculate the number of edge types for a given degree. | ||
86 | */ | ||
87 | def int numOfEdgeTypes(EObject o){ | ||
88 | var count = 0; | ||
89 | |||
90 | for(String type : edgeTypes){ | ||
91 | if(dimentionalDegree(o, type) > 0){ | ||
92 | count++; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | return count; | ||
97 | } | ||
98 | |||
99 | def List<String> getAllTypes(){ | ||
100 | return edgeTypes.toList(); | ||
101 | } | ||
102 | |||
103 | def List<EObject> getAllNodes(){ | ||
104 | return nodes.toList(); | ||
105 | } | ||
106 | } | ||
107 | |||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/PartialInterpretationGraph.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/PartialInterpretationGraph.xtend new file mode 100644 index 00000000..14337ab0 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/PartialInterpretationGraph.xtend | |||
@@ -0,0 +1,77 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.impl.BooleanElementImpl | ||
8 | import java.util.ArrayList | ||
9 | import java.util.List | ||
10 | |||
11 | class PartialInterpretationGraph extends Graph{ | ||
12 | |||
13 | /** | ||
14 | * Define a new PartialInterpretationGraph by parse every element from a PartialInterpretation | ||
15 | */ | ||
16 | new(PartialInterpretation partial, List<Metric> metrics, String name){ | ||
17 | //the edge types are defined in terms of RelationDeclaration | ||
18 | partial.problem.relations.filter(RelationDeclaration).forEach[ | ||
19 | this.statistic.addType(it.name); | ||
20 | ] | ||
21 | // add all elements | ||
22 | val elements = getElements(partial); | ||
23 | for(element : elements){ | ||
24 | statistic.addNode(element) | ||
25 | } | ||
26 | |||
27 | for(relationInterpretation : partial.partialrelationinterpretation) { | ||
28 | val type = relationInterpretation.interpretationOf.name | ||
29 | |||
30 | for(edge : relationInterpretation.relationlinks.filter(BinaryElementRelationLink)){ | ||
31 | statistic.addEdge(edge.param1, edge.param2, type); | ||
32 | } | ||
33 | } | ||
34 | |||
35 | this.name = name; | ||
36 | this.metrics = metrics; | ||
37 | } | ||
38 | |||
39 | /** | ||
40 | * Set basic information for the output | ||
41 | */ | ||
42 | override setBasicInformation(ArrayList<ArrayList<String>> output){ | ||
43 | val metaInfo = new ArrayList<String>(); | ||
44 | metaInfo.add(META_MODEL_HEADER); | ||
45 | metaInfo.add(this.metaModel); | ||
46 | |||
47 | val edgeInfo = new ArrayList<String>(); | ||
48 | edgeInfo.add(NUM_EDGE_TYPE_HEADER); | ||
49 | edgeInfo.add(this.statistic.allTypes.size()+""); | ||
50 | |||
51 | val nodeInfo = new ArrayList<String>(); | ||
52 | nodeInfo.add(NUM_NODE_HEADER); | ||
53 | nodeInfo.add(this.statistic.allNodes.size()+""); | ||
54 | |||
55 | val stateInfo = new ArrayList<String>(); | ||
56 | stateInfo.add(STATE_ID_HEADER); | ||
57 | stateInfo.add(this.name); | ||
58 | |||
59 | output.add(metaInfo); | ||
60 | output.add(edgeInfo); | ||
61 | output.add(nodeInfo); | ||
62 | output.add(stateInfo); | ||
63 | } | ||
64 | |||
65 | private def getElements(PartialInterpretation partial){ | ||
66 | return partial.newElements.filter[!(it instanceof BooleanElementImpl)] + partial.problem.elements; | ||
67 | } | ||
68 | |||
69 | override getStatistic() { | ||
70 | throw new UnsupportedOperationException("TODO: auto-generated method stub") | ||
71 | } | ||
72 | |||
73 | override getName() { | ||
74 | return name; | ||
75 | } | ||
76 | |||
77 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/CsvFileWriter.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/CsvFileWriter.xtend new file mode 100644 index 00000000..bed356e9 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/CsvFileWriter.xtend | |||
@@ -0,0 +1,37 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io; | ||
2 | |||
3 | import java.io.File | ||
4 | import java.io.FileNotFoundException | ||
5 | import java.io.PrintWriter | ||
6 | import java.util.ArrayList | ||
7 | import java.util.List | ||
8 | |||
9 | class CsvFileWriter { | ||
10 | def static void write(ArrayList<ArrayList<String>> datas, String uri) { | ||
11 | if(datas.size() <= 0) { | ||
12 | return; | ||
13 | } | ||
14 | |||
15 | //println("Output csv for " + uri); | ||
16 | try { | ||
17 | val PrintWriter writer = new PrintWriter(new File(uri)); | ||
18 | val output = new StringBuilder; | ||
19 | for(List<String> datarow : datas){ | ||
20 | for(var i = 0; i < datarow.size() - 1; i++){ | ||
21 | output.append(datarow.get(i) + ','); | ||
22 | } | ||
23 | |||
24 | if(datarow.size > 1){ | ||
25 | output.append(datarow.get(datarow.size() - 1)); | ||
26 | output.append('\n'); | ||
27 | } | ||
28 | } | ||
29 | |||
30 | writer.write(output.toString()); | ||
31 | writer.close(); | ||
32 | //println("Output csv finished"); | ||
33 | }catch(FileNotFoundException e) { | ||
34 | e.printStackTrace(); | ||
35 | } | ||
36 | } | ||
37 | } | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.xtend new file mode 100644 index 00000000..fc56e142 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.xtend | |||
@@ -0,0 +1,81 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io; | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.EMFGraph | ||
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric | ||
5 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MultiplexParticipationCoefficientMetric | ||
6 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.NodeActivityMetric | ||
7 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.OutDegreeMetric | ||
8 | import java.io.File | ||
9 | import java.io.FileNotFoundException | ||
10 | import java.util.ArrayList | ||
11 | import java.util.List | ||
12 | import org.eclipse.emf.common.util.URI | ||
13 | import org.eclipse.emf.ecore.EObject | ||
14 | import org.eclipse.emf.ecore.EPackage | ||
15 | import org.eclipse.emf.ecore.EReference | ||
16 | import org.eclipse.emf.ecore.resource.Resource | ||
17 | import org.eclipse.emf.ecore.resource.ResourceSet | ||
18 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl | ||
19 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | ||
20 | |||
21 | class GraphReader{ | ||
22 | val ResourceSet resSet = new ResourceSetImpl(); | ||
23 | val referenceTypes = new ArrayList<String>(); | ||
24 | |||
25 | new(EPackage metaModel) { | ||
26 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("*",new XMIResourceFactoryImpl) | ||
27 | |||
28 | //find all reference types in the meta model | ||
29 | metaModel.eAllContents.forEach[ | ||
30 | if(it instanceof EReference){ | ||
31 | referenceTypes.add(it.name); | ||
32 | } | ||
33 | ] | ||
34 | } | ||
35 | |||
36 | def List<EMFGraph> readModels(String path){ | ||
37 | val dir = new File(path); | ||
38 | if(!dir.isDirectory){ | ||
39 | throw new Exception("expecting a directory"); | ||
40 | } | ||
41 | |||
42 | val graphs = new ArrayList<EMFGraph>(); | ||
43 | |||
44 | val metrics = new ArrayList<Metric>(); | ||
45 | metrics.add(new OutDegreeMetric()); | ||
46 | metrics.add(new NodeActivityMetric()); | ||
47 | metrics.add(new MultiplexParticipationCoefficientMetric()); | ||
48 | |||
49 | //check all files in the directory with xmi | ||
50 | for(String name : dir.list.filter[it| it.endsWith(".xmi")]){ | ||
51 | val file = new File(name); | ||
52 | val roots = readModel(EObject, path, file.name); | ||
53 | //add a list of metrics | ||
54 | val g = new EMFGraph(); | ||
55 | for(root : roots){ | ||
56 | g.init(root, metrics, name.replaceFirst(".xmi", ""), referenceTypes); | ||
57 | } | ||
58 | |||
59 | graphs.add(g); | ||
60 | } | ||
61 | |||
62 | return graphs; | ||
63 | } | ||
64 | |||
65 | def <RootType extends EObject> List<RootType> readModel(Class<RootType> type, String path, String name) { | ||
66 | try { | ||
67 | val resource = resSet.getResource(getURI(path, name),true); | ||
68 | if(resource === null) throw new FileNotFoundException(getURI(path, name).toString) | ||
69 | else { | ||
70 | return resource.contents as List<RootType> | ||
71 | } | ||
72 | } catch(Exception e) { | ||
73 | e.printStackTrace(); | ||
74 | throw new FileNotFoundException(getURI(path, name).toString + "reason: " + e.message) | ||
75 | } | ||
76 | } | ||
77 | |||
78 | def static getURI(String path, String name) { | ||
79 | URI.createFileURI(path + "/" + name) | ||
80 | } | ||
81 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/RepMetricsReader.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/RepMetricsReader.xtend new file mode 100644 index 00000000..867ddd1a --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/RepMetricsReader.xtend | |||
@@ -0,0 +1,79 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.Domain | ||
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MultiplexParticipationCoefficientMetric | ||
5 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.NodeActivityMetric | ||
6 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.OutDegreeMetric | ||
7 | import java.io.File | ||
8 | import java.util.List | ||
9 | import java.util.Scanner | ||
10 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MetricSampleGroup | ||
11 | |||
12 | /** | ||
13 | * Read the sample of the distribution of a metric provided the csv file of the metric | ||
14 | */ | ||
15 | class RepMetricsReader { | ||
16 | static def read(Domain d){ | ||
17 | var domainRepPath = CsvDataName.REP_PATH + d.name + '/'; | ||
18 | var rep = new MetricSampleGroup() | ||
19 | rep.mpcSamples = readFile(domainRepPath + CsvDataName.MPC_REP, MultiplexParticipationCoefficientMetric.valueName, | ||
20 | MultiplexParticipationCoefficientMetric.countName).map[Double.parseDouble(it)]; | ||
21 | rep.naSamples = readFile(domainRepPath+CsvDataName.NA_REP, NodeActivityMetric.valueName, NodeActivityMetric.countName | ||
22 | ).map[Double.parseDouble(it)]; | ||
23 | rep.outDegreeSamples = readFile(domainRepPath+CsvDataName.OUT_D_REP, OutDegreeMetric.valueName, OutDegreeMetric.countName | ||
24 | ).map[Double.parseDouble(it)]; | ||
25 | return rep; | ||
26 | } | ||
27 | |||
28 | /** | ||
29 | * read metric data and parse it to samples | ||
30 | */ | ||
31 | private static def List<String> readFile(String filename, String valueDataName, String countDataName){ | ||
32 | var s = new Scanner(new File(filename)); | ||
33 | val counts = newArrayList(); | ||
34 | val values = newArrayList(); | ||
35 | //read data from csv | ||
36 | while(s.hasNext()){ | ||
37 | var data = s.nextLine().split(','); | ||
38 | |||
39 | if(data.size >= 1){ | ||
40 | if(data.get(0).equals(countDataName)){ | ||
41 | //add all data with parsing them as integers | ||
42 | counts.addAll(data.subList(1, data.size()).map[Integer.parseInt(it)]); | ||
43 | }else if(data.get(0).equals(valueDataName)){ | ||
44 | //add all data without parsing (there can be either double or string, to be parsed later) | ||
45 | values.addAll(data.subList(1, data.size())); | ||
46 | } | ||
47 | } | ||
48 | } | ||
49 | |||
50 | return createSamples(counts, values); | ||
51 | } | ||
52 | |||
53 | // create samples from values and counts | ||
54 | private static def List<String> createSamples(List<Integer> counts, List<String> values){ | ||
55 | val samples = newArrayList(); | ||
56 | |||
57 | if(counts.size() != values.size()){ | ||
58 | throw new RuntimeException("counts and values should have the same size!"); | ||
59 | } | ||
60 | |||
61 | for(var i = 0; i < counts.size(); i++){ | ||
62 | for(var j = 0; j < counts.get(i); j++){ | ||
63 | samples.add(values.get(i)); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | return samples; | ||
68 | } | ||
69 | |||
70 | |||
71 | } | ||
72 | |||
73 | class CsvDataName{ | ||
74 | public static val REP_PATH = 'data/'; | ||
75 | public static val MPC_REP = 'mpc_rep.csv'; | ||
76 | public static val NA_REP = 'na_rep.csv'; | ||
77 | public static val OUT_D_REP = 'out_d_rep.csv'; | ||
78 | } | ||
79 | |||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/Metric.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/Metric.xtend new file mode 100644 index 00000000..38ef72f2 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/Metric.xtend | |||
@@ -0,0 +1,8 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic | ||
4 | |||
5 | abstract class Metric { | ||
6 | abstract def String[][] evaluate(GraphStatistic g); | ||
7 | abstract def double[] evaluateSamples(GraphStatistic g); | ||
8 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/MetricSampleGroup.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/MetricSampleGroup.xtend new file mode 100644 index 00000000..8cd3daee --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/MetricSampleGroup.xtend | |||
@@ -0,0 +1,9 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics | ||
2 | |||
3 | import java.util.List | ||
4 | |||
5 | class MetricSampleGroup{ | ||
6 | public var List<Double> mpcSamples; | ||
7 | public var List<Double> naSamples; | ||
8 | public var List<Double> outDegreeSamples; | ||
9 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/MultiplexParticipationCoefficientMetric.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/MultiplexParticipationCoefficientMetric.xtend new file mode 100644 index 00000000..d9c88bb4 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/MultiplexParticipationCoefficientMetric.xtend | |||
@@ -0,0 +1,80 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic | ||
4 | import java.text.DecimalFormat | ||
5 | import java.util.ArrayList | ||
6 | import java.util.HashMap | ||
7 | import org.eclipse.emf.ecore.EObject | ||
8 | |||
9 | class MultiplexParticipationCoefficientMetric extends Metric { | ||
10 | public static val countName = "MPCCount"; | ||
11 | public static val valueName = "MPCValue"; | ||
12 | |||
13 | |||
14 | override evaluate(GraphStatistic g) { | ||
15 | //because the precision issue of double, we translate double values into String to be the key | ||
16 | val formatter = new DecimalFormat("#0.00000"); | ||
17 | |||
18 | //get number of different types | ||
19 | val typeCounts = g.allTypes.size; | ||
20 | val map = new HashMap<String, Integer>(); | ||
21 | //calculate the metric distribution | ||
22 | g.allNodes.forEach[n| | ||
23 | var coef = calculateMPC(n, g, typeCounts); | ||
24 | |||
25 | //format number to String | ||
26 | val value = formatter.format(coef); | ||
27 | if(!map.containsKey(value)){ | ||
28 | map.put(value, 1); | ||
29 | }else{ | ||
30 | map.put(value, map.get(value) + 1); | ||
31 | } | ||
32 | |||
33 | ] | ||
34 | |||
35 | //convert it into a 2 dimentional array | ||
36 | val String[][] datas = newArrayOfSize(2, map.size+1); | ||
37 | datas.get(0).set(0, valueName); | ||
38 | datas.get(1).set(0, countName) | ||
39 | var count = 1; | ||
40 | for(entry : map.entrySet.sortBy[it.key]){ | ||
41 | datas.get(0).set(count, entry.key+""); | ||
42 | datas.get(1).set(count, entry.value+""); | ||
43 | count++; | ||
44 | } | ||
45 | |||
46 | return datas; | ||
47 | } | ||
48 | |||
49 | override evaluateSamples(GraphStatistic g){ | ||
50 | val samples = new ArrayList<Double>(); | ||
51 | val typeCounts = g.allTypes.size; | ||
52 | //calculate the metric distribution | ||
53 | g.allNodes.forEach[ | ||
54 | samples.add(calculateMPC(it, g, typeCounts)); | ||
55 | ] | ||
56 | |||
57 | return samples; | ||
58 | } | ||
59 | |||
60 | def double calculateMPC(EObject n, GraphStatistic g, int typeCounts){ | ||
61 | val edgeCounts = g.outDegree(n) + g.inDegree(n); | ||
62 | |||
63 | var coef = 0.0; | ||
64 | |||
65 | for(type : g.allTypes){ | ||
66 | val degree = g.dimentionalDegree(n, type) as double; | ||
67 | coef += Math.pow(degree / edgeCounts, 2); | ||
68 | } | ||
69 | coef = 1 - coef; | ||
70 | coef = coef * typeCounts / (typeCounts-1); | ||
71 | |||
72 | //Consider the case that either typeCounts-1 or the edgeCounts could be 0 in some situation | ||
73 | //in this case the metric should be evaluated to 0 | ||
74 | if(Double.isNaN(coef)){ | ||
75 | coef = 0; | ||
76 | } | ||
77 | |||
78 | return coef; | ||
79 | } | ||
80 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/NodeActivityMetric.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/NodeActivityMetric.xtend new file mode 100644 index 00000000..fbf06c47 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/NodeActivityMetric.xtend | |||
@@ -0,0 +1,49 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic | ||
4 | import java.util.ArrayList | ||
5 | import java.util.HashMap | ||
6 | |||
7 | class NodeActivityMetric extends Metric { | ||
8 | public static val countName = "NACount"; | ||
9 | public static val valueName = "NAValue"; | ||
10 | |||
11 | override evaluate(GraphStatistic g) { | ||
12 | val map = new HashMap<Integer, Integer>(); | ||
13 | |||
14 | //calculate the metric distribution | ||
15 | g.allNodes.forEach[ | ||
16 | val value = g.numOfEdgeTypes(it); | ||
17 | if(!map.containsKey(value)){ | ||
18 | map.put(value, 1); | ||
19 | }else{ | ||
20 | map.put(value, map.get(value) + 1); | ||
21 | } | ||
22 | ] | ||
23 | |||
24 | //convert it into a 2 dimentional array | ||
25 | val String[][] datas = newArrayOfSize(2, map.size+1); | ||
26 | datas.get(0).set(0, valueName); | ||
27 | datas.get(1).set(0, countName) | ||
28 | |||
29 | var count = 1; | ||
30 | for(entry : map.entrySet.sortBy[it.key]){ | ||
31 | datas.get(0).set(count, entry.key+""); | ||
32 | datas.get(1).set(count, entry.value+""); | ||
33 | count++; | ||
34 | } | ||
35 | |||
36 | return datas; | ||
37 | } | ||
38 | |||
39 | override evaluateSamples(GraphStatistic g){ | ||
40 | val samples = new ArrayList<Double>(); | ||
41 | |||
42 | //calculate the metric distribution | ||
43 | g.allNodes.forEach[ | ||
44 | samples.add(g.numOfEdgeTypes(it) as double); | ||
45 | ] | ||
46 | |||
47 | return samples; | ||
48 | } | ||
49 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/OutDegreeMetric.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/OutDegreeMetric.xtend new file mode 100644 index 00000000..55046b14 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/OutDegreeMetric.xtend | |||
@@ -0,0 +1,49 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic | ||
4 | import java.util.ArrayList | ||
5 | import java.util.HashMap | ||
6 | |||
7 | class OutDegreeMetric extends Metric { | ||
8 | public static val countName = "OutDegreeCount"; | ||
9 | public static val valueName = "OutDegreeValue"; | ||
10 | |||
11 | override evaluate(GraphStatistic g) { | ||
12 | val map = new HashMap<Integer, Integer>(); | ||
13 | |||
14 | //calculate the metric distribution | ||
15 | g.allNodes.forEach[ | ||
16 | val value = g.outDegree(it); | ||
17 | if(!map.containsKey(value)){ | ||
18 | map.put(value, 1); | ||
19 | }else{ | ||
20 | map.put(value, map.get(value) + 1); | ||
21 | } | ||
22 | ] | ||
23 | |||
24 | //convert it into a 2 dimentional array | ||
25 | val String[][] datas = newArrayOfSize(2, map.size+1); | ||
26 | datas.get(0).set(0, valueName); | ||
27 | datas.get(1).set(0, countName) | ||
28 | var count = 1; | ||
29 | for(entry : map.entrySet.sortBy[it.key]){ | ||
30 | datas.get(0).set(count, entry.key+""); | ||
31 | datas.get(1).set(count, entry.value+""); | ||
32 | count++; | ||
33 | } | ||
34 | |||
35 | return datas; | ||
36 | } | ||
37 | |||
38 | override evaluateSamples(GraphStatistic g){ | ||
39 | val samples = new ArrayList<Double>(); | ||
40 | |||
41 | //calculate the metric distribution | ||
42 | g.allNodes.forEach[ | ||
43 | samples.add(g.outDegree(it) as double); | ||
44 | ] | ||
45 | |||
46 | return samples; | ||
47 | } | ||
48 | |||
49 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/.gitignore b/Metrics/Metrics-Calculation/metrics_plot/.gitignore new file mode 100644 index 00000000..dc53b109 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/.gitignore | |||
@@ -0,0 +1,10 @@ | |||
1 | # virtual enviroment | ||
2 | venv/ | ||
3 | |||
4 | # python cache | ||
5 | *.pyc | ||
6 | .ipynb_checkpoints/ | ||
7 | .idea/ | ||
8 | |||
9 | # keep folders | ||
10 | !.gitignore \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/input/.gitignore b/Metrics/Metrics-Calculation/metrics_plot/model comparison/input/.gitignore new file mode 100644 index 00000000..b3934b01 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/input/.gitignore | |||
@@ -0,0 +1,3 @@ | |||
1 | # ignore everything in this folder | ||
2 | * | ||
3 | !.gitignore \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/MPC.png | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Node Activity.png | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Alloy (30 nodes)-/Out Degree.png | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/MPC.png | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/Node Activity.png | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-/Out Degree.png | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/MPC.png | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Node Activity.png | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Random-Viatra (100 nodes)-/Out Degree.png | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/MPC.png | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Node Activity.png | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-Viatra (60 nodes)-Viatra (100 nodes)-/Out Degree.png | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/MPC.png | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/Node Activity.png | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/real vs viatra vs alloy/Out Degree.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py b/Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py new file mode 100644 index 00000000..2f39ca93 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py | |||
@@ -0,0 +1,98 @@ | |||
1 | import os, sys | ||
2 | lib_path = os.path.abspath(os.path.join('..', '..', 'utils')) | ||
3 | sys.path.append(lib_path) | ||
4 | import glob | ||
5 | import random | ||
6 | from sklearn.manifold import MDS | ||
7 | import matplotlib.pyplot as plt | ||
8 | from scipy import stats | ||
9 | import numpy as np | ||
10 | from GraphType import GraphCollection | ||
11 | |||
12 | def main(): | ||
13 | # read models | ||
14 | human = GraphCollection('../input/humanOutput/', 500, 'Human') | ||
15 | viatra30 = GraphCollection('../input/viatraOutput30/', 500, 'Viatra (30 nodes)') | ||
16 | # viatra60 = GraphCollection('../input/viatraOutput60/', 500, 'Viatra (60 nodes)') | ||
17 | # viatra100 = GraphCollection('../input/viatraOutput100/', 500, 'Viatra (100 nodes)') | ||
18 | # random = GraphCollection('../input/randomOutput/', 500, 'Random') | ||
19 | # alloy = GraphCollection('../input/alloyOutput/', 500, 'Alloy (30 nodes)') | ||
20 | |||
21 | models_to_compare = [human, viatra30] | ||
22 | |||
23 | # define output folder | ||
24 | outputFolder = '../output/' | ||
25 | |||
26 | #calculate metrics | ||
27 | metricStat(models_to_compare, 'Node Activity', nodeActivity, 0, outputFolder) | ||
28 | metricStat(models_to_compare, 'Out Degree', outDegree, 1, outputFolder) | ||
29 | metricStat(models_to_compare, 'MPC', mpc, 2, outputFolder) | ||
30 | |||
31 | def calculateKSMatrix(dists): | ||
32 | dist = [] | ||
33 | |||
34 | for i in range(len(dists)): | ||
35 | dist = dist + dists[i] | ||
36 | matrix = np.empty((len(dist),len(dist))) | ||
37 | |||
38 | for i in range(len(dist)): | ||
39 | matrix[i,i] = 0 | ||
40 | for j in range(i+1, len(dist)): | ||
41 | value, p = stats.ks_2samp(dist[i], dist[j]) | ||
42 | matrix[i, j] = value | ||
43 | matrix[j, i] = value | ||
44 | return matrix | ||
45 | |||
46 | |||
47 | def calculateMDS(dissimilarities): | ||
48 | embedding = MDS(n_components=2, dissimilarity='precomputed') | ||
49 | trans = embedding.fit_transform(X=dissimilarities) | ||
50 | return trans | ||
51 | |||
52 | def plot(graphTypes, coords, title='',index = 0, savePath = ''): | ||
53 | half_length = int(coords.shape[0] / len(graphTypes)) | ||
54 | color = ['blue', 'red', 'green', 'yellow'] | ||
55 | plt.figure(index, figsize=(7, 4)) | ||
56 | plt.title(title) | ||
57 | for i in range(len(graphTypes)): | ||
58 | x = (coords[(i*half_length):((i+1)*half_length), 0].tolist()) | ||
59 | y = (coords[(i*half_length):((i+1)*half_length), 1].tolist()) | ||
60 | plt.plot(x, y, color=color[i], marker='o', label = graphTypes[i].name, linestyle='', alpha=0.7) | ||
61 | plt.legend(loc='upper right') | ||
62 | plt.savefig(fname = savePath, dpi=150) | ||
63 | #graph.show() | ||
64 | |||
65 | def mkdir_p(mypath): | ||
66 | '''Creates a directory. equivalent to using mkdir -p on the command line''' | ||
67 | |||
68 | from errno import EEXIST | ||
69 | from os import makedirs,path | ||
70 | |||
71 | try: | ||
72 | makedirs(mypath) | ||
73 | except OSError as exc: # Python >2.5 | ||
74 | if exc.errno == EEXIST and path.isdir(mypath): | ||
75 | pass | ||
76 | else: raise | ||
77 | |||
78 | def metricStat(graphTypes, metricName, metric, graphIndex, outputFolder): | ||
79 | metrics = [] | ||
80 | for graph in graphTypes: | ||
81 | metrics.append(metric(graph)) | ||
82 | outputFolder = outputFolder + graph.name + '-' | ||
83 | print('calculate' + metricName +' for ' + outputFolder) | ||
84 | mkdir_p(outputFolder) | ||
85 | out_d_coords = calculateMDS(calculateKSMatrix(metrics)) | ||
86 | plot(graphTypes, out_d_coords, metricName, graphIndex,outputFolder + '/'+ metricName+'.png') | ||
87 | |||
88 | def nodeActivity(graphType): | ||
89 | return graphType.nas | ||
90 | |||
91 | def outDegree(graphType): | ||
92 | return graphType.out_ds | ||
93 | |||
94 | def mpc(graphType): | ||
95 | return graphType.mpcs | ||
96 | |||
97 | if __name__ == '__main__': | ||
98 | main() \ No newline at end of file | ||
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 @@ | |||
1 | # ignore everything in this folder | ||
2 | * | ||
3 | !.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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/controled_viatra_with_mpc/Node Activity.jpg | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/controled_viatra_with_mpc/mpc.jpg | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/controled_viatra_with_mpc/out_degree.jpg | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf/mpc.jpg | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf/node activity.jpg | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf/out degree.jpg | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf_instantiator/Node Activity.jpg | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf_instantiator/mpc.jpg | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/random_emf_instantiator/out_degree.jpg | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_constraints/MPC.jpg | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_constraints/node activity.jpg | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_constraints/out degree.jpg | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_no_constraints/MPC.jpg | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_no_constraints/node activity.jpg | |||
Binary files 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 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/output/viatra_no_constraints/out degree.jpg | |||
Binary files 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 @@ | |||
1 | { | ||
2 | "cells": [ | ||
3 | { | ||
4 | "cell_type": "markdown", | ||
5 | "metadata": {}, | ||
6 | "source": [ | ||
7 | "# Compare Metrics Distances to The Human Models" | ||
8 | ] | ||
9 | }, | ||
10 | { | ||
11 | "cell_type": "markdown", | ||
12 | "metadata": {}, | ||
13 | "source": [ | ||
14 | "### Imports" | ||
15 | ] | ||
16 | }, | ||
17 | { | ||
18 | "cell_type": "code", | ||
19 | "execution_count": 48, | ||
20 | "metadata": {}, | ||
21 | "outputs": [], | ||
22 | "source": [ | ||
23 | "from GraphType import GraphStat\n", | ||
24 | "from GraphType import GraphCollection\n", | ||
25 | "from scipy import stats\n", | ||
26 | "from ipywidgets import interact, fixed, interactive\n", | ||
27 | "import readCSV as reader\n", | ||
28 | "import ipywidgets as widgets\n", | ||
29 | "import matplotlib.pyplot as plt\n", | ||
30 | "import random\n", | ||
31 | "import numpy as np\n", | ||
32 | "import constants\n" | ||
33 | ] | ||
34 | }, | ||
35 | { | ||
36 | "cell_type": "markdown", | ||
37 | "metadata": {}, | ||
38 | "source": [ | ||
39 | "### Classes" | ||
40 | ] | ||
41 | }, | ||
42 | { | ||
43 | "cell_type": "markdown", | ||
44 | "metadata": {}, | ||
45 | "source": [ | ||
46 | "* Record the average distances of different metrics for a model to the human models " | ||
47 | ] | ||
48 | }, | ||
49 | { | ||
50 | "cell_type": "code", | ||
51 | "execution_count": 49, | ||
52 | "metadata": {}, | ||
53 | "outputs": [], | ||
54 | "source": [ | ||
55 | "class GraphDistance:\n", | ||
56 | " #init with a graph stat and a collection of graph stats\n", | ||
57 | " def __init__(self, graphStat, collection):\n", | ||
58 | " self.graph = graphStat\n", | ||
59 | " self.collection = collection\n", | ||
60 | " self.out_d_distance = average_ks_distance(collection.out_ds, graphStat.out_d)\n", | ||
61 | " self.na_distance = average_ks_distance(collection.nas, graphStat.na)\n", | ||
62 | " self.mpc_distance = average_ks_distance(collection.mpcs, graphStat.mpc)" | ||
63 | ] | ||
64 | }, | ||
65 | { | ||
66 | "cell_type": "markdown", | ||
67 | "metadata": {}, | ||
68 | "source": [ | ||
69 | "### Methods" | ||
70 | ] | ||
71 | }, | ||
72 | { | ||
73 | "cell_type": "markdown", | ||
74 | "metadata": {}, | ||
75 | "source": [ | ||
76 | "* Calculate the average ks distance" | ||
77 | ] | ||
78 | }, | ||
79 | { | ||
80 | "cell_type": "code", | ||
81 | "execution_count": 50, | ||
82 | "metadata": {}, | ||
83 | "outputs": [], | ||
84 | "source": [ | ||
85 | "def average_ks_distance(targets, sample):\n", | ||
86 | " distance = 0.0\n", | ||
87 | " for target in targets:\n", | ||
88 | " value, p = stats.ks_2samp(target, sample)\n", | ||
89 | " distance += value\n", | ||
90 | " distance = distance / len(targets)\n", | ||
91 | " return distance\n" | ||
92 | ] | ||
93 | }, | ||
94 | { | ||
95 | "cell_type": "markdown", | ||
96 | "metadata": { | ||
97 | "pycharm": { | ||
98 | "name": "#%% md\n" | ||
99 | } | ||
100 | }, | ||
101 | "source": [ | ||
102 | "* Find the median ks distance of the same number of nodes" | ||
103 | ] | ||
104 | }, | ||
105 | { | ||
106 | "cell_type": "code", | ||
107 | "execution_count": 51, | ||
108 | "metadata": { | ||
109 | "pycharm": { | ||
110 | "name": "#%%\n" | ||
111 | } | ||
112 | }, | ||
113 | "outputs": [], | ||
114 | "source": [ | ||
115 | "def find_median(x, metric_distances):\n", | ||
116 | " distance_dic = {}\n", | ||
117 | " for index, num_of_nodes in enumerate(x):\n", | ||
118 | " if num_of_nodes[0] not in distance_dic:\n", | ||
119 | " distance_dic[num_of_nodes[0]] = []\n", | ||
120 | " distance_dic[num_of_nodes[0]].append(metric_distances[index])\n", | ||
121 | " median_x = []\n", | ||
122 | " y = []\n", | ||
123 | " for num_of_nodes, distances in distance_dic.items():\n", | ||
124 | " median_x.append(num_of_nodes)\n", | ||
125 | " y.append(np.median(distances))\n", | ||
126 | " order = np.argsort(median_x)\n", | ||
127 | " median_x = np.array(median_x)[order]\n", | ||
128 | " median_y = np.array(y)[order]\n", | ||
129 | " return median_x, median_y\n" | ||
130 | ] | ||
131 | }, | ||
132 | { | ||
133 | "cell_type": "markdown", | ||
134 | "metadata": {}, | ||
135 | "source": [ | ||
136 | "* Plot Diagram" | ||
137 | ] | ||
138 | }, | ||
139 | { | ||
140 | "cell_type": "code", | ||
141 | "execution_count": 52, | ||
142 | "metadata": {}, | ||
143 | "outputs": [], | ||
144 | "source": [ | ||
145 | "# metric_selector: GraphDistance -> float\n", | ||
146 | "def plot(infos, lines, id, metric_selector,colors, title):\n", | ||
147 | " metric_distances = retrive_info_from_list(metric_selector, list(infos.values()))\n", | ||
148 | " x = retrive_info_from_list(lambda a : a.graph.num_nodes, list(infos.values()))\n", | ||
149 | " graph = plt.figure(id,figsize=(18, 10))\n", | ||
150 | " plt.title(title)\n", | ||
151 | " plt.plot(x, metric_distances, color='red', linestyle='', marker='o',alpha=0.7)\n", | ||
152 | " #plot ks distance median\n", | ||
153 | " median_x, median_y = find_median(x, metric_distances)\n", | ||
154 | " plt.plot(median_x, median_y, color='black',marker='o')\n", | ||
155 | " for i in range(0, len(lines)):\n", | ||
156 | " line_infos = retrive_info_from_list(lambda a: infos[a], lines[i])\n", | ||
157 | " line_y = retrive_info_from_list(metric_selector, line_infos)\n", | ||
158 | " line_x = retrive_info_from_list(lambda a : a.graph.num_nodes, line_infos)\n", | ||
159 | " plt.plot(line_x, line_y, marker='o', color=colors[i])\n", | ||
160 | " #graph.show()" | ||
161 | ] | ||
162 | }, | ||
163 | { | ||
164 | "cell_type": "markdown", | ||
165 | "metadata": {}, | ||
166 | "source": [ | ||
167 | "* Retrieve information from a list " | ||
168 | ] | ||
169 | }, | ||
170 | { | ||
171 | "cell_type": "code", | ||
172 | "execution_count": 53, | ||
173 | "metadata": {}, | ||
174 | "outputs": [], | ||
175 | "source": [ | ||
176 | "def retrive_info_from_list(selector, distances):\n", | ||
177 | " return list(map(selector, distances))" | ||
178 | ] | ||
179 | }, | ||
180 | { | ||
181 | "cell_type": "markdown", | ||
182 | "metadata": {}, | ||
183 | "source": [ | ||
184 | "### Read Models" | ||
185 | ] | ||
186 | }, | ||
187 | { | ||
188 | "cell_type": "code", | ||
189 | "execution_count": 54, | ||
190 | "metadata": {}, | ||
191 | "outputs": [], | ||
192 | "source": [ | ||
193 | "human = GraphCollection('../statistics/humanOutput/', 300, 'Human', True)\n", | ||
194 | "file_names = reader.readmultiplefiles('../statistics/viatraEvolve/', 1000, False)" | ||
195 | ] | ||
196 | }, | ||
197 | { | ||
198 | "cell_type": "markdown", | ||
199 | "metadata": {}, | ||
200 | "source": [ | ||
201 | "### Calculate Distances" | ||
202 | ] | ||
203 | }, | ||
204 | { | ||
205 | "cell_type": "code", | ||
206 | "execution_count": 55, | ||
207 | "metadata": {}, | ||
208 | "outputs": [], | ||
209 | "source": [ | ||
210 | "# Progress Widge\n", | ||
211 | "w2 = widgets.FloatProgress(\n", | ||
212 | " value=0,\n", | ||
213 | " min=0,\n", | ||
214 | " max=1.0,\n", | ||
215 | " step=0.1,\n", | ||
216 | " description='Loading Files...:',\n", | ||
217 | " bar_style='info',\n", | ||
218 | " orientation='horizontal'\n", | ||
219 | ")" | ||
220 | ] | ||
221 | }, | ||
222 | { | ||
223 | "cell_type": "code", | ||
224 | "execution_count": 56, | ||
225 | "metadata": {}, | ||
226 | "outputs": [ | ||
227 | { | ||
228 | "data": { | ||
229 | "application/vnd.jupyter.widget-view+json": { | ||
230 | "model_id": "ca7932bce2a741afaff6b919042c42b0", | ||
231 | "version_major": 2, | ||
232 | "version_minor": 0 | ||
233 | }, | ||
234 | "text/plain": [ | ||
235 | "FloatProgress(value=0.0, bar_style='info', description='Loading Files...:', max=1.0)" | ||
236 | ] | ||
237 | }, | ||
238 | "metadata": {}, | ||
239 | "output_type": "display_data" | ||
240 | } | ||
241 | ], | ||
242 | "source": [ | ||
243 | "infos = []\n", | ||
244 | "# read all files\n", | ||
245 | "counter = 0.0\n", | ||
246 | "size = len(file_names)\n", | ||
247 | "#display progress bar\n", | ||
248 | "display(w2)\n", | ||
249 | "for name in file_names:\n", | ||
250 | " infos.append(GraphStat(name))\n", | ||
251 | "\n", | ||
252 | "info_dic = {}\n", | ||
253 | "for info in infos:\n", | ||
254 | " w2.value = (counter/size)\n", | ||
255 | " counter+=1\n", | ||
256 | " info = GraphDistance(info, human)\n", | ||
257 | " info_dic[info.graph.id] = info" | ||
258 | ] | ||
259 | }, | ||
260 | { | ||
261 | "cell_type": "markdown", | ||
262 | "metadata": {}, | ||
263 | "source": [ | ||
264 | "#### Plot Graphs" | ||
265 | ] | ||
266 | }, | ||
267 | { | ||
268 | "cell_type": "markdown", | ||
269 | "metadata": {}, | ||
270 | "source": [ | ||
271 | "* widget for select trajectory" | ||
272 | ] | ||
273 | }, | ||
274 | { | ||
275 | "cell_type": "code", | ||
276 | "execution_count": 57, | ||
277 | "metadata": {}, | ||
278 | "outputs": [], | ||
279 | "source": [ | ||
280 | "filenames = reader.readmultiplefiles('../statistics/trajectories/', 10, False)\n", | ||
281 | "trajectories = {}\n", | ||
282 | "for name in filenames:\n", | ||
283 | " trajectories[name] = reader.readTrajectory(name)\n", | ||
284 | "\n", | ||
285 | "w = widgets.SelectMultiple(\n", | ||
286 | " options = trajectories,\n", | ||
287 | " value = [trajectories[filenames[0]]],\n", | ||
288 | " description='Trajectory:',\n", | ||
289 | " disabled=False,\n", | ||
290 | ")\n", | ||
291 | "\n", | ||
292 | "#generate random color for each line\n", | ||
293 | "colors = []\n", | ||
294 | "\n", | ||
295 | "for i in range(0, len(trajectories)):\n", | ||
296 | " color = \"#%06x\" % random.randint(0, 0xFFFFFF)\n", | ||
297 | " colors.append(color)" | ||
298 | ] | ||
299 | }, | ||
300 | { | ||
301 | "cell_type": "markdown", | ||
302 | "metadata": {}, | ||
303 | "source": [ | ||
304 | "#### Out Degree" | ||
305 | ] | ||
306 | }, | ||
307 | { | ||
308 | "cell_type": "code", | ||
309 | "execution_count": 63, | ||
310 | "metadata": {}, | ||
311 | "outputs": [ | ||
312 | { | ||
313 | "data": { | ||
314 | "application/vnd.jupyter.widget-view+json": { | ||
315 | "model_id": "08da62cb0c3f4e6e9591c7dc811d27cc", | ||
316 | "version_major": 2, | ||
317 | "version_minor": 0 | ||
318 | }, | ||
319 | "text/plain": [ | ||
320 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(1,), options={'../statistics/trajectori…" | ||
321 | ] | ||
322 | }, | ||
323 | "metadata": {}, | ||
324 | "output_type": "display_data" | ||
325 | }, | ||
326 | { | ||
327 | "data": { | ||
328 | "text/plain": [ | ||
329 | "<function __main__.plot_out_degree(lines)>" | ||
330 | ] | ||
331 | }, | ||
332 | "execution_count": 63, | ||
333 | "metadata": {}, | ||
334 | "output_type": "execute_result" | ||
335 | } | ||
336 | ], | ||
337 | "source": [ | ||
338 | "def plot_out_degree(lines):\n", | ||
339 | " plot(info_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree')\n", | ||
340 | "interact(plot_out_degree, lines=w)" | ||
341 | ] | ||
342 | }, | ||
343 | { | ||
344 | "cell_type": "markdown", | ||
345 | "metadata": {}, | ||
346 | "source": [ | ||
347 | "#### Node Activity" | ||
348 | ] | ||
349 | }, | ||
350 | { | ||
351 | "cell_type": "code", | ||
352 | "execution_count": 64, | ||
353 | "metadata": { | ||
354 | "scrolled": true | ||
355 | }, | ||
356 | "outputs": [ | ||
357 | { | ||
358 | "data": { | ||
359 | "application/vnd.jupyter.widget-view+json": { | ||
360 | "model_id": "a708f43645a24bd2b15b53ea12c7d88f", | ||
361 | "version_major": 2, | ||
362 | "version_minor": 0 | ||
363 | }, | ||
364 | "text/plain": [ | ||
365 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(1,), options={'../statistics/trajectori…" | ||
366 | ] | ||
367 | }, | ||
368 | "metadata": {}, | ||
369 | "output_type": "display_data" | ||
370 | }, | ||
371 | { | ||
372 | "data": { | ||
373 | "text/plain": [ | ||
374 | "<function __main__.plot_na(lines)>" | ||
375 | ] | ||
376 | }, | ||
377 | "execution_count": 64, | ||
378 | "metadata": {}, | ||
379 | "output_type": "execute_result" | ||
380 | } | ||
381 | ], | ||
382 | "source": [ | ||
383 | "def plot_na(lines):\n", | ||
384 | " plot(info_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity')\n", | ||
385 | "interact(plot_na, lines=w)" | ||
386 | ] | ||
387 | }, | ||
388 | { | ||
389 | "cell_type": "markdown", | ||
390 | "metadata": {}, | ||
391 | "source": [ | ||
392 | "#### MPC" | ||
393 | ] | ||
394 | }, | ||
395 | { | ||
396 | "cell_type": "code", | ||
397 | "execution_count": null, | ||
398 | "metadata": {}, | ||
399 | "outputs": [], | ||
400 | "source": [] | ||
401 | }, | ||
402 | { | ||
403 | "cell_type": "code", | ||
404 | "execution_count": 65, | ||
405 | "metadata": {}, | ||
406 | "outputs": [ | ||
407 | { | ||
408 | "data": { | ||
409 | "application/vnd.jupyter.widget-view+json": { | ||
410 | "model_id": "124a0cb0ebfb4225bf4ced24c09032f7", | ||
411 | "version_major": 2, | ||
412 | "version_minor": 0 | ||
413 | }, | ||
414 | "text/plain": [ | ||
415 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(1,), options={'../statistics/trajectori…" | ||
416 | ] | ||
417 | }, | ||
418 | "metadata": {}, | ||
419 | "output_type": "display_data" | ||
420 | }, | ||
421 | { | ||
422 | "data": { | ||
423 | "text/plain": [ | ||
424 | "<function __main__.plot_out_degree(lines)>" | ||
425 | ] | ||
426 | }, | ||
427 | "execution_count": 65, | ||
428 | "metadata": {}, | ||
429 | "output_type": "execute_result" | ||
430 | } | ||
431 | ], | ||
432 | "source": [ | ||
433 | "def plot_out_degree(lines):\n", | ||
434 | " plot(info_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC')\n", | ||
435 | "interact(plot_out_degree, lines=w)" | ||
436 | ] | ||
437 | }, | ||
438 | { | ||
439 | "cell_type": "code", | ||
440 | "execution_count": 19, | ||
441 | "metadata": {}, | ||
442 | "outputs": [], | ||
443 | "source": [ | ||
444 | "for name in file_names:\n", | ||
445 | " contents = reader.readcsvfile(name)\n", | ||
446 | " if(contents['State Id'][0] == 1032396643):\n", | ||
447 | " print(name)" | ||
448 | ] | ||
449 | } | ||
450 | ], | ||
451 | "metadata": { | ||
452 | "kernelspec": { | ||
453 | "display_name": "Python 3", | ||
454 | "language": "python", | ||
455 | "name": "python3" | ||
456 | }, | ||
457 | "language_info": { | ||
458 | "codemirror_mode": { | ||
459 | "name": "ipython", | ||
460 | "version": 3 | ||
461 | }, | ||
462 | "file_extension": ".py", | ||
463 | "mimetype": "text/x-python", | ||
464 | "name": "python", | ||
465 | "nbconvert_exporter": "python", | ||
466 | "pygments_lexer": "ipython3", | ||
467 | "version": "3.7.3" | ||
468 | }, | ||
469 | "pycharm": { | ||
470 | "stem_cell": { | ||
471 | "cell_type": "raw", | ||
472 | "metadata": { | ||
473 | "collapsed": false | ||
474 | }, | ||
475 | "source": [] | ||
476 | } | ||
477 | } | ||
478 | }, | ||
479 | "nbformat": 4, | ||
480 | "nbformat_minor": 2 | ||
481 | } | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/metrics_distance_with_selector.ipynb b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/metrics_distance_with_selector.ipynb new file mode 100644 index 00000000..4c7fecb3 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/metrics_distance_with_selector.ipynb | |||
@@ -0,0 +1,955 @@ | |||
1 | { | ||
2 | "cells": [ | ||
3 | { | ||
4 | "cell_type": "markdown", | ||
5 | "metadata": {}, | ||
6 | "source": [ | ||
7 | "# Measuremments with Representative" | ||
8 | ] | ||
9 | }, | ||
10 | { | ||
11 | "cell_type": "markdown", | ||
12 | "metadata": {}, | ||
13 | "source": [ | ||
14 | "### Imports" | ||
15 | ] | ||
16 | }, | ||
17 | { | ||
18 | "cell_type": "code", | ||
19 | "execution_count": 2, | ||
20 | "metadata": {}, | ||
21 | "outputs": [], | ||
22 | "source": [ | ||
23 | "import os, sys\n", | ||
24 | "lib_path = os.path.abspath(os.path.join('..', '..', 'utils'))\n", | ||
25 | "sys.path.append(lib_path)\n", | ||
26 | "from GraphType import GraphStat\n", | ||
27 | "from GraphType import GraphCollection\n", | ||
28 | "from scipy import stats\n", | ||
29 | "from ipywidgets import interact, fixed, interactive\n", | ||
30 | "import readCSV as reader\n", | ||
31 | "import ipywidgets as widgets\n", | ||
32 | "import matplotlib.pyplot as plt\n", | ||
33 | "import random\n", | ||
34 | "import numpy as np\n", | ||
35 | "import constants\n" | ||
36 | ] | ||
37 | }, | ||
38 | { | ||
39 | "cell_type": "markdown", | ||
40 | "metadata": {}, | ||
41 | "source": [ | ||
42 | "### Classes" | ||
43 | ] | ||
44 | }, | ||
45 | { | ||
46 | "cell_type": "markdown", | ||
47 | "metadata": {}, | ||
48 | "source": [ | ||
49 | "* Record the distances of different metrics using a representative" | ||
50 | ] | ||
51 | }, | ||
52 | { | ||
53 | "cell_type": "code", | ||
54 | "execution_count": 3, | ||
55 | "metadata": {}, | ||
56 | "outputs": [], | ||
57 | "source": [ | ||
58 | "class GraphDistanceWithRep:\n", | ||
59 | " #init with a graph stat and a collection of graph stats\n", | ||
60 | " def __init__(self, graphStat, rep):\n", | ||
61 | " self.graph = graphStat\n", | ||
62 | " self.rep = rep\n", | ||
63 | " self.out_d_distance, _ = stats.ks_2samp(graphStat.out_d, rep.out_d)\n", | ||
64 | " self.na_distance,_ = stats.ks_2samp(graphStat.na, rep.na)\n", | ||
65 | " self.mpc_distance,_ = stats.ks_2samp(graphStat.mpc, rep.mpc)\n" | ||
66 | ] | ||
67 | }, | ||
68 | { | ||
69 | "cell_type": "markdown", | ||
70 | "metadata": {}, | ||
71 | "source": [ | ||
72 | "### Methods\n" | ||
73 | ] | ||
74 | }, | ||
75 | { | ||
76 | "cell_type": "markdown", | ||
77 | "metadata": {}, | ||
78 | "source": [ | ||
79 | "* Find the median ks distance of the same number of nodes" | ||
80 | ] | ||
81 | }, | ||
82 | { | ||
83 | "cell_type": "code", | ||
84 | "execution_count": 4, | ||
85 | "metadata": {}, | ||
86 | "outputs": [], | ||
87 | "source": [ | ||
88 | "def find_median(x, metric_distances):\n", | ||
89 | " distance_dic = {}\n", | ||
90 | " for index, num_of_nodes in enumerate(x):\n", | ||
91 | " if num_of_nodes[0] not in distance_dic:\n", | ||
92 | " distance_dic[num_of_nodes[0]] = []\n", | ||
93 | " distance_dic[num_of_nodes[0]].append(metric_distances[index])\n", | ||
94 | " median_x = []\n", | ||
95 | " y = []\n", | ||
96 | " for num_of_nodes, distances in distance_dic.items():\n", | ||
97 | " median_x.append(num_of_nodes)\n", | ||
98 | " y.append(np.median(distances))\n", | ||
99 | " order = np.argsort(median_x)\n", | ||
100 | " median_x = np.array(median_x)[order]\n", | ||
101 | " median_y = np.array(y)[order]\n", | ||
102 | " return median_x, median_y\n" | ||
103 | ] | ||
104 | }, | ||
105 | { | ||
106 | "cell_type": "markdown", | ||
107 | "metadata": {}, | ||
108 | "source": [ | ||
109 | "* Plot Diagram" | ||
110 | ] | ||
111 | }, | ||
112 | { | ||
113 | "cell_type": "code", | ||
114 | "execution_count": 38, | ||
115 | "metadata": {}, | ||
116 | "outputs": [], | ||
117 | "source": [ | ||
118 | "# metric_selector: GraphDistance -> float\n", | ||
119 | "def plot(infos, lines, id, metric_selector,colors, title, foldername):\n", | ||
120 | " metric_distances = retrive_info_from_list(metric_selector, list(infos.values()))\n", | ||
121 | " x = retrive_info_from_list(lambda a : a.graph.num_nodes, list(infos.values()))\n", | ||
122 | " graph = plt.figure(id,figsize=(18, 10))\n", | ||
123 | " plt.title(title)\n", | ||
124 | " plt.plot(x, metric_distances, color='red', linestyle='', marker='o',alpha=0.7)\n", | ||
125 | " #plot ks distance median\n", | ||
126 | " median_x, median_y = find_median(x, metric_distances)\n", | ||
127 | " plt.plot(median_x, median_y, color='black',marker='o')\n", | ||
128 | " for i in range(0, len(lines)):\n", | ||
129 | " line_infos = retrive_info_from_list(lambda a: infos[a], lines[i])\n", | ||
130 | " line_y = retrive_info_from_list(metric_selector, line_infos)\n", | ||
131 | " line_x = retrive_info_from_list(lambda a : a.graph.num_nodes, line_infos)\n", | ||
132 | " plt.plot(line_x, line_y, marker='o', color=colors[i])\n", | ||
133 | " mkdir_p(foldername)\n", | ||
134 | " plt.savefig(fname = foldername+title+'.jpg', dpi=150)\n", | ||
135 | " #graph.show()" | ||
136 | ] | ||
137 | }, | ||
138 | { | ||
139 | "cell_type": "markdown", | ||
140 | "metadata": {}, | ||
141 | "source": [ | ||
142 | "* Retrieve information from a list " | ||
143 | ] | ||
144 | }, | ||
145 | { | ||
146 | "cell_type": "code", | ||
147 | "execution_count": 6, | ||
148 | "metadata": {}, | ||
149 | "outputs": [], | ||
150 | "source": [ | ||
151 | "def retrive_info_from_list(selector, distances):\n", | ||
152 | " return list(map(selector, distances))" | ||
153 | ] | ||
154 | }, | ||
155 | { | ||
156 | "cell_type": "code", | ||
157 | "execution_count": 7, | ||
158 | "metadata": {}, | ||
159 | "outputs": [], | ||
160 | "source": [ | ||
161 | "def readStats(path, numModels):\n", | ||
162 | " names = reader.readmultiplefiles(path, numModels, False)\n", | ||
163 | " stats = []\n", | ||
164 | " for name in names:\n", | ||
165 | " stats.append(GraphStat(name))\n", | ||
166 | " return stats" | ||
167 | ] | ||
168 | }, | ||
169 | { | ||
170 | "cell_type": "code", | ||
171 | "execution_count": 8, | ||
172 | "metadata": {}, | ||
173 | "outputs": [], | ||
174 | "source": [ | ||
175 | "def calDistanceDic(stats, rep):\n", | ||
176 | " dic = {}\n", | ||
177 | " for info in stats:\n", | ||
178 | " info = GraphDistanceWithRep(info, rep)\n", | ||
179 | " dic[info.graph.id] = info\n", | ||
180 | " return dic" | ||
181 | ] | ||
182 | }, | ||
183 | { | ||
184 | "cell_type": "code", | ||
185 | "execution_count": 25, | ||
186 | "metadata": {}, | ||
187 | "outputs": [], | ||
188 | "source": [ | ||
189 | "def createRandomColors(size):\n", | ||
190 | " #generate random color for each line\n", | ||
191 | " colors = []\n", | ||
192 | "\n", | ||
193 | " for i in range(0, size):\n", | ||
194 | " color = \"#%06x\" % random.randint(0, 0xFFFFFF)\n", | ||
195 | " colors.append(color)\n", | ||
196 | " return colors" | ||
197 | ] | ||
198 | }, | ||
199 | { | ||
200 | "cell_type": "code", | ||
201 | "execution_count": 43, | ||
202 | "metadata": {}, | ||
203 | "outputs": [], | ||
204 | "source": [ | ||
205 | "def createSelectionWidge(options):\n", | ||
206 | " w = widgets.SelectMultiple(\n", | ||
207 | " options = options,\n", | ||
208 | " value = [],\n", | ||
209 | " description='Trajectory:',\n", | ||
210 | " disabled=False,\n", | ||
211 | " )\n", | ||
212 | " return w" | ||
213 | ] | ||
214 | }, | ||
215 | { | ||
216 | "cell_type": "code", | ||
217 | "execution_count": 33, | ||
218 | "metadata": {}, | ||
219 | "outputs": [], | ||
220 | "source": [ | ||
221 | "def mkdir_p(mypath):\n", | ||
222 | " '''Creates a directory. equivalent to using mkdir -p on the command line'''\n", | ||
223 | "\n", | ||
224 | " from errno import EEXIST\n", | ||
225 | " from os import makedirs,path\n", | ||
226 | "\n", | ||
227 | " try:\n", | ||
228 | " makedirs(mypath)\n", | ||
229 | " except OSError as exc: # Python >2.5\n", | ||
230 | " if exc.errno == EEXIST and path.isdir(mypath):\n", | ||
231 | " pass\n", | ||
232 | " else: raise" | ||
233 | ] | ||
234 | }, | ||
235 | { | ||
236 | "cell_type": "markdown", | ||
237 | "metadata": {}, | ||
238 | "source": [ | ||
239 | "## Metrics During GenerationPlots" | ||
240 | ] | ||
241 | }, | ||
242 | { | ||
243 | "cell_type": "markdown", | ||
244 | "metadata": {}, | ||
245 | "source": [ | ||
246 | "### Read Human Representatives" | ||
247 | ] | ||
248 | }, | ||
249 | { | ||
250 | "cell_type": "code", | ||
251 | "execution_count": 42, | ||
252 | "metadata": {}, | ||
253 | "outputs": [], | ||
254 | "source": [ | ||
255 | "### Read Models\n", | ||
256 | "#read representative\n", | ||
257 | "human_rep = GraphStat(constants.HUMAN_OUT_D_REP)\n", | ||
258 | "human_na = GraphStat(constants.HUMAN_NA_REP)\n", | ||
259 | "human_mpc = GraphStat(constants.HUMAN_MPC_REP)\n", | ||
260 | "\n", | ||
261 | "# assign rep distributions to human_rep\n", | ||
262 | "human_rep.na = human_na.na\n", | ||
263 | "human_rep.mpc = human_mpc.mpc" | ||
264 | ] | ||
265 | }, | ||
266 | { | ||
267 | "cell_type": "markdown", | ||
268 | "metadata": {}, | ||
269 | "source": [ | ||
270 | "## Viatra No Constraint" | ||
271 | ] | ||
272 | }, | ||
273 | { | ||
274 | "cell_type": "code", | ||
275 | "execution_count": 15, | ||
276 | "metadata": {}, | ||
277 | "outputs": [], | ||
278 | "source": [ | ||
279 | "# Read generated models\n", | ||
280 | "viatra_no_con_stats = readStats('../input/viatra_nocon_output/', 5000)\n", | ||
281 | "viatra_no_con_dic = calDistanceDic(viatra_no_con_stats, human_rep)" | ||
282 | ] | ||
283 | }, | ||
284 | { | ||
285 | "cell_type": "code", | ||
286 | "execution_count": 46, | ||
287 | "metadata": {}, | ||
288 | "outputs": [], | ||
289 | "source": [ | ||
290 | "filenames = reader.readmultiplefiles('../input/viatra_nocon_output/trajectories/', 15, False)\n", | ||
291 | "trajectories = {}\n", | ||
292 | "for name in filenames:\n", | ||
293 | " trajectories[name] = reader.readTrajectory(name)\n", | ||
294 | "w = createSelectionWidge(trajectories)\n", | ||
295 | "colors = createRandomColors(len(trajectories))" | ||
296 | ] | ||
297 | }, | ||
298 | { | ||
299 | "cell_type": "code", | ||
300 | "execution_count": 77, | ||
301 | "metadata": {}, | ||
302 | "outputs": [ | ||
303 | { | ||
304 | "data": { | ||
305 | "application/vnd.jupyter.widget-view+json": { | ||
306 | "model_id": "9519be563fbc41c28921c77ef6481b17", | ||
307 | "version_major": 2, | ||
308 | "version_minor": 0 | ||
309 | }, | ||
310 | "text/plain": [ | ||
311 | "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" | ||
312 | ] | ||
313 | }, | ||
314 | "metadata": {}, | ||
315 | "output_type": "display_data" | ||
316 | }, | ||
317 | { | ||
318 | "data": { | ||
319 | "text/plain": [ | ||
320 | "<function __main__.plot_out_degree(lines)>" | ||
321 | ] | ||
322 | }, | ||
323 | "execution_count": 77, | ||
324 | "metadata": {}, | ||
325 | "output_type": "execute_result" | ||
326 | } | ||
327 | ], | ||
328 | "source": [ | ||
329 | "def plot_out_degree(lines):\n", | ||
330 | " plot(viatra_no_con_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree', '../output/viatra_no_constraints/')\n", | ||
331 | "interact(plot_out_degree, lines=w)" | ||
332 | ] | ||
333 | }, | ||
334 | { | ||
335 | "cell_type": "code", | ||
336 | "execution_count": 78, | ||
337 | "metadata": {}, | ||
338 | "outputs": [ | ||
339 | { | ||
340 | "data": { | ||
341 | "application/vnd.jupyter.widget-view+json": { | ||
342 | "model_id": "c896725e542c4bf8a1bc76ba66819b20", | ||
343 | "version_major": 2, | ||
344 | "version_minor": 0 | ||
345 | }, | ||
346 | "text/plain": [ | ||
347 | "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" | ||
348 | ] | ||
349 | }, | ||
350 | "metadata": {}, | ||
351 | "output_type": "display_data" | ||
352 | }, | ||
353 | { | ||
354 | "data": { | ||
355 | "text/plain": [ | ||
356 | "<function __main__.plot_out_na(lines)>" | ||
357 | ] | ||
358 | }, | ||
359 | "execution_count": 78, | ||
360 | "metadata": {}, | ||
361 | "output_type": "execute_result" | ||
362 | } | ||
363 | ], | ||
364 | "source": [ | ||
365 | "def plot_out_na(lines):\n", | ||
366 | " plot(viatra_no_con_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity', '../output/viatra_no_constraints/')\n", | ||
367 | "interact(plot_out_na, lines=w)" | ||
368 | ] | ||
369 | }, | ||
370 | { | ||
371 | "cell_type": "code", | ||
372 | "execution_count": 79, | ||
373 | "metadata": {}, | ||
374 | "outputs": [ | ||
375 | { | ||
376 | "data": { | ||
377 | "application/vnd.jupyter.widget-view+json": { | ||
378 | "model_id": "880410d675624545ab73977a463bb5c9", | ||
379 | "version_major": 2, | ||
380 | "version_minor": 0 | ||
381 | }, | ||
382 | "text/plain": [ | ||
383 | "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" | ||
384 | ] | ||
385 | }, | ||
386 | "metadata": {}, | ||
387 | "output_type": "display_data" | ||
388 | }, | ||
389 | { | ||
390 | "data": { | ||
391 | "text/plain": [ | ||
392 | "<function __main__.plot_out_mpc(lines)>" | ||
393 | ] | ||
394 | }, | ||
395 | "execution_count": 79, | ||
396 | "metadata": {}, | ||
397 | "output_type": "execute_result" | ||
398 | } | ||
399 | ], | ||
400 | "source": [ | ||
401 | "def plot_out_mpc(lines):\n", | ||
402 | " plot(viatra_no_con_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC', '../output/viatra_no_constraints/')\n", | ||
403 | "interact(plot_out_mpc, lines=w)" | ||
404 | ] | ||
405 | }, | ||
406 | { | ||
407 | "cell_type": "markdown", | ||
408 | "metadata": {}, | ||
409 | "source": [ | ||
410 | "## Viatra with constraints" | ||
411 | ] | ||
412 | }, | ||
413 | { | ||
414 | "cell_type": "code", | ||
415 | "execution_count": 50, | ||
416 | "metadata": {}, | ||
417 | "outputs": [], | ||
418 | "source": [ | ||
419 | "viatra_con_stats = readStats('../input/viatra_con_output/',5000)\n", | ||
420 | "viatra_con_dic = calDistanceDic(viatra_con_stats, human_rep)\n", | ||
421 | "\n", | ||
422 | "# trajectories and colors\n", | ||
423 | "trajectories = {}\n", | ||
424 | "w = createSelectionWidge(trajectories)\n", | ||
425 | "colors = createRandomColors(len(trajectories))" | ||
426 | ] | ||
427 | }, | ||
428 | { | ||
429 | "cell_type": "code", | ||
430 | "execution_count": 51, | ||
431 | "metadata": {}, | ||
432 | "outputs": [ | ||
433 | { | ||
434 | "data": { | ||
435 | "application/vnd.jupyter.widget-view+json": { | ||
436 | "model_id": "0d04d6db770a49f4a160ff55cc7131f6", | ||
437 | "version_major": 2, | ||
438 | "version_minor": 0 | ||
439 | }, | ||
440 | "text/plain": [ | ||
441 | "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" | ||
442 | ] | ||
443 | }, | ||
444 | "metadata": {}, | ||
445 | "output_type": "display_data" | ||
446 | }, | ||
447 | { | ||
448 | "data": { | ||
449 | "text/plain": [ | ||
450 | "<function __main__.plot_out_degree(lines)>" | ||
451 | ] | ||
452 | }, | ||
453 | "execution_count": 51, | ||
454 | "metadata": {}, | ||
455 | "output_type": "execute_result" | ||
456 | } | ||
457 | ], | ||
458 | "source": [ | ||
459 | "def plot_out_degree(lines):\n", | ||
460 | " plot(viatra_con_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree', '../output/viatra_constraints/')\n", | ||
461 | "interact(plot_out_degree, lines=[[]])" | ||
462 | ] | ||
463 | }, | ||
464 | { | ||
465 | "cell_type": "code", | ||
466 | "execution_count": 52, | ||
467 | "metadata": {}, | ||
468 | "outputs": [ | ||
469 | { | ||
470 | "data": { | ||
471 | "application/vnd.jupyter.widget-view+json": { | ||
472 | "model_id": "96eebad1f6274d79ad377c8c54b44615", | ||
473 | "version_major": 2, | ||
474 | "version_minor": 0 | ||
475 | }, | ||
476 | "text/plain": [ | ||
477 | "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" | ||
478 | ] | ||
479 | }, | ||
480 | "metadata": {}, | ||
481 | "output_type": "display_data" | ||
482 | }, | ||
483 | { | ||
484 | "data": { | ||
485 | "text/plain": [ | ||
486 | "<function __main__.plot_na(lines)>" | ||
487 | ] | ||
488 | }, | ||
489 | "execution_count": 52, | ||
490 | "metadata": {}, | ||
491 | "output_type": "execute_result" | ||
492 | } | ||
493 | ], | ||
494 | "source": [ | ||
495 | "def plot_na(lines):\n", | ||
496 | " plot(viatra_con_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity', '../output/viatra_constraints/')\n", | ||
497 | "interact(plot_na, lines=[[]])" | ||
498 | ] | ||
499 | }, | ||
500 | { | ||
501 | "cell_type": "code", | ||
502 | "execution_count": 53, | ||
503 | "metadata": {}, | ||
504 | "outputs": [ | ||
505 | { | ||
506 | "data": { | ||
507 | "application/vnd.jupyter.widget-view+json": { | ||
508 | "model_id": "4fc2714a3cd3440daf5014bb4b942b9a", | ||
509 | "version_major": 2, | ||
510 | "version_minor": 0 | ||
511 | }, | ||
512 | "text/plain": [ | ||
513 | "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" | ||
514 | ] | ||
515 | }, | ||
516 | "metadata": {}, | ||
517 | "output_type": "display_data" | ||
518 | }, | ||
519 | { | ||
520 | "data": { | ||
521 | "text/plain": [ | ||
522 | "<function __main__.plot_mpc(lines)>" | ||
523 | ] | ||
524 | }, | ||
525 | "execution_count": 53, | ||
526 | "metadata": {}, | ||
527 | "output_type": "execute_result" | ||
528 | } | ||
529 | ], | ||
530 | "source": [ | ||
531 | "def plot_mpc(lines):\n", | ||
532 | " plot(viatra_con_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC', '../output/viatra_constraints/')\n", | ||
533 | "interact(plot_mpc, lines=[[]])" | ||
534 | ] | ||
535 | }, | ||
536 | { | ||
537 | "cell_type": "markdown", | ||
538 | "metadata": {}, | ||
539 | "source": [ | ||
540 | "## Controlled RandomEMF" | ||
541 | ] | ||
542 | }, | ||
543 | { | ||
544 | "cell_type": "code", | ||
545 | "execution_count": 59, | ||
546 | "metadata": {}, | ||
547 | "outputs": [], | ||
548 | "source": [ | ||
549 | "random_emf_stats = readStats('../input/random_emf_output/',5000)\n", | ||
550 | "random_emf_dic = calDistanceDic(random_emf_stats, human_rep)\n", | ||
551 | "\n", | ||
552 | "# trajectories and colors\n", | ||
553 | "trajectories = {}\n", | ||
554 | "w = createSelectionWidge(trajectories)\n", | ||
555 | "colors = createRandomColors(len(trajectories))" | ||
556 | ] | ||
557 | }, | ||
558 | { | ||
559 | "cell_type": "code", | ||
560 | "execution_count": 60, | ||
561 | "metadata": {}, | ||
562 | "outputs": [ | ||
563 | { | ||
564 | "data": { | ||
565 | "application/vnd.jupyter.widget-view+json": { | ||
566 | "model_id": "4401931533b5497f864f146d7b4dcd3c", | ||
567 | "version_major": 2, | ||
568 | "version_minor": 0 | ||
569 | }, | ||
570 | "text/plain": [ | ||
571 | "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" | ||
572 | ] | ||
573 | }, | ||
574 | "metadata": {}, | ||
575 | "output_type": "display_data" | ||
576 | }, | ||
577 | { | ||
578 | "data": { | ||
579 | "text/plain": [ | ||
580 | "<function __main__.plot_out_degree(lines)>" | ||
581 | ] | ||
582 | }, | ||
583 | "execution_count": 60, | ||
584 | "metadata": {}, | ||
585 | "output_type": "execute_result" | ||
586 | } | ||
587 | ], | ||
588 | "source": [ | ||
589 | "def plot_out_degree(lines):\n", | ||
590 | " plot(random_emf_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree', '../output/random_emf/')\n", | ||
591 | "interact(plot_out_degree, lines=[[]])" | ||
592 | ] | ||
593 | }, | ||
594 | { | ||
595 | "cell_type": "code", | ||
596 | "execution_count": 61, | ||
597 | "metadata": {}, | ||
598 | "outputs": [ | ||
599 | { | ||
600 | "data": { | ||
601 | "application/vnd.jupyter.widget-view+json": { | ||
602 | "model_id": "fb7bdedff841420bb8f817013f565020", | ||
603 | "version_major": 2, | ||
604 | "version_minor": 0 | ||
605 | }, | ||
606 | "text/plain": [ | ||
607 | "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" | ||
608 | ] | ||
609 | }, | ||
610 | "metadata": {}, | ||
611 | "output_type": "display_data" | ||
612 | }, | ||
613 | { | ||
614 | "data": { | ||
615 | "text/plain": [ | ||
616 | "<function __main__.plot_node_activity(lines)>" | ||
617 | ] | ||
618 | }, | ||
619 | "execution_count": 61, | ||
620 | "metadata": {}, | ||
621 | "output_type": "execute_result" | ||
622 | } | ||
623 | ], | ||
624 | "source": [ | ||
625 | "def plot_node_activity(lines):\n", | ||
626 | " plot(random_emf_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity', '../output/random_emf/')\n", | ||
627 | "interact(plot_node_activity, lines=[[]])" | ||
628 | ] | ||
629 | }, | ||
630 | { | ||
631 | "cell_type": "code", | ||
632 | "execution_count": 62, | ||
633 | "metadata": {}, | ||
634 | "outputs": [ | ||
635 | { | ||
636 | "data": { | ||
637 | "application/vnd.jupyter.widget-view+json": { | ||
638 | "model_id": "6b0c349c4a3b4813825513f739ea30da", | ||
639 | "version_major": 2, | ||
640 | "version_minor": 0 | ||
641 | }, | ||
642 | "text/plain": [ | ||
643 | "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" | ||
644 | ] | ||
645 | }, | ||
646 | "metadata": {}, | ||
647 | "output_type": "display_data" | ||
648 | }, | ||
649 | { | ||
650 | "data": { | ||
651 | "text/plain": [ | ||
652 | "<function __main__.plot_mpc(lines)>" | ||
653 | ] | ||
654 | }, | ||
655 | "execution_count": 62, | ||
656 | "metadata": {}, | ||
657 | "output_type": "execute_result" | ||
658 | } | ||
659 | ], | ||
660 | "source": [ | ||
661 | "def plot_mpc(lines):\n", | ||
662 | " plot(random_emf_dic, lines, 0, lambda a: a.mpc_distance, colors, 'mpc', '../output/random_emf/')\n", | ||
663 | "interact(plot_mpc, lines=[[]])" | ||
664 | ] | ||
665 | }, | ||
666 | { | ||
667 | "cell_type": "markdown", | ||
668 | "metadata": {}, | ||
669 | "source": [ | ||
670 | "## Controlled Viatra with MPC" | ||
671 | ] | ||
672 | }, | ||
673 | { | ||
674 | "cell_type": "code", | ||
675 | "execution_count": 67, | ||
676 | "metadata": {}, | ||
677 | "outputs": [], | ||
678 | "source": [ | ||
679 | "con_viatra_stats = readStats('../input/controled_viatra_mpc/',5000)\n", | ||
680 | "con_viatra_dic = calDistanceDic(con_viatra_stats, human_rep)\n", | ||
681 | "\n", | ||
682 | "# trajectories and colors\n", | ||
683 | "trajectories = {}\n", | ||
684 | "w = createSelectionWidge(trajectories)\n", | ||
685 | "colors = createRandomColors(len(trajectories))" | ||
686 | ] | ||
687 | }, | ||
688 | { | ||
689 | "cell_type": "code", | ||
690 | "execution_count": 74, | ||
691 | "metadata": {}, | ||
692 | "outputs": [ | ||
693 | { | ||
694 | "data": { | ||
695 | "application/vnd.jupyter.widget-view+json": { | ||
696 | "model_id": "b76901ba9d44433984032e0dc5679fa9", | ||
697 | "version_major": 2, | ||
698 | "version_minor": 0 | ||
699 | }, | ||
700 | "text/plain": [ | ||
701 | "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" | ||
702 | ] | ||
703 | }, | ||
704 | "metadata": {}, | ||
705 | "output_type": "display_data" | ||
706 | }, | ||
707 | { | ||
708 | "data": { | ||
709 | "text/plain": [ | ||
710 | "<function __main__.plot_out_degree(lines)>" | ||
711 | ] | ||
712 | }, | ||
713 | "execution_count": 74, | ||
714 | "metadata": {}, | ||
715 | "output_type": "execute_result" | ||
716 | } | ||
717 | ], | ||
718 | "source": [ | ||
719 | "def plot_out_degree(lines):\n", | ||
720 | " plot(con_viatra_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out_degree', '../output/controled_viatra_with_mpc/')\n", | ||
721 | "interact(plot_out_degree, lines=w)" | ||
722 | ] | ||
723 | }, | ||
724 | { | ||
725 | "cell_type": "code", | ||
726 | "execution_count": 75, | ||
727 | "metadata": {}, | ||
728 | "outputs": [ | ||
729 | { | ||
730 | "data": { | ||
731 | "application/vnd.jupyter.widget-view+json": { | ||
732 | "model_id": "9e0d61e29b02467cb52618860a1bde7f", | ||
733 | "version_major": 2, | ||
734 | "version_minor": 0 | ||
735 | }, | ||
736 | "text/plain": [ | ||
737 | "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" | ||
738 | ] | ||
739 | }, | ||
740 | "metadata": {}, | ||
741 | "output_type": "display_data" | ||
742 | }, | ||
743 | { | ||
744 | "data": { | ||
745 | "text/plain": [ | ||
746 | "<function __main__.plot_na(lines)>" | ||
747 | ] | ||
748 | }, | ||
749 | "execution_count": 75, | ||
750 | "metadata": {}, | ||
751 | "output_type": "execute_result" | ||
752 | } | ||
753 | ], | ||
754 | "source": [ | ||
755 | "def plot_na(lines):\n", | ||
756 | " plot(con_viatra_dic, lines, 0, lambda a: a.na_distance, colors, 'Node Activity', '../output/controled_viatra_with_mpc/')\n", | ||
757 | "interact(plot_na, lines=w)" | ||
758 | ] | ||
759 | }, | ||
760 | { | ||
761 | "cell_type": "code", | ||
762 | "execution_count": 76, | ||
763 | "metadata": {}, | ||
764 | "outputs": [ | ||
765 | { | ||
766 | "data": { | ||
767 | "application/vnd.jupyter.widget-view+json": { | ||
768 | "model_id": "70074805fee44a1aa5b9ccb3770b5c0c", | ||
769 | "version_major": 2, | ||
770 | "version_minor": 0 | ||
771 | }, | ||
772 | "text/plain": [ | ||
773 | "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" | ||
774 | ] | ||
775 | }, | ||
776 | "metadata": {}, | ||
777 | "output_type": "display_data" | ||
778 | }, | ||
779 | { | ||
780 | "data": { | ||
781 | "text/plain": [ | ||
782 | "<function __main__.plot_mpc(lines)>" | ||
783 | ] | ||
784 | }, | ||
785 | "execution_count": 76, | ||
786 | "metadata": {}, | ||
787 | "output_type": "execute_result" | ||
788 | } | ||
789 | ], | ||
790 | "source": [ | ||
791 | "def plot_mpc(lines):\n", | ||
792 | " plot(con_viatra_dic, lines, 0, lambda a: a.mpc_distance, colors, 'mpc', '../output/controled_viatra_with_mpc/')\n", | ||
793 | "interact(plot_mpc, lines=w)" | ||
794 | ] | ||
795 | }, | ||
796 | { | ||
797 | "cell_type": "markdown", | ||
798 | "metadata": {}, | ||
799 | "source": [ | ||
800 | "## (Pseudo) Random EMF instantiator" | ||
801 | ] | ||
802 | }, | ||
803 | { | ||
804 | "cell_type": "code", | ||
805 | "execution_count": 80, | ||
806 | "metadata": {}, | ||
807 | "outputs": [], | ||
808 | "source": [ | ||
809 | "random_emf_stats = readStats('../input/real_random_output/',5000)\n", | ||
810 | "random_emf_dic = calDistanceDic(random_emf_stats, human_rep)\n", | ||
811 | "\n", | ||
812 | "# trajectories and colors\n", | ||
813 | "trajectories = {}\n", | ||
814 | "w = createSelectionWidge(trajectories)\n", | ||
815 | "colors = createRandomColors(len(trajectories))" | ||
816 | ] | ||
817 | }, | ||
818 | { | ||
819 | "cell_type": "code", | ||
820 | "execution_count": 82, | ||
821 | "metadata": {}, | ||
822 | "outputs": [ | ||
823 | { | ||
824 | "data": { | ||
825 | "application/vnd.jupyter.widget-view+json": { | ||
826 | "model_id": "912ba2fdfd7c46848065f174aa6177e0", | ||
827 | "version_major": 2, | ||
828 | "version_minor": 0 | ||
829 | }, | ||
830 | "text/plain": [ | ||
831 | "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" | ||
832 | ] | ||
833 | }, | ||
834 | "metadata": {}, | ||
835 | "output_type": "display_data" | ||
836 | }, | ||
837 | { | ||
838 | "data": { | ||
839 | "text/plain": [ | ||
840 | "<function __main__.plot_out_degree(lines)>" | ||
841 | ] | ||
842 | }, | ||
843 | "execution_count": 82, | ||
844 | "metadata": {}, | ||
845 | "output_type": "execute_result" | ||
846 | } | ||
847 | ], | ||
848 | "source": [ | ||
849 | "def plot_out_degree(lines):\n", | ||
850 | " plot(random_emf_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out_degree', '../output/random_emf_instantiator/')\n", | ||
851 | "interact(plot_out_degree, lines=w)" | ||
852 | ] | ||
853 | }, | ||
854 | { | ||
855 | "cell_type": "code", | ||
856 | "execution_count": 83, | ||
857 | "metadata": {}, | ||
858 | "outputs": [ | ||
859 | { | ||
860 | "data": { | ||
861 | "application/vnd.jupyter.widget-view+json": { | ||
862 | "model_id": "0ba621dd0e7d4957aaff2cf209bba165", | ||
863 | "version_major": 2, | ||
864 | "version_minor": 0 | ||
865 | }, | ||
866 | "text/plain": [ | ||
867 | "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" | ||
868 | ] | ||
869 | }, | ||
870 | "metadata": {}, | ||
871 | "output_type": "display_data" | ||
872 | }, | ||
873 | { | ||
874 | "data": { | ||
875 | "text/plain": [ | ||
876 | "<function __main__.plot_na(lines)>" | ||
877 | ] | ||
878 | }, | ||
879 | "execution_count": 83, | ||
880 | "metadata": {}, | ||
881 | "output_type": "execute_result" | ||
882 | } | ||
883 | ], | ||
884 | "source": [ | ||
885 | "def plot_na(lines):\n", | ||
886 | " plot(random_emf_dic, lines, 0, lambda a: a.na_distance, colors, 'Node Activity', '../output/random_emf_instantiator/')\n", | ||
887 | "interact(plot_na, lines=w)" | ||
888 | ] | ||
889 | }, | ||
890 | { | ||
891 | "cell_type": "code", | ||
892 | "execution_count": 84, | ||
893 | "metadata": {}, | ||
894 | "outputs": [ | ||
895 | { | ||
896 | "data": { | ||
897 | "application/vnd.jupyter.widget-view+json": { | ||
898 | "model_id": "d432bbae1c6f48c3acd1767f2e2b13c7", | ||
899 | "version_major": 2, | ||
900 | "version_minor": 0 | ||
901 | }, | ||
902 | "text/plain": [ | ||
903 | "interactive(children=(SelectMultiple(description='Trajectory:', options={}, value=()), Output()), _dom_classes…" | ||
904 | ] | ||
905 | }, | ||
906 | "metadata": {}, | ||
907 | "output_type": "display_data" | ||
908 | }, | ||
909 | { | ||
910 | "data": { | ||
911 | "text/plain": [ | ||
912 | "<function __main__.plot_mpc(lines)>" | ||
913 | ] | ||
914 | }, | ||
915 | "execution_count": 84, | ||
916 | "metadata": {}, | ||
917 | "output_type": "execute_result" | ||
918 | } | ||
919 | ], | ||
920 | "source": [ | ||
921 | "def plot_mpc(lines):\n", | ||
922 | " plot(random_emf_dic, lines, 0, lambda a: a.mpc_distance, colors, 'mpc', '../output/random_emf_instantiator/')\n", | ||
923 | "interact(plot_mpc, lines=w)" | ||
924 | ] | ||
925 | }, | ||
926 | { | ||
927 | "cell_type": "code", | ||
928 | "execution_count": null, | ||
929 | "metadata": {}, | ||
930 | "outputs": [], | ||
931 | "source": [] | ||
932 | } | ||
933 | ], | ||
934 | "metadata": { | ||
935 | "kernelspec": { | ||
936 | "display_name": "Python 3", | ||
937 | "language": "python", | ||
938 | "name": "python3" | ||
939 | }, | ||
940 | "language_info": { | ||
941 | "codemirror_mode": { | ||
942 | "name": "ipython", | ||
943 | "version": 3 | ||
944 | }, | ||
945 | "file_extension": ".py", | ||
946 | "mimetype": "text/x-python", | ||
947 | "name": "python", | ||
948 | "nbconvert_exporter": "python", | ||
949 | "pygments_lexer": "ipython3", | ||
950 | "version": "3.7.3" | ||
951 | } | ||
952 | }, | ||
953 | "nbformat": 4, | ||
954 | "nbformat_minor": 2 | ||
955 | } | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/representative_selector .ipynb b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/representative_selector .ipynb new file mode 100644 index 00000000..9653b2a0 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model_evolve_comparison/src/representative_selector .ipynb | |||
@@ -0,0 +1,336 @@ | |||
1 | { | ||
2 | "cells": [ | ||
3 | { | ||
4 | "cell_type": "markdown", | ||
5 | "metadata": {}, | ||
6 | "source": [ | ||
7 | "## Use K-medoid algorithm to find the suitable human model representitives" | ||
8 | ] | ||
9 | }, | ||
10 | { | ||
11 | "cell_type": "markdown", | ||
12 | "metadata": {}, | ||
13 | "source": [ | ||
14 | "### Imports" | ||
15 | ] | ||
16 | }, | ||
17 | { | ||
18 | "cell_type": "code", | ||
19 | "execution_count": 1, | ||
20 | "metadata": {}, | ||
21 | "outputs": [], | ||
22 | "source": [ | ||
23 | "import os, sys\n", | ||
24 | "lib_path = os.path.abspath(os.path.join('..', '..', 'utils'))\n", | ||
25 | "sys.path.append(lib_path)\n", | ||
26 | "from GraphType import GraphStat\n", | ||
27 | "import readCSV as reader\n", | ||
28 | "from scipy import stats\n", | ||
29 | "from ipywidgets import interact, fixed, interactive\n", | ||
30 | "import ipywidgets as widgets\n", | ||
31 | "from pyclustering.cluster.kmedoids import kmedoids\n", | ||
32 | "from pyclustering.utils.metric import distance_metric, type_metric\n", | ||
33 | "import random" | ||
34 | ] | ||
35 | }, | ||
36 | { | ||
37 | "cell_type": "markdown", | ||
38 | "metadata": {}, | ||
39 | "source": [ | ||
40 | "### Define a new distance metric" | ||
41 | ] | ||
42 | }, | ||
43 | { | ||
44 | "cell_type": "code", | ||
45 | "execution_count": 2, | ||
46 | "metadata": {}, | ||
47 | "outputs": [], | ||
48 | "source": [ | ||
49 | "def ks_value(dest1, dest2):\n", | ||
50 | " value, p = stats.ks_2samp(dest1, dest2)\n", | ||
51 | " return value\n", | ||
52 | "\n", | ||
53 | "\n", | ||
54 | "ks_metric = distance_metric(type_metric.USER_DEFINED, func=ks_value)" | ||
55 | ] | ||
56 | }, | ||
57 | { | ||
58 | "cell_type": "markdown", | ||
59 | "metadata": {}, | ||
60 | "source": [ | ||
61 | "### Read Human Models" | ||
62 | ] | ||
63 | }, | ||
64 | { | ||
65 | "cell_type": "code", | ||
66 | "execution_count": 4, | ||
67 | "metadata": {}, | ||
68 | "outputs": [ | ||
69 | { | ||
70 | "data": { | ||
71 | "text/plain": [ | ||
72 | "1253" | ||
73 | ] | ||
74 | }, | ||
75 | "execution_count": 4, | ||
76 | "metadata": {}, | ||
77 | "output_type": "execute_result" | ||
78 | } | ||
79 | ], | ||
80 | "source": [ | ||
81 | "# Progress Widge\n", | ||
82 | "w = widgets.FloatProgress(\n", | ||
83 | " value=0,\n", | ||
84 | " min=0,\n", | ||
85 | " max=1.0,\n", | ||
86 | " step=0.1,\n", | ||
87 | " description='Loading Files...:',\n", | ||
88 | " bar_style='info',\n", | ||
89 | " orientation='horizontal'\n", | ||
90 | ")\n", | ||
91 | "\n", | ||
92 | "\n", | ||
93 | "humanFiles = reader.readmultiplefiles('../input/humanOutput/', 1300, False)\n", | ||
94 | "modelToFileName = {}\n", | ||
95 | "for name in humanFiles:\n", | ||
96 | " modelToFileName[GraphStat(name)] = name\n", | ||
97 | "\n", | ||
98 | "models = list(modelToFileName.keys())\n", | ||
99 | "len(humanFiles)" | ||
100 | ] | ||
101 | }, | ||
102 | { | ||
103 | "cell_type": "markdown", | ||
104 | "metadata": {}, | ||
105 | "source": [ | ||
106 | "### Find Representative by K-medroid for different dists on GraphStat" | ||
107 | ] | ||
108 | }, | ||
109 | { | ||
110 | "cell_type": "markdown", | ||
111 | "metadata": {}, | ||
112 | "source": [ | ||
113 | "* Returns the index of the representative" | ||
114 | ] | ||
115 | }, | ||
116 | { | ||
117 | "cell_type": "code", | ||
118 | "execution_count": 5, | ||
119 | "metadata": {}, | ||
120 | "outputs": [], | ||
121 | "source": [ | ||
122 | "def findRep(graphStats, func):\n", | ||
123 | " out_ds = list(map(func, models))\n", | ||
124 | "\n", | ||
125 | " #choose a random starting point\n", | ||
126 | " start_index = random.randint(0, len(out_ds))\n", | ||
127 | "\n", | ||
128 | " # start with one initial metrid [start_index]\n", | ||
129 | " outdegree_kmedoid = kmedoids(out_ds, [start_index], metric=ks_metric)\n", | ||
130 | "\n", | ||
131 | " outdegree_kmedoid.process()\n", | ||
132 | " centoids = outdegree_kmedoid.get_medoids()\n", | ||
133 | " return centoids[0]" | ||
134 | ] | ||
135 | }, | ||
136 | { | ||
137 | "cell_type": "markdown", | ||
138 | "metadata": {}, | ||
139 | "source": [ | ||
140 | "### Find representative for out degree" | ||
141 | ] | ||
142 | }, | ||
143 | { | ||
144 | "cell_type": "markdown", | ||
145 | "metadata": {}, | ||
146 | "source": [ | ||
147 | "* the rep found is ../input/humanOutput\\R_20158_run_1.csv\n", | ||
148 | "* the average distance between it and others is 0.05515988287586802" | ||
149 | ] | ||
150 | }, | ||
151 | { | ||
152 | "cell_type": "code", | ||
153 | "execution_count": 6, | ||
154 | "metadata": {}, | ||
155 | "outputs": [ | ||
156 | { | ||
157 | "name": "stdout", | ||
158 | "output_type": "stream", | ||
159 | "text": [ | ||
160 | "../input/humanOutput\\R_20158_run_1.csv\n", | ||
161 | "../input/humanOutput\\R_20158_run_1.csv\n" | ||
162 | ] | ||
163 | } | ||
164 | ], | ||
165 | "source": [ | ||
166 | "od_rep_index = findRep(models, lambda m: m.out_d)\n", | ||
167 | "print(list(modelToFileName.values())[od_rep_index])\n", | ||
168 | "od_rep_model = models[od_rep_index]\n", | ||
169 | "print(modelToFileName[od_rep_model])\n" | ||
170 | ] | ||
171 | }, | ||
172 | { | ||
173 | "cell_type": "code", | ||
174 | "execution_count": 19, | ||
175 | "metadata": {}, | ||
176 | "outputs": [ | ||
177 | { | ||
178 | "name": "stdout", | ||
179 | "output_type": "stream", | ||
180 | "text": [ | ||
181 | "0.05515988287586802\n" | ||
182 | ] | ||
183 | } | ||
184 | ], | ||
185 | "source": [ | ||
186 | "total_distance = 0\n", | ||
187 | "count = 0\n", | ||
188 | "for model in models:\n", | ||
189 | " total_distance += ks_value(od_rep_model.out_d, model.out_d)\n", | ||
190 | "print(total_distance / len(models))" | ||
191 | ] | ||
192 | }, | ||
193 | { | ||
194 | "cell_type": "markdown", | ||
195 | "metadata": {}, | ||
196 | "source": [ | ||
197 | "### Find Representative for node activities" | ||
198 | ] | ||
199 | }, | ||
200 | { | ||
201 | "cell_type": "markdown", | ||
202 | "metadata": {}, | ||
203 | "source": [ | ||
204 | "* the rep found is ../input/humanOutput\\R_2016176_run_1.csv\n", | ||
205 | "* the average distance between it and others is 0.05275267434589047" | ||
206 | ] | ||
207 | }, | ||
208 | { | ||
209 | "cell_type": "code", | ||
210 | "execution_count": 7, | ||
211 | "metadata": {}, | ||
212 | "outputs": [ | ||
213 | { | ||
214 | "name": "stdout", | ||
215 | "output_type": "stream", | ||
216 | "text": [ | ||
217 | "../input/humanOutput\\R_2016176_run_1.csv\n", | ||
218 | "../input/humanOutput\\R_2016176_run_1.csv\n" | ||
219 | ] | ||
220 | } | ||
221 | ], | ||
222 | "source": [ | ||
223 | "total_distance = 0\n", | ||
224 | "for model in models:\n", | ||
225 | " total_distance += ks_value(od_rep_model.mpc, model.mpc)\n", | ||
226 | "print(total_distance / len(models))" | ||
227 | ] | ||
228 | }, | ||
229 | { | ||
230 | "cell_type": "code", | ||
231 | "execution_count": 18, | ||
232 | "metadata": {}, | ||
233 | "outputs": [ | ||
234 | { | ||
235 | "name": "stdout", | ||
236 | "output_type": "stream", | ||
237 | "text": [ | ||
238 | "0.05275267434589047\n" | ||
239 | ] | ||
240 | } | ||
241 | ], | ||
242 | "source": [ | ||
243 | "total_distance = 0\n", | ||
244 | "count = 0\n", | ||
245 | "for model in models:\n", | ||
246 | " total_distance += ks_value(od_rep_model.na, model.na)\n", | ||
247 | "print(total_distance / len(models))" | ||
248 | ] | ||
249 | }, | ||
250 | { | ||
251 | "cell_type": "markdown", | ||
252 | "metadata": {}, | ||
253 | "source": [ | ||
254 | "### Find Representative for MPC" | ||
255 | ] | ||
256 | }, | ||
257 | { | ||
258 | "cell_type": "markdown", | ||
259 | "metadata": {}, | ||
260 | "source": [ | ||
261 | "* the rep found is ../input/humanOutput\\R_2015246_run_1.csv\n", | ||
262 | "* the average distance between it and others is 0.08556632702185384" | ||
263 | ] | ||
264 | }, | ||
265 | { | ||
266 | "cell_type": "code", | ||
267 | "execution_count": 8, | ||
268 | "metadata": {}, | ||
269 | "outputs": [ | ||
270 | { | ||
271 | "name": "stdout", | ||
272 | "output_type": "stream", | ||
273 | "text": [ | ||
274 | "../input/humanOutput\\R_2015246_run_1.csv\n", | ||
275 | "../input/humanOutput\\R_2015246_run_1.csv\n" | ||
276 | ] | ||
277 | } | ||
278 | ], | ||
279 | "source": [ | ||
280 | "mpc_rep_index = findRep(models, lambda m: m.mpc)\n", | ||
281 | "print(list(modelToFileName.values())[mpc_rep_index])\n", | ||
282 | "mpc_rep_model = models[mpc_rep_index]\n", | ||
283 | "print(modelToFileName[mpc_rep_model])" | ||
284 | ] | ||
285 | }, | ||
286 | { | ||
287 | "cell_type": "code", | ||
288 | "execution_count": 20, | ||
289 | "metadata": {}, | ||
290 | "outputs": [ | ||
291 | { | ||
292 | "name": "stdout", | ||
293 | "output_type": "stream", | ||
294 | "text": [ | ||
295 | "0.08556632702185384\n" | ||
296 | ] | ||
297 | } | ||
298 | ], | ||
299 | "source": [ | ||
300 | "total_distance = 0\n", | ||
301 | "count = 0\n", | ||
302 | "for model in models:\n", | ||
303 | " total_distance += ks_value(od_rep_model.mpc, model.mpc)\n", | ||
304 | "print(total_distance / len(models))" | ||
305 | ] | ||
306 | }, | ||
307 | { | ||
308 | "cell_type": "code", | ||
309 | "execution_count": null, | ||
310 | "metadata": {}, | ||
311 | "outputs": [], | ||
312 | "source": [] | ||
313 | } | ||
314 | ], | ||
315 | "metadata": { | ||
316 | "kernelspec": { | ||
317 | "display_name": "Python 3", | ||
318 | "language": "python", | ||
319 | "name": "python3" | ||
320 | }, | ||
321 | "language_info": { | ||
322 | "codemirror_mode": { | ||
323 | "name": "ipython", | ||
324 | "version": 3 | ||
325 | }, | ||
326 | "file_extension": ".py", | ||
327 | "mimetype": "text/x-python", | ||
328 | "name": "python", | ||
329 | "nbconvert_exporter": "python", | ||
330 | "pygments_lexer": "ipython3", | ||
331 | "version": "3.7.3" | ||
332 | } | ||
333 | }, | ||
334 | "nbformat": 4, | ||
335 | "nbformat_minor": 2 | ||
336 | } | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/utils/GraphType.py b/Metrics/Metrics-Calculation/metrics_plot/utils/GraphType.py new file mode 100644 index 00000000..13754e80 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/utils/GraphType.py | |||
@@ -0,0 +1,29 @@ | |||
1 | import readCSV as reader | ||
2 | import constants | ||
3 | import numpy as np | ||
4 | |||
5 | # graph stats for a collection of graphs | ||
6 | class GraphCollection: | ||
7 | |||
8 | # init with path contrain files and number of files to read reader is imported from (readCSV) | ||
9 | def __init__(self, path, number, name, shouldShuffle = True): | ||
10 | self.out_ds = [] | ||
11 | self.nas = [] | ||
12 | self.mpcs = [] | ||
13 | self.name = name | ||
14 | models = reader.readmultiplefiles(path, number, shouldShuffle) | ||
15 | for i in range(len(models)): | ||
16 | contents, out_d, na, mpc = reader.getmetrics(models[i]) | ||
17 | self.out_ds.append(out_d) | ||
18 | self.nas.append(na) | ||
19 | self.mpcs.append(mpc) | ||
20 | print(len(self.out_ds)) | ||
21 | |||
22 | #Graph stat for one graph | ||
23 | class GraphStat: | ||
24 | # init with teh file name of the stat | ||
25 | def __init__(self, filename): | ||
26 | contents, self.out_d, self.na, self.mpc = reader.getmetrics(filename) | ||
27 | self.num_nodes = np.array(contents[constants.NUMBER_NODES]) | ||
28 | if constants.STATE_ID in contents: | ||
29 | self.id = (contents[constants.STATE_ID])[0] | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/utils/constants.py b/Metrics/Metrics-Calculation/metrics_plot/utils/constants.py new file mode 100644 index 00000000..ce9d4255 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/utils/constants.py | |||
@@ -0,0 +1,25 @@ | |||
1 | NUMBER_EDGE_TYPES = 'Number of Edge types' | ||
2 | |||
3 | NUMBER_NODES = 'Number Of Nodes' | ||
4 | |||
5 | OUT_DEGREE_COUNT = 'OutDegreeCount' | ||
6 | |||
7 | OUT_DEGREE_VALUE = 'OutDegreeValue' | ||
8 | |||
9 | NA_COUNT = 'NACount' | ||
10 | |||
11 | NA_VALUE = 'NAValue' | ||
12 | |||
13 | MPC_VALUE = 'MPCValue' | ||
14 | |||
15 | MPC_COUNT = 'MPCCount' | ||
16 | |||
17 | METAMODEL = 'Meta Mode' | ||
18 | |||
19 | STATE_ID = 'State Id' | ||
20 | |||
21 | HUMAN_OUT_D_REP = '../input/humanOutput/R_20158_run_1.csv' | ||
22 | |||
23 | HUMAN_MPC_REP = '../input/humanOutput/R_2015246_run_1.csv' | ||
24 | |||
25 | HUMAN_NA_REP = '../input/humanOutput/R_2016176_run_1.csv' | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/utils/readCSV.py b/Metrics/Metrics-Calculation/metrics_plot/utils/readCSV.py new file mode 100644 index 00000000..e0402519 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/utils/readCSV.py | |||
@@ -0,0 +1,169 @@ | |||
1 | import numpy as np | ||
2 | import matplotlib.pyplot as plt | ||
3 | from scipy import stats | ||
4 | import glob | ||
5 | import random | ||
6 | import constants | ||
7 | |||
8 | # | ||
9 | # read csvfile returns outdegree, node activity, mpc | ||
10 | # as matrix with the first row of values and second row of count | ||
11 | # | ||
12 | def readcsvfile(filename): | ||
13 | |||
14 | contents = {} | ||
15 | with open(filename) as f: | ||
16 | for i, line in enumerate(f): | ||
17 | arr = line.split(',') | ||
18 | # if there is no element in the line, continue | ||
19 | if len(line) < 0: continue | ||
20 | # else check for contents | ||
21 | # if it is MPC then use float | ||
22 | if arr[0] == constants.MPC_VALUE: | ||
23 | contents[constants.MPC_VALUE] = list(map(float, arr[1:])) | ||
24 | # meta models are string | ||
25 | elif(arr[0] == constants.METAMODEL): | ||
26 | contents[constants.METAMODEL] = arr[1:] | ||
27 | # all other contants are integer | ||
28 | else: | ||
29 | contents[arr[0]] = list(map(int, arr[1:])) | ||
30 | f.close() | ||
31 | return contents | ||
32 | |||
33 | def checkAndReshape(arr): | ||
34 | if len(arr.shape) < 2: | ||
35 | arr = np.reshape(arr, (arr.shape[0],1)) | ||
36 | return arr | ||
37 | |||
38 | def readTrajectory(filename): | ||
39 | state_codes = [] | ||
40 | with open(filename) as f: | ||
41 | for i, line in enumerate(f): | ||
42 | if(line == ''): continue | ||
43 | state_codes.append(int(line)) | ||
44 | return state_codes | ||
45 | # | ||
46 | # take a matrix as input | ||
47 | # return the sample array | ||
48 | # | ||
49 | def getsample(dataMatrix): | ||
50 | data = [] | ||
51 | value = dataMatrix[0, :] | ||
52 | count = dataMatrix[1, :] | ||
53 | for i, v in enumerate(value): | ||
54 | for x in range(0, int(count[i])): | ||
55 | data.append(v) | ||
56 | return data | ||
57 | |||
58 | def reproduceSample(values, counts): | ||
59 | arr = np.array([values, counts]) | ||
60 | return getsample(arr) | ||
61 | |||
62 | # | ||
63 | # take an array of filenames as input | ||
64 | # return the samples of outdegree, na, mpc | ||
65 | # | ||
66 | def getmetrics(filename): | ||
67 | contents = readcsvfile(filename) | ||
68 | outdegree_sample = reproduceSample(contents[constants.OUT_DEGREE_VALUE], contents[constants.OUT_DEGREE_COUNT]) | ||
69 | na_sample = reproduceSample(contents[constants.NA_VALUE], contents[constants.NA_COUNT]) | ||
70 | mpc_sample = reproduceSample(contents[constants.MPC_VALUE], contents[constants.MPC_COUNT]) | ||
71 | return contents,outdegree_sample, na_sample, mpc_sample | ||
72 | |||
73 | # | ||
74 | # read number of files in the given path RANDOMLY | ||
75 | # | ||
76 | def readmultiplefiles(dirName, maxNumberOfFiles, shouldShuffle = True): | ||
77 | list_of_files = glob.glob(dirName + '*.csv') # create the list of file | ||
78 | if shouldShuffle: | ||
79 | random.shuffle(list_of_files) | ||
80 | #if the number of files is out of bound then just give the whole list | ||
81 | file_names = list_of_files[:maxNumberOfFiles] | ||
82 | # print(file_names) | ||
83 | return file_names | ||
84 | |||
85 | |||
86 | def plotlines(x, y, ax): | ||
87 | l1, = ax.plot(x, y) | ||
88 | |||
89 | |||
90 | def testgetsamplesfromfiles(): | ||
91 | files = readmultiplefiles('../statistics/viatraOutput/', 2) | ||
92 | for file in files: | ||
93 | getmetrics(file) | ||
94 | |||
95 | def probability(data): | ||
96 | sum = np.sum(data) | ||
97 | probabilityList = [] | ||
98 | for d in data: | ||
99 | p = d/sum | ||
100 | probabilityList.append(p) | ||
101 | a = np.array(probabilityList) | ||
102 | return a | ||
103 | |||
104 | |||
105 | def cumulativeProbability(p): | ||
106 | cdf = np.cumsum(p) | ||
107 | return cdf | ||
108 | |||
109 | |||
110 | def plot(): | ||
111 | fig, ax = plt.subplots() | ||
112 | fig, ax1 = plt.subplots() | ||
113 | fig, ax2 = plt.subplots() | ||
114 | fig, ax3 = plt.subplots() | ||
115 | fig, ax4 = plt.subplots() | ||
116 | fig, ax5 = plt.subplots() | ||
117 | list_of_files = readmultiplefiles('../statistics/iatraOutput/') | ||
118 | for file_name in list_of_files: | ||
119 | contents = readcsvfile(file_name) | ||
120 | outdegree = [contents[constants.OUT_DEGREE_VALUE], contents[constants.OUT_DEGREE_COUNT]] | ||
121 | na = [contents[constants.NA_VALUE], contents[constants.NA_COUNT]] | ||
122 | mpc = [contents[constants.MPC_VALUE], contents[constants.MPC_COUNT]] | ||
123 | outV = outdegree[0, :] | ||
124 | outC = outdegree[1, :] | ||
125 | outP = probability(outC) | ||
126 | outCumP = cumulativeProbability(outP) | ||
127 | plotlines(outV, outP, ax) | ||
128 | naV = na[0, :] | ||
129 | naC = na[1, :] | ||
130 | naP = probability(naC) | ||
131 | naCumP = cumulativeProbability(naP) | ||
132 | plotlines(naV, naP, ax1) | ||
133 | mpcV = mpc[0, :] | ||
134 | mpcC = mpc[1, :] | ||
135 | mpcP = probability(mpcC) | ||
136 | mpcCumP = cumulativeProbability(mpcP) | ||
137 | plotlines(mpcV, mpcP, ax2) | ||
138 | plotlines(outV, outCumP, ax3) | ||
139 | plotlines(naV, naCumP, ax4) | ||
140 | plotlines(mpcV, mpcCumP, ax5) | ||
141 | ax.set_xlabel('ourdegree') | ||
142 | ax.set_ylabel('pdf') | ||
143 | ax.grid() | ||
144 | |||
145 | ax1.set_xlabel('node activity') | ||
146 | ax1.set_ylabel('pdf') | ||
147 | ax1.grid() | ||
148 | |||
149 | ax2.set_xlabel('multiplex participation coefficient') | ||
150 | ax2.set_ylabel('pdf') | ||
151 | ax2.grid() | ||
152 | |||
153 | ax3.set_xlabel('ourdegree') | ||
154 | ax3.set_ylabel('cdf') | ||
155 | ax3.grid() | ||
156 | |||
157 | ax4.set_xlabel('node activity') | ||
158 | ax4.set_ylabel('cdf') | ||
159 | ax4.grid() | ||
160 | |||
161 | ax5.set_xlabel('multiplex participation coefficient') | ||
162 | ax5.set_ylabel('cdf') | ||
163 | ax5.grid() | ||
164 | |||
165 | plt.show() | ||
166 | |||
167 | |||
168 | # plot() | ||
169 | |||