diff options
Diffstat (limited to 'Metrics/Metrics-Calculation')
27 files changed, 686 insertions, 237 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 index 428337e5..f4f8357b 100644 --- a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/.classpath +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/.classpath | |||
@@ -4,5 +4,7 @@ | |||
4 | <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | 4 | <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> |
5 | <classpathentry kind="src" path="src"/> | 5 | <classpathentry kind="src" path="src"/> |
6 | <classpathentry kind="src" path="xtend-gen"/> | 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"/> | ||
7 | <classpathentry kind="output" path="bin"/> | 9 | <classpathentry kind="output" path="bin"/> |
8 | </classpath> | 10 | </classpath> |
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 index 15df0dde..cf871ead 100644 --- 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 | |||
@@ -1,8 +1,8 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app | 1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app |
2 | 2 | ||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.EMFGraph | 3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.EMFGraph |
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.input.GraphReader | 4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io.CsvFileWriter |
5 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.output.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 | 6 | import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.impl.YakindummPackageImpl |
7 | import java.util.ArrayList | 7 | import java.util.ArrayList |
8 | 8 | ||
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 index 0e505d30..cdd06027 100644 --- 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 | |||
@@ -1,11 +1,12 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app | 1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app |
2 | 2 | ||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.distance.KSDistance | ||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.PartialInterpretationGraph | 4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.PartialInterpretationGraph |
5 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io.CsvFileWriter | ||
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric | 6 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric |
5 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MultiplexParticipationCoefficientMetric | 7 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MultiplexParticipationCoefficientMetric |
6 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.NodeActivityMetric | 8 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.NodeActivityMetric |
7 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.OutDegreeMetric | 9 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.OutDegreeMetric |
8 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.output.CsvFileWriter | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | 10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation |
10 | import java.io.File | 11 | import java.io.File |
11 | import java.io.FileNotFoundException | 12 | import java.io.FileNotFoundException |
@@ -17,10 +18,28 @@ import org.eclipse.viatra.dse.api.Solution | |||
17 | 18 | ||
18 | class PartialInterpretationMetric { | 19 | class PartialInterpretationMetric { |
19 | var static state = 0; | 20 | var static state = 0; |
21 | var static KSDistance ks; | ||
20 | 22 | ||
21 | def static void initPaths(){ | 23 | def static void initPaths(){ |
22 | new File("debug/metric/").mkdir(); | 24 | new File("debug/metric/").mkdir(); |
23 | new File("debug/metric/trajectories/").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); | ||
24 | } | 43 | } |
25 | 44 | ||
26 | // calculate the metrics for a state | 45 | // calculate the metrics for a state |
@@ -78,4 +97,28 @@ class PartialInterpretationMetric { | |||
78 | } | 97 | } |
79 | } | 98 | } |
80 | } | 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 | } | ||
81 | } \ No newline at end of file | 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/Graph.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/Graph.xtend index 6d65367f..cf4aedba 100644 --- 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 | |||
@@ -1,8 +1,12 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph | 1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph |
2 | 2 | ||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric | 3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric |
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MetricSampleGroup | ||
4 | import java.util.ArrayList | 5 | import java.util.ArrayList |
5 | import java.util.List | 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 | ||
6 | 10 | ||
7 | abstract class Graph { | 11 | abstract class Graph { |
8 | 12 | ||
@@ -33,6 +37,22 @@ abstract class Graph { | |||
33 | return result; | 37 | return result; |
34 | } | 38 | } |
35 | 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 | |||
36 | def void setBasicInformation(ArrayList<ArrayList<String>> result); | 56 | def void setBasicInformation(ArrayList<ArrayList<String>> result); |
37 | 57 | ||
38 | def GraphStatistic getStatistic(); | 58 | def GraphStatistic getStatistic(); |
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/input/PartialInterpretationReader.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/input/PartialInterpretationReader.xtend deleted file mode 100644 index dbaf36b2..00000000 --- a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/input/PartialInterpretationReader.xtend +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.input | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
4 | |||
5 | class PartialInterpretationReader { | ||
6 | |||
7 | } \ 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/output/CsvFileWriter.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/CsvFileWriter.xtend index 1dd204a0..bed356e9 100644 --- a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/output/CsvFileWriter.xtend +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/CsvFileWriter.xtend | |||
@@ -1,4 +1,4 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.output; | 1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io; |
2 | 2 | ||
3 | import java.io.File | 3 | import java.io.File |
4 | import java.io.FileNotFoundException | 4 | import java.io.FileNotFoundException |
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/input/GraphReader.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.xtend index 56bf95a3..fc56e142 100644 --- a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/input/GraphReader.xtend +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/io/GraphReader.xtend | |||
@@ -1,4 +1,4 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.input | 1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io; |
2 | 2 | ||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.EMFGraph | 3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.EMFGraph |
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric | 4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric |
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 index ea52009a..38ef72f2 100644 --- 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 | |||
@@ -4,4 +4,5 @@ import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatis | |||
4 | 4 | ||
5 | abstract class Metric { | 5 | abstract class Metric { |
6 | abstract def String[][] evaluate(GraphStatistic g); | 6 | abstract def String[][] evaluate(GraphStatistic g); |
7 | abstract def double[] evaluateSamples(GraphStatistic g); | ||
7 | } \ No newline at end of file | 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 index 7bd48754..d9c88bb4 100644 --- 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 | |||
@@ -2,11 +2,13 @@ package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics | |||
2 | 2 | ||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic | 3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic |
4 | import java.text.DecimalFormat | 4 | import java.text.DecimalFormat |
5 | import java.util.ArrayList | ||
5 | import java.util.HashMap | 6 | import java.util.HashMap |
7 | import org.eclipse.emf.ecore.EObject | ||
6 | 8 | ||
7 | class MultiplexParticipationCoefficientMetric extends Metric { | 9 | class MultiplexParticipationCoefficientMetric extends Metric { |
8 | static val countName = "MPCCount"; | 10 | public static val countName = "MPCCount"; |
9 | static val valueName = "MPCValue"; | 11 | public static val valueName = "MPCValue"; |
10 | 12 | ||
11 | 13 | ||
12 | override evaluate(GraphStatistic g) { | 14 | override evaluate(GraphStatistic g) { |
@@ -18,26 +20,7 @@ class MultiplexParticipationCoefficientMetric extends Metric { | |||
18 | val map = new HashMap<String, Integer>(); | 20 | val map = new HashMap<String, Integer>(); |
19 | //calculate the metric distribution | 21 | //calculate the metric distribution |
20 | g.allNodes.forEach[n| | 22 | g.allNodes.forEach[n| |
21 | val edgeCounts = g.outDegree(n) + g.inDegree(n); | 23 | var coef = calculateMPC(n, g, typeCounts); |
22 | |||
23 | var coef = 0.0; | ||
24 | |||
25 | for(type : g.allTypes){ | ||
26 | val degree = g.dimentionalDegree(n, type) as double; | ||
27 | coef += Math.pow(degree / edgeCounts, 2); | ||
28 | } | ||
29 | coef = 1 - coef; | ||
30 | coef = coef * typeCounts / (typeCounts-1); | ||
31 | |||
32 | //Consider the case that either typeCounts-1 or the edgeCounts could be 0 in some situation | ||
33 | //in this case the metric should be evaluated to 0 | ||
34 | if(typeCounts == 1){ | ||
35 | println("bad"); | ||
36 | } | ||
37 | |||
38 | if(Double.isNaN(coef)){ | ||
39 | coef = 0; | ||
40 | } | ||
41 | 24 | ||
42 | //format number to String | 25 | //format number to String |
43 | val value = formatter.format(coef); | 26 | val value = formatter.format(coef); |
@@ -62,4 +45,36 @@ class MultiplexParticipationCoefficientMetric extends Metric { | |||
62 | 45 | ||
63 | return datas; | 46 | return datas; |
64 | } | 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 | } | ||
65 | } \ No newline at end of file | 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 index 297bdd14..fbf06c47 100644 --- 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 | |||
@@ -1,11 +1,12 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics | 1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics |
2 | 2 | ||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic | 3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic |
4 | import java.util.ArrayList | ||
4 | import java.util.HashMap | 5 | import java.util.HashMap |
5 | 6 | ||
6 | class NodeActivityMetric extends Metric { | 7 | class NodeActivityMetric extends Metric { |
7 | static val countName = "NACount"; | 8 | public static val countName = "NACount"; |
8 | static val valueName = "NAValue"; | 9 | public static val valueName = "NAValue"; |
9 | 10 | ||
10 | override evaluate(GraphStatistic g) { | 11 | override evaluate(GraphStatistic g) { |
11 | val map = new HashMap<Integer, Integer>(); | 12 | val map = new HashMap<Integer, Integer>(); |
@@ -34,4 +35,15 @@ class NodeActivityMetric extends Metric { | |||
34 | 35 | ||
35 | return datas; | 36 | return datas; |
36 | } | 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 | } | ||
37 | } \ No newline at end of file | 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 index 1ba6c8c7..55046b14 100644 --- 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 | |||
@@ -1,11 +1,12 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics | 1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics |
2 | 2 | ||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic | 3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic |
4 | import java.util.ArrayList | ||
4 | import java.util.HashMap | 5 | import java.util.HashMap |
5 | 6 | ||
6 | class OutDegreeMetric extends Metric { | 7 | class OutDegreeMetric extends Metric { |
7 | static val countName = "OutDegreeCount"; | 8 | public static val countName = "OutDegreeCount"; |
8 | static val valueName = "OutDegreeValue"; | 9 | public static val valueName = "OutDegreeValue"; |
9 | 10 | ||
10 | override evaluate(GraphStatistic g) { | 11 | override evaluate(GraphStatistic g) { |
11 | val map = new HashMap<Integer, Integer>(); | 12 | val map = new HashMap<Integer, Integer>(); |
@@ -34,5 +35,15 @@ class OutDegreeMetric extends Metric { | |||
34 | return datas; | 35 | return datas; |
35 | } | 36 | } |
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 | } | ||
37 | 48 | ||
38 | } \ No newline at end of file | 49 | } \ 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)-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/MPC.png new file mode 100644 index 00000000..e660f3da --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/MPC.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Node Activity.png new file mode 100644 index 00000000..92047e47 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Node Activity.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Out Degree.png new file mode 100644 index 00000000..dad7483f --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/output/Human-Viatra (30 nodes)-/Out Degree.png | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py b/Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py new file mode 100644 index 00000000..2f39ca93 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/model comparison/src/plot_ks_stats.py | |||
@@ -0,0 +1,98 @@ | |||
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/output/Human-viatraEvolve-/MPC.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/MPC.png deleted file mode 100644 index d819aad5..00000000 --- a/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/MPC.png +++ /dev/null | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/Node Activity.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/Node Activity.png deleted file mode 100644 index 4b3b187e..00000000 --- a/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/Node Activity.png +++ /dev/null | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/Out Degree.png b/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/Out Degree.png deleted file mode 100644 index d8e01f6e..00000000 --- a/Metrics/Metrics-Calculation/metrics_plot/output/Human-viatraEvolve-/Out Degree.png +++ /dev/null | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance_with_selector.ipynb b/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance_with_selector.ipynb index 8c57a327..a0b0ad8d 100644 --- a/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance_with_selector.ipynb +++ b/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance_with_selector.ipynb | |||
@@ -108,7 +108,7 @@ | |||
108 | }, | 108 | }, |
109 | { | 109 | { |
110 | "cell_type": "code", | 110 | "cell_type": "code", |
111 | "execution_count": 20, | 111 | "execution_count": 4, |
112 | "metadata": {}, | 112 | "metadata": {}, |
113 | "outputs": [], | 113 | "outputs": [], |
114 | "source": [ | 114 | "source": [ |
@@ -184,7 +184,7 @@ | |||
184 | }, | 184 | }, |
185 | { | 185 | { |
186 | "cell_type": "code", | 186 | "cell_type": "code", |
187 | "execution_count": 8, | 187 | "execution_count": 9, |
188 | "metadata": {}, | 188 | "metadata": {}, |
189 | "outputs": [], | 189 | "outputs": [], |
190 | "source": [ | 190 | "source": [ |
@@ -201,8 +201,7 @@ | |||
201 | "viatra_no_con_stats = readStats('../statistics/viatra_nocon_output/', 5000)\n", | 201 | "viatra_no_con_stats = readStats('../statistics/viatra_nocon_output/', 5000)\n", |
202 | "viatra_con_stats = readStats('../statistics/viatra_con_output/',5000)\n", | 202 | "viatra_con_stats = readStats('../statistics/viatra_con_output/',5000)\n", |
203 | "random_stats = readStats('../statistics/random_output/',5000)\n", | 203 | "random_stats = readStats('../statistics/random_output/',5000)\n", |
204 | "real_random_stats = readStats('../statistics/real_random_output/', 10000)\n", | 204 | "con_viatra_stats = readStats('../statistics/controled_viatra/',300)" |
205 | "viatra_500_stats = readStats('../statistics/viatra500nodes/', 10000)" | ||
206 | ] | 205 | ] |
207 | }, | 206 | }, |
208 | { | 207 | { |
@@ -214,20 +213,19 @@ | |||
214 | }, | 213 | }, |
215 | { | 214 | { |
216 | "cell_type": "code", | 215 | "cell_type": "code", |
217 | "execution_count": 9, | 216 | "execution_count": 10, |
218 | "metadata": {}, | 217 | "metadata": {}, |
219 | "outputs": [], | 218 | "outputs": [], |
220 | "source": [ | 219 | "source": [ |
221 | "viatra_no_con_dic = calDistanceDic(viatra_no_con_stats, human_rep)\n", | 220 | "viatra_no_con_dic = calDistanceDic(viatra_no_con_stats, human_rep)\n", |
222 | "viatra_con_dic = calDistanceDic(viatra_con_stats, human_rep)\n", | 221 | "viatra_con_dic = calDistanceDic(viatra_con_stats, human_rep)\n", |
223 | "random_dic = calDistanceDic(random_stats, human_rep)\n", | 222 | "random_dic = calDistanceDic(random_stats, human_rep)\n", |
224 | "real_random_dic = calDistanceDic(real_random_stats, human_rep)\n", | 223 | "con_viatra_dic = calDistanceDic(con_viatra_stats, human_rep)" |
225 | "viatra_500_dic = calDistanceDic(viatra_500_stats, human_rep)" | ||
226 | ] | 224 | ] |
227 | }, | 225 | }, |
228 | { | 226 | { |
229 | "cell_type": "code", | 227 | "cell_type": "code", |
230 | "execution_count": 30, | 228 | "execution_count": 11, |
231 | "metadata": {}, | 229 | "metadata": {}, |
232 | "outputs": [], | 230 | "outputs": [], |
233 | "source": [ | 231 | "source": [ |
@@ -253,13 +251,13 @@ | |||
253 | }, | 251 | }, |
254 | { | 252 | { |
255 | "cell_type": "code", | 253 | "cell_type": "code", |
256 | "execution_count": 31, | 254 | "execution_count": 12, |
257 | "metadata": {}, | 255 | "metadata": {}, |
258 | "outputs": [ | 256 | "outputs": [ |
259 | { | 257 | { |
260 | "data": { | 258 | "data": { |
261 | "application/vnd.jupyter.widget-view+json": { | 259 | "application/vnd.jupyter.widget-view+json": { |
262 | "model_id": "cba63d8050a043018a16db6f1a0440f9", | 260 | "model_id": "868a437468d24144926f1390cbf2acb8", |
263 | "version_major": 2, | 261 | "version_major": 2, |
264 | "version_minor": 0 | 262 | "version_minor": 0 |
265 | }, | 263 | }, |
@@ -276,7 +274,7 @@ | |||
276 | "<function __main__.plot_out_degree(lines)>" | 274 | "<function __main__.plot_out_degree(lines)>" |
277 | ] | 275 | ] |
278 | }, | 276 | }, |
279 | "execution_count": 31, | 277 | "execution_count": 12, |
280 | "metadata": {}, | 278 | "metadata": {}, |
281 | "output_type": "execute_result" | 279 | "output_type": "execute_result" |
282 | } | 280 | } |
@@ -289,18 +287,18 @@ | |||
289 | }, | 287 | }, |
290 | { | 288 | { |
291 | "cell_type": "code", | 289 | "cell_type": "code", |
292 | "execution_count": 32, | 290 | "execution_count": 13, |
293 | "metadata": {}, | 291 | "metadata": {}, |
294 | "outputs": [ | 292 | "outputs": [ |
295 | { | 293 | { |
296 | "data": { | 294 | "data": { |
297 | "application/vnd.jupyter.widget-view+json": { | 295 | "application/vnd.jupyter.widget-view+json": { |
298 | "model_id": "3c07dab0b6fd4c45b0168d206e99e4ea", | 296 | "model_id": "e8b74fe96a45445f8062468ddf2597bf", |
299 | "version_major": 2, | 297 | "version_major": 2, |
300 | "version_minor": 0 | 298 | "version_minor": 0 |
301 | }, | 299 | }, |
302 | "text/plain": [ | 300 | "text/plain": [ |
303 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(11,), options={'../statistics/viatra_no…" | 301 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/viatra_noc…" |
304 | ] | 302 | ] |
305 | }, | 303 | }, |
306 | "metadata": {}, | 304 | "metadata": {}, |
@@ -312,7 +310,7 @@ | |||
312 | "<function __main__.plot_out_na(lines)>" | 310 | "<function __main__.plot_out_na(lines)>" |
313 | ] | 311 | ] |
314 | }, | 312 | }, |
315 | "execution_count": 32, | 313 | "execution_count": 13, |
316 | "metadata": {}, | 314 | "metadata": {}, |
317 | "output_type": "execute_result" | 315 | "output_type": "execute_result" |
318 | } | 316 | } |
@@ -325,18 +323,18 @@ | |||
325 | }, | 323 | }, |
326 | { | 324 | { |
327 | "cell_type": "code", | 325 | "cell_type": "code", |
328 | "execution_count": 33, | 326 | "execution_count": 14, |
329 | "metadata": {}, | 327 | "metadata": {}, |
330 | "outputs": [ | 328 | "outputs": [ |
331 | { | 329 | { |
332 | "data": { | 330 | "data": { |
333 | "application/vnd.jupyter.widget-view+json": { | 331 | "application/vnd.jupyter.widget-view+json": { |
334 | "model_id": "f3bb86160c964b5383bda7cdee81a1b7", | 332 | "model_id": "c6e7e31f454a48169dac12c8aac70eef", |
335 | "version_major": 2, | 333 | "version_major": 2, |
336 | "version_minor": 0 | 334 | "version_minor": 0 |
337 | }, | 335 | }, |
338 | "text/plain": [ | 336 | "text/plain": [ |
339 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(11,), options={'../statistics/viatra_no…" | 337 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/viatra_noc…" |
340 | ] | 338 | ] |
341 | }, | 339 | }, |
342 | "metadata": {}, | 340 | "metadata": {}, |
@@ -348,7 +346,7 @@ | |||
348 | "<function __main__.plot_out_mpc(lines)>" | 346 | "<function __main__.plot_out_mpc(lines)>" |
349 | ] | 347 | ] |
350 | }, | 348 | }, |
351 | "execution_count": 33, | 349 | "execution_count": 14, |
352 | "metadata": {}, | 350 | "metadata": {}, |
353 | "output_type": "execute_result" | 351 | "output_type": "execute_result" |
354 | } | 352 | } |
@@ -361,44 +359,18 @@ | |||
361 | }, | 359 | }, |
362 | { | 360 | { |
363 | "cell_type": "code", | 361 | "cell_type": "code", |
364 | "execution_count": 35, | 362 | "execution_count": 15, |
365 | "metadata": {}, | ||
366 | "outputs": [], | ||
367 | "source": [ | ||
368 | "filenames = reader.readmultiplefiles('../statistics/viatra_con_output/trajectories/', 15, False)\n", | ||
369 | "trajectories = {}\n", | ||
370 | "for name in filenames:\n", | ||
371 | " trajectories[name] = reader.readTrajectory(name)\n", | ||
372 | "\n", | ||
373 | "w = widgets.SelectMultiple(\n", | ||
374 | " options = trajectories,\n", | ||
375 | " value = [trajectories[filenames[0]]],\n", | ||
376 | " description='Trajectory:',\n", | ||
377 | " disabled=False,\n", | ||
378 | ")\n", | ||
379 | "\n", | ||
380 | "#generate random color for each line\n", | ||
381 | "colors = []\n", | ||
382 | "\n", | ||
383 | "for i in range(0, len(trajectories)):\n", | ||
384 | " color = \"#%06x\" % random.randint(0, 0xFFFFFF)\n", | ||
385 | " colors.append(color)" | ||
386 | ] | ||
387 | }, | ||
388 | { | ||
389 | "cell_type": "code", | ||
390 | "execution_count": 36, | ||
391 | "metadata": {}, | 363 | "metadata": {}, |
392 | "outputs": [ | 364 | "outputs": [ |
393 | { | 365 | { |
394 | "data": { | 366 | "data": { |
395 | "application/vnd.jupyter.widget-view+json": { | 367 | "application/vnd.jupyter.widget-view+json": { |
396 | "model_id": "ec10c88d57f14461b160572e0a3f4e0d", | 368 | "model_id": "cebc359548f74cc8b7540ecc3876c9ee", |
397 | "version_major": 2, | 369 | "version_major": 2, |
398 | "version_minor": 0 | 370 | "version_minor": 0 |
399 | }, | 371 | }, |
400 | "text/plain": [ | 372 | "text/plain": [ |
401 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/viatra_con…" | 373 | "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" |
402 | ] | 374 | ] |
403 | }, | 375 | }, |
404 | "metadata": {}, | 376 | "metadata": {}, |
@@ -410,7 +382,7 @@ | |||
410 | "<function __main__.plot_out_degree(lines)>" | 382 | "<function __main__.plot_out_degree(lines)>" |
411 | ] | 383 | ] |
412 | }, | 384 | }, |
413 | "execution_count": 36, | 385 | "execution_count": 15, |
414 | "metadata": {}, | 386 | "metadata": {}, |
415 | "output_type": "execute_result" | 387 | "output_type": "execute_result" |
416 | } | 388 | } |
@@ -418,23 +390,23 @@ | |||
418 | "source": [ | 390 | "source": [ |
419 | "def plot_out_degree(lines):\n", | 391 | "def plot_out_degree(lines):\n", |
420 | " plot(viatra_con_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree')\n", | 392 | " plot(viatra_con_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree')\n", |
421 | "interact(plot_out_degree, lines=w)" | 393 | "interact(plot_out_degree, lines=[[]])" |
422 | ] | 394 | ] |
423 | }, | 395 | }, |
424 | { | 396 | { |
425 | "cell_type": "code", | 397 | "cell_type": "code", |
426 | "execution_count": 37, | 398 | "execution_count": 16, |
427 | "metadata": {}, | 399 | "metadata": {}, |
428 | "outputs": [ | 400 | "outputs": [ |
429 | { | 401 | { |
430 | "data": { | 402 | "data": { |
431 | "application/vnd.jupyter.widget-view+json": { | 403 | "application/vnd.jupyter.widget-view+json": { |
432 | "model_id": "bde0cb7466f64699be0159a8404eb821", | 404 | "model_id": "682beae42eef4676b11b6fe23127a44e", |
433 | "version_major": 2, | 405 | "version_major": 2, |
434 | "version_minor": 0 | 406 | "version_minor": 0 |
435 | }, | 407 | }, |
436 | "text/plain": [ | 408 | "text/plain": [ |
437 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(3,), options={'../statistics/viatra_con…" | 409 | "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" |
438 | ] | 410 | ] |
439 | }, | 411 | }, |
440 | "metadata": {}, | 412 | "metadata": {}, |
@@ -446,7 +418,7 @@ | |||
446 | "<function __main__.plot_na(lines)>" | 418 | "<function __main__.plot_na(lines)>" |
447 | ] | 419 | ] |
448 | }, | 420 | }, |
449 | "execution_count": 37, | 421 | "execution_count": 16, |
450 | "metadata": {}, | 422 | "metadata": {}, |
451 | "output_type": "execute_result" | 423 | "output_type": "execute_result" |
452 | } | 424 | } |
@@ -454,23 +426,23 @@ | |||
454 | "source": [ | 426 | "source": [ |
455 | "def plot_na(lines):\n", | 427 | "def plot_na(lines):\n", |
456 | " plot(viatra_con_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity')\n", | 428 | " plot(viatra_con_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity')\n", |
457 | "interact(plot_na, lines=w)" | 429 | "interact(plot_na, lines=[[]])" |
458 | ] | 430 | ] |
459 | }, | 431 | }, |
460 | { | 432 | { |
461 | "cell_type": "code", | 433 | "cell_type": "code", |
462 | "execution_count": 38, | 434 | "execution_count": 17, |
463 | "metadata": {}, | 435 | "metadata": {}, |
464 | "outputs": [ | 436 | "outputs": [ |
465 | { | 437 | { |
466 | "data": { | 438 | "data": { |
467 | "application/vnd.jupyter.widget-view+json": { | 439 | "application/vnd.jupyter.widget-view+json": { |
468 | "model_id": "9fda08a154104d80aca9d6eef3404bf1", | 440 | "model_id": "6893b8c6e03441f89fc35bf784992ae9", |
469 | "version_major": 2, | 441 | "version_major": 2, |
470 | "version_minor": 0 | 442 | "version_minor": 0 |
471 | }, | 443 | }, |
472 | "text/plain": [ | 444 | "text/plain": [ |
473 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(3,), options={'../statistics/viatra_con…" | 445 | "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" |
474 | ] | 446 | ] |
475 | }, | 447 | }, |
476 | "metadata": {}, | 448 | "metadata": {}, |
@@ -482,7 +454,7 @@ | |||
482 | "<function __main__.plot_mpc(lines)>" | 454 | "<function __main__.plot_mpc(lines)>" |
483 | ] | 455 | ] |
484 | }, | 456 | }, |
485 | "execution_count": 38, | 457 | "execution_count": 17, |
486 | "metadata": {}, | 458 | "metadata": {}, |
487 | "output_type": "execute_result" | 459 | "output_type": "execute_result" |
488 | } | 460 | } |
@@ -490,18 +462,18 @@ | |||
490 | "source": [ | 462 | "source": [ |
491 | "def plot_mpc(lines):\n", | 463 | "def plot_mpc(lines):\n", |
492 | " plot(viatra_con_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC')\n", | 464 | " plot(viatra_con_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC')\n", |
493 | "interact(plot_mpc, lines=w)" | 465 | "interact(plot_mpc, lines=[[]])" |
494 | ] | 466 | ] |
495 | }, | 467 | }, |
496 | { | 468 | { |
497 | "cell_type": "code", | 469 | "cell_type": "code", |
498 | "execution_count": 29, | 470 | "execution_count": 18, |
499 | "metadata": {}, | 471 | "metadata": {}, |
500 | "outputs": [ | 472 | "outputs": [ |
501 | { | 473 | { |
502 | "data": { | 474 | "data": { |
503 | "application/vnd.jupyter.widget-view+json": { | 475 | "application/vnd.jupyter.widget-view+json": { |
504 | "model_id": "5f4859e7657a4080b8ee0db66ad70b04", | 476 | "model_id": "ff0e1991c69a4d77a40f57225f90295a", |
505 | "version_major": 2, | 477 | "version_major": 2, |
506 | "version_minor": 0 | 478 | "version_minor": 0 |
507 | }, | 479 | }, |
@@ -518,7 +490,7 @@ | |||
518 | "<function __main__.plot_out_degree(lines)>" | 490 | "<function __main__.plot_out_degree(lines)>" |
519 | ] | 491 | ] |
520 | }, | 492 | }, |
521 | "execution_count": 29, | 493 | "execution_count": 18, |
522 | "metadata": {}, | 494 | "metadata": {}, |
523 | "output_type": "execute_result" | 495 | "output_type": "execute_result" |
524 | } | 496 | } |
@@ -531,49 +503,13 @@ | |||
531 | }, | 503 | }, |
532 | { | 504 | { |
533 | "cell_type": "code", | 505 | "cell_type": "code", |
534 | "execution_count": 28, | 506 | "execution_count": 19, |
535 | "metadata": {}, | ||
536 | "outputs": [ | ||
537 | { | ||
538 | "data": { | ||
539 | "application/vnd.jupyter.widget-view+json": { | ||
540 | "model_id": "fd6387994c764904b20975a54b47bf3a", | ||
541 | "version_major": 2, | ||
542 | "version_minor": 0 | ||
543 | }, | ||
544 | "text/plain": [ | ||
545 | "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" | ||
546 | ] | ||
547 | }, | ||
548 | "metadata": {}, | ||
549 | "output_type": "display_data" | ||
550 | }, | ||
551 | { | ||
552 | "data": { | ||
553 | "text/plain": [ | ||
554 | "<function __main__.plot_out_degree(lines)>" | ||
555 | ] | ||
556 | }, | ||
557 | "execution_count": 28, | ||
558 | "metadata": {}, | ||
559 | "output_type": "execute_result" | ||
560 | } | ||
561 | ], | ||
562 | "source": [ | ||
563 | "def plot_out_degree(lines):\n", | ||
564 | " plot(random_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity')\n", | ||
565 | "interact(plot_out_degree, lines=[[]])" | ||
566 | ] | ||
567 | }, | ||
568 | { | ||
569 | "cell_type": "code", | ||
570 | "execution_count": 26, | ||
571 | "metadata": {}, | 507 | "metadata": {}, |
572 | "outputs": [ | 508 | "outputs": [ |
573 | { | 509 | { |
574 | "data": { | 510 | "data": { |
575 | "application/vnd.jupyter.widget-view+json": { | 511 | "application/vnd.jupyter.widget-view+json": { |
576 | "model_id": "27e3897451694ffb8af3dd32bc0ece70", | 512 | "model_id": "838570f20bed4d8d9c618305984d19ef", |
577 | "version_major": 2, | 513 | "version_major": 2, |
578 | "version_minor": 0 | 514 | "version_minor": 0 |
579 | }, | 515 | }, |
@@ -590,26 +526,26 @@ | |||
590 | "<function __main__.plot_out_degree(lines)>" | 526 | "<function __main__.plot_out_degree(lines)>" |
591 | ] | 527 | ] |
592 | }, | 528 | }, |
593 | "execution_count": 26, | 529 | "execution_count": 19, |
594 | "metadata": {}, | 530 | "metadata": {}, |
595 | "output_type": "execute_result" | 531 | "output_type": "execute_result" |
596 | } | 532 | } |
597 | ], | 533 | ], |
598 | "source": [ | 534 | "source": [ |
599 | "def plot_out_degree(lines):\n", | 535 | "def plot_out_degree(lines):\n", |
600 | " plot(random_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC')\n", | 536 | " plot(random_dic, lines, 0, lambda a: a.na_distance, colors, 'out degree')\n", |
601 | "interact(plot_out_degree, lines=[[]])" | 537 | "interact(plot_out_degree, lines=[[]])" |
602 | ] | 538 | ] |
603 | }, | 539 | }, |
604 | { | 540 | { |
605 | "cell_type": "code", | 541 | "cell_type": "code", |
606 | "execution_count": 25, | 542 | "execution_count": 20, |
607 | "metadata": {}, | 543 | "metadata": {}, |
608 | "outputs": [ | 544 | "outputs": [ |
609 | { | 545 | { |
610 | "data": { | 546 | "data": { |
611 | "application/vnd.jupyter.widget-view+json": { | 547 | "application/vnd.jupyter.widget-view+json": { |
612 | "model_id": "f4d0964368254b599c7cb8d6b6f9a0f4", | 548 | "model_id": "f4825f6257a74bce9dd22aac8a98effa", |
613 | "version_major": 2, | 549 | "version_major": 2, |
614 | "version_minor": 0 | 550 | "version_minor": 0 |
615 | }, | 551 | }, |
@@ -626,96 +562,41 @@ | |||
626 | "<function __main__.plot_out_degree(lines)>" | 562 | "<function __main__.plot_out_degree(lines)>" |
627 | ] | 563 | ] |
628 | }, | 564 | }, |
629 | "execution_count": 25, | 565 | "execution_count": 20, |
630 | "metadata": {}, | 566 | "metadata": {}, |
631 | "output_type": "execute_result" | 567 | "output_type": "execute_result" |
632 | } | 568 | } |
633 | ], | 569 | ], |
634 | "source": [ | 570 | "source": [ |
635 | "def plot_out_degree(lines):\n", | 571 | "def plot_out_degree(lines):\n", |
636 | " plot(real_random_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree')\n", | 572 | " plot(random_dic, lines, 0, lambda a: a.mpc_distance, colors, 'out degree')\n", |
637 | "interact(plot_out_degree, lines=[[]])" | 573 | "interact(plot_out_degree, lines=[[]])" |
638 | ] | 574 | ] |
639 | }, | 575 | }, |
640 | { | 576 | { |
641 | "cell_type": "code", | 577 | "cell_type": "code", |
642 | "execution_count": 24, | 578 | "execution_count": 54, |
643 | "metadata": {}, | 579 | "metadata": {}, |
644 | "outputs": [ | 580 | "outputs": [], |
645 | { | ||
646 | "data": { | ||
647 | "application/vnd.jupyter.widget-view+json": { | ||
648 | "model_id": "eca026dd74a945bcbebde5cb69cfe0e2", | ||
649 | "version_major": 2, | ||
650 | "version_minor": 0 | ||
651 | }, | ||
652 | "text/plain": [ | ||
653 | "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" | ||
654 | ] | ||
655 | }, | ||
656 | "metadata": {}, | ||
657 | "output_type": "display_data" | ||
658 | }, | ||
659 | { | ||
660 | "data": { | ||
661 | "text/plain": [ | ||
662 | "<function __main__.plot_out_degree(lines)>" | ||
663 | ] | ||
664 | }, | ||
665 | "execution_count": 24, | ||
666 | "metadata": {}, | ||
667 | "output_type": "execute_result" | ||
668 | } | ||
669 | ], | ||
670 | "source": [ | 581 | "source": [ |
671 | "def plot_out_degree(lines):\n", | 582 | "con_viatra_stats = readStats('../statistics/controled_viatra/',5000)\n", |
672 | " plot(real_random_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity')\n", | 583 | "con_viatra_dic = calDistanceDic(con_viatra_stats, human_rep)" |
673 | "interact(plot_out_degree, lines=[[]])" | ||
674 | ] | 584 | ] |
675 | }, | 585 | }, |
676 | { | 586 | { |
677 | "cell_type": "code", | 587 | "cell_type": "markdown", |
678 | "execution_count": 27, | ||
679 | "metadata": {}, | 588 | "metadata": {}, |
680 | "outputs": [ | ||
681 | { | ||
682 | "data": { | ||
683 | "application/vnd.jupyter.widget-view+json": { | ||
684 | "model_id": "eff1d3cd5d1a4a85b56024362890759c", | ||
685 | "version_major": 2, | ||
686 | "version_minor": 0 | ||
687 | }, | ||
688 | "text/plain": [ | ||
689 | "interactive(children=(Dropdown(description='lines', options=([],), value=[]), Output()), _dom_classes=('widget…" | ||
690 | ] | ||
691 | }, | ||
692 | "metadata": {}, | ||
693 | "output_type": "display_data" | ||
694 | }, | ||
695 | { | ||
696 | "data": { | ||
697 | "text/plain": [ | ||
698 | "<function __main__.plot_out_degree(lines)>" | ||
699 | ] | ||
700 | }, | ||
701 | "execution_count": 27, | ||
702 | "metadata": {}, | ||
703 | "output_type": "execute_result" | ||
704 | } | ||
705 | ], | ||
706 | "source": [ | 589 | "source": [ |
707 | "def plot_out_degree(lines):\n", | 590 | "## Trajectories for controlled viatra solver" |
708 | " plot(real_random_dic, lines, 0, lambda a: a.mpc_distance, colors, 'MPC')\n", | ||
709 | "interact(plot_out_degree, lines=[[]])" | ||
710 | ] | 591 | ] |
711 | }, | 592 | }, |
712 | { | 593 | { |
713 | "cell_type": "code", | 594 | "cell_type": "code", |
714 | "execution_count": 11, | 595 | "execution_count": 56, |
715 | "metadata": {}, | 596 | "metadata": {}, |
716 | "outputs": [], | 597 | "outputs": [], |
717 | "source": [ | 598 | "source": [ |
718 | "filenames = reader.readmultiplefiles('../statistics/viatra500nodes/trajectories/', 15, False)\n", | 599 | "filenames = reader.readmultiplefiles('../statistics/controled_viatra/trajectories/', 25, False)\n", |
719 | "trajectories = {}\n", | 600 | "trajectories = {}\n", |
720 | "for name in filenames:\n", | 601 | "for name in filenames:\n", |
721 | " trajectories[name] = reader.readTrajectory(name)\n", | 602 | " trajectories[name] = reader.readTrajectory(name)\n", |
@@ -725,30 +606,23 @@ | |||
725 | " value = [trajectories[filenames[0]]],\n", | 606 | " value = [trajectories[filenames[0]]],\n", |
726 | " description='Trajectory:',\n", | 607 | " description='Trajectory:',\n", |
727 | " disabled=False,\n", | 608 | " disabled=False,\n", |
728 | ")\n", | 609 | ")" |
729 | "\n", | ||
730 | "#generate random color for each line\n", | ||
731 | "colors = []\n", | ||
732 | "\n", | ||
733 | "for i in range(0, len(trajectories)):\n", | ||
734 | " color = \"#%06x\" % random.randint(0, 0xFFFFFF)\n", | ||
735 | " colors.append(color)" | ||
736 | ] | 610 | ] |
737 | }, | 611 | }, |
738 | { | 612 | { |
739 | "cell_type": "code", | 613 | "cell_type": "code", |
740 | "execution_count": 12, | 614 | "execution_count": 57, |
741 | "metadata": {}, | 615 | "metadata": {}, |
742 | "outputs": [ | 616 | "outputs": [ |
743 | { | 617 | { |
744 | "data": { | 618 | "data": { |
745 | "application/vnd.jupyter.widget-view+json": { | 619 | "application/vnd.jupyter.widget-view+json": { |
746 | "model_id": "e281415e80684a85ba24ab8cb48ea3fe", | 620 | "model_id": "4b60ae3859e343299badf29272f67d21", |
747 | "version_major": 2, | 621 | "version_major": 2, |
748 | "version_minor": 0 | 622 | "version_minor": 0 |
749 | }, | 623 | }, |
750 | "text/plain": [ | 624 | "text/plain": [ |
751 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/viatra500n…" | 625 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/controled_…" |
752 | ] | 626 | ] |
753 | }, | 627 | }, |
754 | "metadata": {}, | 628 | "metadata": {}, |
@@ -760,31 +634,31 @@ | |||
760 | "<function __main__.plot_out_degree(lines)>" | 634 | "<function __main__.plot_out_degree(lines)>" |
761 | ] | 635 | ] |
762 | }, | 636 | }, |
763 | "execution_count": 12, | 637 | "execution_count": 57, |
764 | "metadata": {}, | 638 | "metadata": {}, |
765 | "output_type": "execute_result" | 639 | "output_type": "execute_result" |
766 | } | 640 | } |
767 | ], | 641 | ], |
768 | "source": [ | 642 | "source": [ |
769 | "def plot_out_degree(lines):\n", | 643 | "def plot_out_degree(lines):\n", |
770 | " plot(viatra_500_dic, lines, 0, lambda a: a.na_distance, colors, 'node activity')\n", | 644 | " plot(con_viatra_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out_degree')\n", |
771 | "interact(plot_out_degree, lines=w)" | 645 | "interact(plot_out_degree, lines=w)" |
772 | ] | 646 | ] |
773 | }, | 647 | }, |
774 | { | 648 | { |
775 | "cell_type": "code", | 649 | "cell_type": "code", |
776 | "execution_count": 22, | 650 | "execution_count": 58, |
777 | "metadata": {}, | 651 | "metadata": {}, |
778 | "outputs": [ | 652 | "outputs": [ |
779 | { | 653 | { |
780 | "data": { | 654 | "data": { |
781 | "application/vnd.jupyter.widget-view+json": { | 655 | "application/vnd.jupyter.widget-view+json": { |
782 | "model_id": "d678fee844e84e2785d50945288f833d", | 656 | "model_id": "8e7965d793a146d4bbc268554262eb58", |
783 | "version_major": 2, | 657 | "version_major": 2, |
784 | "version_minor": 0 | 658 | "version_minor": 0 |
785 | }, | 659 | }, |
786 | "text/plain": [ | 660 | "text/plain": [ |
787 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/viatra500n…" | 661 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/controled_…" |
788 | ] | 662 | ] |
789 | }, | 663 | }, |
790 | "metadata": {}, | 664 | "metadata": {}, |
@@ -793,34 +667,34 @@ | |||
793 | { | 667 | { |
794 | "data": { | 668 | "data": { |
795 | "text/plain": [ | 669 | "text/plain": [ |
796 | "<function __main__.plot_out_degree(lines)>" | 670 | "<function __main__.plot_na(lines)>" |
797 | ] | 671 | ] |
798 | }, | 672 | }, |
799 | "execution_count": 22, | 673 | "execution_count": 58, |
800 | "metadata": {}, | 674 | "metadata": {}, |
801 | "output_type": "execute_result" | 675 | "output_type": "execute_result" |
802 | } | 676 | } |
803 | ], | 677 | ], |
804 | "source": [ | 678 | "source": [ |
805 | "def plot_out_degree(lines):\n", | 679 | "def plot_na(lines):\n", |
806 | " plot(viatra_500_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out degree')\n", | 680 | " plot(con_viatra_dic, lines, 0, lambda a: a.na_distance, colors, 'Node Activity')\n", |
807 | "interact(plot_out_degree, lines=w)" | 681 | "interact(plot_na, lines=w)" |
808 | ] | 682 | ] |
809 | }, | 683 | }, |
810 | { | 684 | { |
811 | "cell_type": "code", | 685 | "cell_type": "code", |
812 | "execution_count": 21, | 686 | "execution_count": 59, |
813 | "metadata": {}, | 687 | "metadata": {}, |
814 | "outputs": [ | 688 | "outputs": [ |
815 | { | 689 | { |
816 | "data": { | 690 | "data": { |
817 | "application/vnd.jupyter.widget-view+json": { | 691 | "application/vnd.jupyter.widget-view+json": { |
818 | "model_id": "55ca7c3f89224cce8d3a87cf23b20f92", | 692 | "model_id": "55a1209d0b924a39b4729228e81ee3ab", |
819 | "version_major": 2, | 693 | "version_major": 2, |
820 | "version_minor": 0 | 694 | "version_minor": 0 |
821 | }, | 695 | }, |
822 | "text/plain": [ | 696 | "text/plain": [ |
823 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/viatra500n…" | 697 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/controled_…" |
824 | ] | 698 | ] |
825 | }, | 699 | }, |
826 | "metadata": {}, | 700 | "metadata": {}, |
@@ -829,18 +703,18 @@ | |||
829 | { | 703 | { |
830 | "data": { | 704 | "data": { |
831 | "text/plain": [ | 705 | "text/plain": [ |
832 | "<function __main__.plot_out_degree(lines)>" | 706 | "<function __main__.plot_mpc(lines)>" |
833 | ] | 707 | ] |
834 | }, | 708 | }, |
835 | "execution_count": 21, | 709 | "execution_count": 59, |
836 | "metadata": {}, | 710 | "metadata": {}, |
837 | "output_type": "execute_result" | 711 | "output_type": "execute_result" |
838 | } | 712 | } |
839 | ], | 713 | ], |
840 | "source": [ | 714 | "source": [ |
841 | "def plot_out_degree(lines):\n", | 715 | "def plot_mpc(lines):\n", |
842 | " plot(viatra_500_dic, lines, 0, lambda a: a.mpc_distance, colors, 'mpc')\n", | 716 | " plot(con_viatra_dic, lines, 0, lambda a: a.mpc_distance, colors, 'mpc')\n", |
843 | "interact(plot_out_degree, lines=w)" | 717 | "interact(plot_mpc, lines=w)" |
844 | ] | 718 | ] |
845 | }, | 719 | }, |
846 | { | 720 | { |
@@ -849,6 +723,20 @@ | |||
849 | "metadata": {}, | 723 | "metadata": {}, |
850 | "outputs": [], | 724 | "outputs": [], |
851 | "source": [] | 725 | "source": [] |
726 | }, | ||
727 | { | ||
728 | "cell_type": "code", | ||
729 | "execution_count": null, | ||
730 | "metadata": {}, | ||
731 | "outputs": [], | ||
732 | "source": [] | ||
733 | }, | ||
734 | { | ||
735 | "cell_type": "code", | ||
736 | "execution_count": null, | ||
737 | "metadata": {}, | ||
738 | "outputs": [], | ||
739 | "source": [] | ||
852 | } | 740 | } |
853 | ], | 741 | ], |
854 | "metadata": { | 742 | "metadata": { |
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..58ca7549 --- /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 = '../statistics/humanOutput\R_20158_run_1.csv' | ||
22 | |||
23 | HUMAN_MPC_REP = '../statistics/humanOutput\R_2015246_run_1.csv' | ||
24 | |||
25 | HUMAN_NA_REP = '../statistics/humanOutput\R_2016176_run_1.csv' | ||
diff --git a/Metrics/Metrics-Calculation/metrics_plot/utils/readCSV.py b/Metrics/Metrics-Calculation/metrics_plot/utils/readCSV.py new file mode 100644 index 00000000..e0402519 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/utils/readCSV.py | |||
@@ -0,0 +1,169 @@ | |||
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 | |||