diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/distance')
-rw-r--r-- | Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/distance/KSDistance.xtend | 23 |
1 files changed, 20 insertions, 3 deletions
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 index 08d8704a..c486a328 100644 --- 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 | |||
@@ -70,13 +70,30 @@ class KSDistance extends CostDistance { | |||
70 | instanceDist.add(samples.getOrDefault(key, 0.0)); | 70 | instanceDist.add(samples.getOrDefault(key, 0.0)); |
71 | } | 71 | } |
72 | 72 | ||
73 | return ks_distance_two_dist(sourceDist, instanceDist); | ||
74 | } | ||
75 | |||
76 | def edgeTypeDistance(HashMap<String, Double> samples){ | ||
77 | var typesDistMap = g.edgeTypeSamples; | ||
78 | var sourceDist = newArrayList(); | ||
79 | var instanceDist = newArrayList(); | ||
80 | |||
81 | for(key : typesDistMap.keySet()){ | ||
82 | sourceDist.add(typesDistMap.get(key)); | ||
83 | instanceDist.add(samples.getOrDefault(key, 0.0)); | ||
84 | } | ||
85 | |||
86 | return ks_distance_two_dist(sourceDist, instanceDist); | ||
87 | } | ||
88 | |||
89 | def double ks_distance_two_dist(List<Double> dist1, List<Double> dist2){ | ||
73 | // Since we already know the pdf, we compute the ks-test manully | 90 | // Since we already know the pdf, we compute the ks-test manully |
74 | var ksStatistics = 0.0; | 91 | var ksStatistics = 0.0; |
75 | var sum1 = 0.0; | 92 | var sum1 = 0.0; |
76 | var sum2 = 0.0; | 93 | var sum2 = 0.0; |
77 | for(var i = 0; i < sourceDist.size(); i++){ | 94 | for(var i = 0; i < dist1.size(); i++){ |
78 | sum1 += sourceDist.get(i); | 95 | sum1 += dist1.get(i); |
79 | sum2 += instanceDist.get(i); | 96 | sum2 += dist2.get(i); |
80 | 97 | ||
81 | ksStatistics = Math.max(ksStatistics, Math.abs(sum1 - sum2)); | 98 | ksStatistics = Math.max(ksStatistics, Math.abs(sum1 - sum2)); |
82 | } | 99 | } |