diff options
Diffstat (limited to 'Metrics')
27 files changed, 781 insertions, 60 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 e5868da0..a0b0ad8d 100644 --- a/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance_with_selector.ipynb +++ b/Metrics/Metrics-Calculation/metrics_plot/src/metrics_distance_with_selector.ipynb | |||
@@ -16,7 +16,7 @@ | |||
16 | }, | 16 | }, |
17 | { | 17 | { |
18 | "cell_type": "code", | 18 | "cell_type": "code", |
19 | "execution_count": 2, | 19 | "execution_count": 1, |
20 | "metadata": {}, | 20 | "metadata": {}, |
21 | "outputs": [], | 21 | "outputs": [], |
22 | "source": [ | 22 | "source": [ |
@@ -48,7 +48,7 @@ | |||
48 | }, | 48 | }, |
49 | { | 49 | { |
50 | "cell_type": "code", | 50 | "cell_type": "code", |
51 | "execution_count": 3, | 51 | "execution_count": 2, |
52 | "metadata": {}, | 52 | "metadata": {}, |
53 | "outputs": [], | 53 | "outputs": [], |
54 | "source": [ | 54 | "source": [ |
@@ -78,7 +78,7 @@ | |||
78 | }, | 78 | }, |
79 | { | 79 | { |
80 | "cell_type": "code", | 80 | "cell_type": "code", |
81 | "execution_count": 4, | 81 | "execution_count": 3, |
82 | "metadata": {}, | 82 | "metadata": {}, |
83 | "outputs": [], | 83 | "outputs": [], |
84 | "source": [ | 84 | "source": [ |
@@ -108,7 +108,7 @@ | |||
108 | }, | 108 | }, |
109 | { | 109 | { |
110 | "cell_type": "code", | 110 | "cell_type": "code", |
111 | "execution_count": 5, | 111 | "execution_count": 4, |
112 | "metadata": {}, | 112 | "metadata": {}, |
113 | "outputs": [], | 113 | "outputs": [], |
114 | "source": [ | 114 | "source": [ |
@@ -139,7 +139,7 @@ | |||
139 | }, | 139 | }, |
140 | { | 140 | { |
141 | "cell_type": "code", | 141 | "cell_type": "code", |
142 | "execution_count": 6, | 142 | "execution_count": 5, |
143 | "metadata": {}, | 143 | "metadata": {}, |
144 | "outputs": [], | 144 | "outputs": [], |
145 | "source": [ | 145 | "source": [ |
@@ -149,7 +149,7 @@ | |||
149 | }, | 149 | }, |
150 | { | 150 | { |
151 | "cell_type": "code", | 151 | "cell_type": "code", |
152 | "execution_count": 7, | 152 | "execution_count": 6, |
153 | "metadata": {}, | 153 | "metadata": {}, |
154 | "outputs": [], | 154 | "outputs": [], |
155 | "source": [ | 155 | "source": [ |
@@ -163,7 +163,7 @@ | |||
163 | }, | 163 | }, |
164 | { | 164 | { |
165 | "cell_type": "code", | 165 | "cell_type": "code", |
166 | "execution_count": 8, | 166 | "execution_count": 7, |
167 | "metadata": {}, | 167 | "metadata": {}, |
168 | "outputs": [], | 168 | "outputs": [], |
169 | "source": [ | 169 | "source": [ |
@@ -200,7 +200,8 @@ | |||
200 | "# Read generated models\n", | 200 | "# Read generated models\n", |
201 | "viatra_no_con_stats = readStats('../statistics/viatra_nocon_output/', 5000)\n", | 201 | "viatra_no_con_stats = readStats('../statistics/viatra_nocon_output/', 5000)\n", |
202 | "viatra_con_stats = readStats('../statistics/viatra_con_output/',5000)\n", | 202 | "viatra_con_stats = readStats('../statistics/viatra_con_output/',5000)\n", |
203 | "random_stats = readStats('../statistics/random_output/',5000)" | 203 | "random_stats = readStats('../statistics/random_output/',5000)\n", |
204 | "con_viatra_stats = readStats('../statistics/controled_viatra/',300)" | ||
204 | ] | 205 | ] |
205 | }, | 206 | }, |
206 | { | 207 | { |
@@ -218,7 +219,8 @@ | |||
218 | "source": [ | 219 | "source": [ |
219 | "viatra_no_con_dic = calDistanceDic(viatra_no_con_stats, human_rep)\n", | 220 | "viatra_no_con_dic = calDistanceDic(viatra_no_con_stats, human_rep)\n", |
220 | "viatra_con_dic = calDistanceDic(viatra_con_stats, human_rep)\n", | 221 | "viatra_con_dic = calDistanceDic(viatra_con_stats, human_rep)\n", |
221 | "random_dic = calDistanceDic(random_stats, human_rep)" | 222 | "random_dic = calDistanceDic(random_stats, human_rep)\n", |
223 | "con_viatra_dic = calDistanceDic(con_viatra_stats, human_rep)" | ||
222 | ] | 224 | ] |
223 | }, | 225 | }, |
224 | { | 226 | { |
@@ -255,7 +257,7 @@ | |||
255 | { | 257 | { |
256 | "data": { | 258 | "data": { |
257 | "application/vnd.jupyter.widget-view+json": { | 259 | "application/vnd.jupyter.widget-view+json": { |
258 | "model_id": "1bdc31418d894783b36cc79c60251f00", | 260 | "model_id": "868a437468d24144926f1390cbf2acb8", |
259 | "version_major": 2, | 261 | "version_major": 2, |
260 | "version_minor": 0 | 262 | "version_minor": 0 |
261 | }, | 263 | }, |
@@ -291,7 +293,7 @@ | |||
291 | { | 293 | { |
292 | "data": { | 294 | "data": { |
293 | "application/vnd.jupyter.widget-view+json": { | 295 | "application/vnd.jupyter.widget-view+json": { |
294 | "model_id": "78565a0ec3d740908fcea753387cfc3e", | 296 | "model_id": "e8b74fe96a45445f8062468ddf2597bf", |
295 | "version_major": 2, | 297 | "version_major": 2, |
296 | "version_minor": 0 | 298 | "version_minor": 0 |
297 | }, | 299 | }, |
@@ -327,7 +329,7 @@ | |||
327 | { | 329 | { |
328 | "data": { | 330 | "data": { |
329 | "application/vnd.jupyter.widget-view+json": { | 331 | "application/vnd.jupyter.widget-view+json": { |
330 | "model_id": "4392eb19fe1844c4affeb62f9ba9163b", | 332 | "model_id": "c6e7e31f454a48169dac12c8aac70eef", |
331 | "version_major": 2, | 333 | "version_major": 2, |
332 | "version_minor": 0 | 334 | "version_minor": 0 |
333 | }, | 335 | }, |
@@ -363,7 +365,7 @@ | |||
363 | { | 365 | { |
364 | "data": { | 366 | "data": { |
365 | "application/vnd.jupyter.widget-view+json": { | 367 | "application/vnd.jupyter.widget-view+json": { |
366 | "model_id": "c667f0f9dcd5494f81d95c64ad900612", | 368 | "model_id": "cebc359548f74cc8b7540ecc3876c9ee", |
367 | "version_major": 2, | 369 | "version_major": 2, |
368 | "version_minor": 0 | 370 | "version_minor": 0 |
369 | }, | 371 | }, |
@@ -399,7 +401,7 @@ | |||
399 | { | 401 | { |
400 | "data": { | 402 | "data": { |
401 | "application/vnd.jupyter.widget-view+json": { | 403 | "application/vnd.jupyter.widget-view+json": { |
402 | "model_id": "991d8d2bfc644c82a9b079615900dc4d", | 404 | "model_id": "682beae42eef4676b11b6fe23127a44e", |
403 | "version_major": 2, | 405 | "version_major": 2, |
404 | "version_minor": 0 | 406 | "version_minor": 0 |
405 | }, | 407 | }, |
@@ -435,7 +437,7 @@ | |||
435 | { | 437 | { |
436 | "data": { | 438 | "data": { |
437 | "application/vnd.jupyter.widget-view+json": { | 439 | "application/vnd.jupyter.widget-view+json": { |
438 | "model_id": "be65f39c2fae4c84a1d6908f3b70a86e", | 440 | "model_id": "6893b8c6e03441f89fc35bf784992ae9", |
439 | "version_major": 2, | 441 | "version_major": 2, |
440 | "version_minor": 0 | 442 | "version_minor": 0 |
441 | }, | 443 | }, |
@@ -471,7 +473,7 @@ | |||
471 | { | 473 | { |
472 | "data": { | 474 | "data": { |
473 | "application/vnd.jupyter.widget-view+json": { | 475 | "application/vnd.jupyter.widget-view+json": { |
474 | "model_id": "1de0db5b5c8d46de958f6b43144dac54", | 476 | "model_id": "ff0e1991c69a4d77a40f57225f90295a", |
475 | "version_major": 2, | 477 | "version_major": 2, |
476 | "version_minor": 0 | 478 | "version_minor": 0 |
477 | }, | 479 | }, |
@@ -501,13 +503,13 @@ | |||
501 | }, | 503 | }, |
502 | { | 504 | { |
503 | "cell_type": "code", | 505 | "cell_type": "code", |
504 | "execution_count": 20, | 506 | "execution_count": 19, |
505 | "metadata": {}, | 507 | "metadata": {}, |
506 | "outputs": [ | 508 | "outputs": [ |
507 | { | 509 | { |
508 | "data": { | 510 | "data": { |
509 | "application/vnd.jupyter.widget-view+json": { | 511 | "application/vnd.jupyter.widget-view+json": { |
510 | "model_id": "6f8fa855125b4beca603abbf801412ac", | 512 | "model_id": "838570f20bed4d8d9c618305984d19ef", |
511 | "version_major": 2, | 513 | "version_major": 2, |
512 | "version_minor": 0 | 514 | "version_minor": 0 |
513 | }, | 515 | }, |
@@ -524,7 +526,7 @@ | |||
524 | "<function __main__.plot_out_degree(lines)>" | 526 | "<function __main__.plot_out_degree(lines)>" |
525 | ] | 527 | ] |
526 | }, | 528 | }, |
527 | "execution_count": 20, | 529 | "execution_count": 19, |
528 | "metadata": {}, | 530 | "metadata": {}, |
529 | "output_type": "execute_result" | 531 | "output_type": "execute_result" |
530 | } | 532 | } |
@@ -537,13 +539,13 @@ | |||
537 | }, | 539 | }, |
538 | { | 540 | { |
539 | "cell_type": "code", | 541 | "cell_type": "code", |
540 | "execution_count": 23, | 542 | "execution_count": 20, |
541 | "metadata": {}, | 543 | "metadata": {}, |
542 | "outputs": [ | 544 | "outputs": [ |
543 | { | 545 | { |
544 | "data": { | 546 | "data": { |
545 | "application/vnd.jupyter.widget-view+json": { | 547 | "application/vnd.jupyter.widget-view+json": { |
546 | "model_id": "b4ed2adb29004908a3799bc91bf0662b", | 548 | "model_id": "f4825f6257a74bce9dd22aac8a98effa", |
547 | "version_major": 2, | 549 | "version_major": 2, |
548 | "version_minor": 0 | 550 | "version_minor": 0 |
549 | }, | 551 | }, |
@@ -560,7 +562,7 @@ | |||
560 | "<function __main__.plot_out_degree(lines)>" | 562 | "<function __main__.plot_out_degree(lines)>" |
561 | ] | 563 | ] |
562 | }, | 564 | }, |
563 | "execution_count": 23, | 565 | "execution_count": 20, |
564 | "metadata": {}, | 566 | "metadata": {}, |
565 | "output_type": "execute_result" | 567 | "output_type": "execute_result" |
566 | } | 568 | } |
@@ -573,6 +575,164 @@ | |||
573 | }, | 575 | }, |
574 | { | 576 | { |
575 | "cell_type": "code", | 577 | "cell_type": "code", |
578 | "execution_count": 54, | ||
579 | "metadata": {}, | ||
580 | "outputs": [], | ||
581 | "source": [ | ||
582 | "con_viatra_stats = readStats('../statistics/controled_viatra/',5000)\n", | ||
583 | "con_viatra_dic = calDistanceDic(con_viatra_stats, human_rep)" | ||
584 | ] | ||
585 | }, | ||
586 | { | ||
587 | "cell_type": "markdown", | ||
588 | "metadata": {}, | ||
589 | "source": [ | ||
590 | "## Trajectories for controlled viatra solver" | ||
591 | ] | ||
592 | }, | ||
593 | { | ||
594 | "cell_type": "code", | ||
595 | "execution_count": 56, | ||
596 | "metadata": {}, | ||
597 | "outputs": [], | ||
598 | "source": [ | ||
599 | "filenames = reader.readmultiplefiles('../statistics/controled_viatra/trajectories/', 25, False)\n", | ||
600 | "trajectories = {}\n", | ||
601 | "for name in filenames:\n", | ||
602 | " trajectories[name] = reader.readTrajectory(name)\n", | ||
603 | "\n", | ||
604 | "w = widgets.SelectMultiple(\n", | ||
605 | " options = trajectories,\n", | ||
606 | " value = [trajectories[filenames[0]]],\n", | ||
607 | " description='Trajectory:',\n", | ||
608 | " disabled=False,\n", | ||
609 | ")" | ||
610 | ] | ||
611 | }, | ||
612 | { | ||
613 | "cell_type": "code", | ||
614 | "execution_count": 57, | ||
615 | "metadata": {}, | ||
616 | "outputs": [ | ||
617 | { | ||
618 | "data": { | ||
619 | "application/vnd.jupyter.widget-view+json": { | ||
620 | "model_id": "4b60ae3859e343299badf29272f67d21", | ||
621 | "version_major": 2, | ||
622 | "version_minor": 0 | ||
623 | }, | ||
624 | "text/plain": [ | ||
625 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/controled_…" | ||
626 | ] | ||
627 | }, | ||
628 | "metadata": {}, | ||
629 | "output_type": "display_data" | ||
630 | }, | ||
631 | { | ||
632 | "data": { | ||
633 | "text/plain": [ | ||
634 | "<function __main__.plot_out_degree(lines)>" | ||
635 | ] | ||
636 | }, | ||
637 | "execution_count": 57, | ||
638 | "metadata": {}, | ||
639 | "output_type": "execute_result" | ||
640 | } | ||
641 | ], | ||
642 | "source": [ | ||
643 | "def plot_out_degree(lines):\n", | ||
644 | " plot(con_viatra_dic, lines, 0, lambda a: a.out_d_distance, colors, 'out_degree')\n", | ||
645 | "interact(plot_out_degree, lines=w)" | ||
646 | ] | ||
647 | }, | ||
648 | { | ||
649 | "cell_type": "code", | ||
650 | "execution_count": 58, | ||
651 | "metadata": {}, | ||
652 | "outputs": [ | ||
653 | { | ||
654 | "data": { | ||
655 | "application/vnd.jupyter.widget-view+json": { | ||
656 | "model_id": "8e7965d793a146d4bbc268554262eb58", | ||
657 | "version_major": 2, | ||
658 | "version_minor": 0 | ||
659 | }, | ||
660 | "text/plain": [ | ||
661 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/controled_…" | ||
662 | ] | ||
663 | }, | ||
664 | "metadata": {}, | ||
665 | "output_type": "display_data" | ||
666 | }, | ||
667 | { | ||
668 | "data": { | ||
669 | "text/plain": [ | ||
670 | "<function __main__.plot_na(lines)>" | ||
671 | ] | ||
672 | }, | ||
673 | "execution_count": 58, | ||
674 | "metadata": {}, | ||
675 | "output_type": "execute_result" | ||
676 | } | ||
677 | ], | ||
678 | "source": [ | ||
679 | "def plot_na(lines):\n", | ||
680 | " plot(con_viatra_dic, lines, 0, lambda a: a.na_distance, colors, 'Node Activity')\n", | ||
681 | "interact(plot_na, lines=w)" | ||
682 | ] | ||
683 | }, | ||
684 | { | ||
685 | "cell_type": "code", | ||
686 | "execution_count": 59, | ||
687 | "metadata": {}, | ||
688 | "outputs": [ | ||
689 | { | ||
690 | "data": { | ||
691 | "application/vnd.jupyter.widget-view+json": { | ||
692 | "model_id": "55a1209d0b924a39b4729228e81ee3ab", | ||
693 | "version_major": 2, | ||
694 | "version_minor": 0 | ||
695 | }, | ||
696 | "text/plain": [ | ||
697 | "interactive(children=(SelectMultiple(description='Trajectory:', index=(0,), options={'../statistics/controled_…" | ||
698 | ] | ||
699 | }, | ||
700 | "metadata": {}, | ||
701 | "output_type": "display_data" | ||
702 | }, | ||
703 | { | ||
704 | "data": { | ||
705 | "text/plain": [ | ||
706 | "<function __main__.plot_mpc(lines)>" | ||
707 | ] | ||
708 | }, | ||
709 | "execution_count": 59, | ||
710 | "metadata": {}, | ||
711 | "output_type": "execute_result" | ||
712 | } | ||
713 | ], | ||
714 | "source": [ | ||
715 | "def plot_mpc(lines):\n", | ||
716 | " plot(con_viatra_dic, lines, 0, lambda a: a.mpc_distance, colors, 'mpc')\n", | ||
717 | "interact(plot_mpc, lines=w)" | ||
718 | ] | ||
719 | }, | ||
720 | { | ||
721 | "cell_type": "code", | ||
722 | "execution_count": null, | ||
723 | "metadata": {}, | ||
724 | "outputs": [], | ||
725 | "source": [] | ||
726 | }, | ||
727 | { | ||
728 | "cell_type": "code", | ||
729 | "execution_count": null, | ||
730 | "metadata": {}, | ||
731 | "outputs": [], | ||
732 | "source": [] | ||
733 | }, | ||
734 | { | ||
735 | "cell_type": "code", | ||
576 | "execution_count": null, | 736 | "execution_count": null, |
577 | "metadata": {}, | 737 | "metadata": {}, |
578 | "outputs": [], | 738 | "outputs": [], |
diff --git a/Metrics/Metrics-Calculation/metrics_plot/utils/GraphType.py b/Metrics/Metrics-Calculation/metrics_plot/utils/GraphType.py new file mode 100644 index 00000000..13754e80 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/utils/GraphType.py | |||
@@ -0,0 +1,29 @@ | |||
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 | |||