diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics')
4 files changed, 147 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/Metric.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/Metric.xtend new file mode 100644 index 00000000..ea52009a --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/Metric.xtend | |||
@@ -0,0 +1,7 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic | ||
4 | |||
5 | abstract class Metric { | ||
6 | abstract def String[][] evaluate(GraphStatistic g); | ||
7 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/MultiplexParticipationCoefficientMetric.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/MultiplexParticipationCoefficientMetric.xtend new file mode 100644 index 00000000..7bd48754 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/MultiplexParticipationCoefficientMetric.xtend | |||
@@ -0,0 +1,65 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic | ||
4 | import java.text.DecimalFormat | ||
5 | import java.util.HashMap | ||
6 | |||
7 | class MultiplexParticipationCoefficientMetric extends Metric { | ||
8 | static val countName = "MPCCount"; | ||
9 | static val valueName = "MPCValue"; | ||
10 | |||
11 | |||
12 | override evaluate(GraphStatistic g) { | ||
13 | //because the precision issue of double, we translate double values into String to be the key | ||
14 | val formatter = new DecimalFormat("#0.00000"); | ||
15 | |||
16 | //get number of different types | ||
17 | val typeCounts = g.allTypes.size; | ||
18 | val map = new HashMap<String, Integer>(); | ||
19 | //calculate the metric distribution | ||
20 | g.allNodes.forEach[n| | ||
21 | val edgeCounts = g.outDegree(n) + g.inDegree(n); | ||
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 | |||
42 | //format number to String | ||
43 | val value = formatter.format(coef); | ||
44 | if(!map.containsKey(value)){ | ||
45 | map.put(value, 1); | ||
46 | }else{ | ||
47 | map.put(value, map.get(value) + 1); | ||
48 | } | ||
49 | |||
50 | ] | ||
51 | |||
52 | //convert it into a 2 dimentional array | ||
53 | val String[][] datas = newArrayOfSize(2, map.size+1); | ||
54 | datas.get(0).set(0, valueName); | ||
55 | datas.get(1).set(0, countName) | ||
56 | var count = 1; | ||
57 | for(entry : map.entrySet.sortBy[it.key]){ | ||
58 | datas.get(0).set(count, entry.key+""); | ||
59 | datas.get(1).set(count, entry.value+""); | ||
60 | count++; | ||
61 | } | ||
62 | |||
63 | return datas; | ||
64 | } | ||
65 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/NodeActivityMetric.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/NodeActivityMetric.xtend new file mode 100644 index 00000000..297bdd14 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/NodeActivityMetric.xtend | |||
@@ -0,0 +1,37 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic | ||
4 | import java.util.HashMap | ||
5 | |||
6 | class NodeActivityMetric extends Metric { | ||
7 | static val countName = "NACount"; | ||
8 | static val valueName = "NAValue"; | ||
9 | |||
10 | override evaluate(GraphStatistic g) { | ||
11 | val map = new HashMap<Integer, Integer>(); | ||
12 | |||
13 | //calculate the metric distribution | ||
14 | g.allNodes.forEach[ | ||
15 | val value = g.numOfEdgeTypes(it); | ||
16 | if(!map.containsKey(value)){ | ||
17 | map.put(value, 1); | ||
18 | }else{ | ||
19 | map.put(value, map.get(value) + 1); | ||
20 | } | ||
21 | ] | ||
22 | |||
23 | //convert it into a 2 dimentional array | ||
24 | val String[][] datas = newArrayOfSize(2, map.size+1); | ||
25 | datas.get(0).set(0, valueName); | ||
26 | datas.get(1).set(0, countName) | ||
27 | |||
28 | var count = 1; | ||
29 | for(entry : map.entrySet.sortBy[it.key]){ | ||
30 | datas.get(0).set(count, entry.key+""); | ||
31 | datas.get(1).set(count, entry.value+""); | ||
32 | count++; | ||
33 | } | ||
34 | |||
35 | return datas; | ||
36 | } | ||
37 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/OutDegreeMetric.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/OutDegreeMetric.xtend new file mode 100644 index 00000000..1ba6c8c7 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/OutDegreeMetric.xtend | |||
@@ -0,0 +1,38 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic | ||
4 | import java.util.HashMap | ||
5 | |||
6 | class OutDegreeMetric extends Metric { | ||
7 | static val countName = "OutDegreeCount"; | ||
8 | static val valueName = "OutDegreeValue"; | ||
9 | |||
10 | override evaluate(GraphStatistic g) { | ||
11 | val map = new HashMap<Integer, Integer>(); | ||
12 | |||
13 | //calculate the metric distribution | ||
14 | g.allNodes.forEach[ | ||
15 | val value = g.outDegree(it); | ||
16 | if(!map.containsKey(value)){ | ||
17 | map.put(value, 1); | ||
18 | }else{ | ||
19 | map.put(value, map.get(value) + 1); | ||
20 | } | ||
21 | ] | ||
22 | |||
23 | //convert it into a 2 dimentional array | ||
24 | val String[][] datas = newArrayOfSize(2, map.size+1); | ||
25 | datas.get(0).set(0, valueName); | ||
26 | datas.get(1).set(0, countName) | ||
27 | var count = 1; | ||
28 | for(entry : map.entrySet.sortBy[it.key]){ | ||
29 | datas.get(0).set(count, entry.key+""); | ||
30 | datas.get(1).set(count, entry.value+""); | ||
31 | count++; | ||
32 | } | ||
33 | |||
34 | return datas; | ||
35 | } | ||
36 | |||
37 | |||
38 | } \ No newline at end of file | ||