diff options
author | ArenBabikian <aren.babikian@mail.mcgill.ca> | 2019-08-28 05:56:34 -0400 |
---|---|---|
committer | ArenBabikian <aren.babikian@mail.mcgill.ca> | 2019-08-28 05:56:34 -0400 |
commit | 6b70878a56052e1c254ba8c66485f217d22db3f8 (patch) | |
tree | 66088b97e5b6c0194f1a45f70f5f05315aba9e43 /Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/distance/JSDistance.java | |
parent | Pre-realisticBranchCreation Commit (diff) | |
download | VIATRA-Generator-6b70878a56052e1c254ba8c66485f217d22db3f8.tar.gz VIATRA-Generator-6b70878a56052e1c254ba8c66485f217d22db3f8.tar.zst VIATRA-Generator-6b70878a56052e1c254ba8c66485f217d22db3f8.zip |
VAMPIRE: integrate local Vampire executeable #32
Diffstat (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/distance/JSDistance.java')
-rw-r--r-- | Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/distance/JSDistance.java | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/distance/JSDistance.java b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/distance/JSDistance.java new file mode 100644 index 00000000..d3e7e3ad --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/distance/JSDistance.java | |||
@@ -0,0 +1,136 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.distance; | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.distance.CostDistance; | ||
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MetricSampleGroup; | ||
5 | import com.google.common.collect.Sets; | ||
6 | import java.text.DecimalFormat; | ||
7 | import java.util.HashMap; | ||
8 | import java.util.List; | ||
9 | import java.util.Set; | ||
10 | import java.util.function.ToDoubleFunction; | ||
11 | import org.eclipse.xtext.xbase.lib.Conversions; | ||
12 | import org.eclipse.xtext.xbase.lib.DoubleExtensions; | ||
13 | |||
14 | @SuppressWarnings("all") | ||
15 | public class JSDistance extends CostDistance { | ||
16 | private HashMap<String, Double> mpcPMF; | ||
17 | |||
18 | private HashMap<String, Double> naPMF; | ||
19 | |||
20 | private HashMap<String, Double> outDegreePMF; | ||
21 | |||
22 | private HashMap<String, Double> nodeTypesPMF; | ||
23 | |||
24 | private DecimalFormat formatter; | ||
25 | |||
26 | public JSDistance(final MetricSampleGroup g) { | ||
27 | List<Double> mpcSamples = g.mpcSamples; | ||
28 | final ToDoubleFunction<Double> _function = (Double it) -> { | ||
29 | return (it).doubleValue(); | ||
30 | }; | ||
31 | double[] naSamples = g.naSamples.stream().mapToDouble(_function).toArray(); | ||
32 | final ToDoubleFunction<Double> _function_1 = (Double it) -> { | ||
33 | return (it).doubleValue(); | ||
34 | }; | ||
35 | double[] outDegreeSamples = g.outDegreeSamples.stream().mapToDouble(_function_1).toArray(); | ||
36 | DecimalFormat _decimalFormat = new DecimalFormat("#0.00000"); | ||
37 | this.formatter = _decimalFormat; | ||
38 | final List<Double> _converted_mpcSamples = (List<Double>)mpcSamples; | ||
39 | this.mpcPMF = this.pmfFromSamples(((double[])Conversions.unwrapArray(_converted_mpcSamples, double.class)), this.formatter); | ||
40 | this.naPMF = this.pmfFromSamples(naSamples, this.formatter); | ||
41 | this.outDegreePMF = this.pmfFromSamples(outDegreeSamples, this.formatter); | ||
42 | this.nodeTypesPMF = g.nodeTypeSamples; | ||
43 | } | ||
44 | |||
45 | private HashMap<String, Double> combinePMF(final HashMap<String, Double> pmf1, final HashMap<String, Double> pmf2) { | ||
46 | HashMap<String, Double> pmfMap = new HashMap<String, Double>(); | ||
47 | Sets.SetView<String> union = Sets.<String>union(pmf1.keySet(), pmf2.keySet()); | ||
48 | for (final String key : union) { | ||
49 | { | ||
50 | Double _orDefault = pmf1.getOrDefault(key, Double.valueOf(0.0)); | ||
51 | Double _orDefault_1 = pmf2.getOrDefault(key, Double.valueOf(0.0)); | ||
52 | double _plus = DoubleExtensions.operator_plus(_orDefault, _orDefault_1); | ||
53 | double value = ((1.0 / 2) * _plus); | ||
54 | pmfMap.put(key, Double.valueOf(value)); | ||
55 | } | ||
56 | } | ||
57 | return pmfMap; | ||
58 | } | ||
59 | |||
60 | private double jsDivergence(final HashMap<String, Double> p, final HashMap<String, Double> q) { | ||
61 | final HashMap<String, Double> m = this.combinePMF(q, p); | ||
62 | double _klDivergence = this.klDivergence(p, m); | ||
63 | double _multiply = ((1.0 / 2) * _klDivergence); | ||
64 | double _klDivergence_1 = this.klDivergence(q, m); | ||
65 | double _multiply_1 = ((1.0 / 2) * _klDivergence_1); | ||
66 | double distance = (_multiply + _multiply_1); | ||
67 | return distance; | ||
68 | } | ||
69 | |||
70 | public double klDivergence(final HashMap<String, Double> p, final HashMap<String, Double> q) { | ||
71 | double distance = 0.0; | ||
72 | Set<String> _keySet = q.keySet(); | ||
73 | for (final String key : _keySet) { | ||
74 | boolean _containsKey = p.containsKey(key); | ||
75 | if (_containsKey) { | ||
76 | double _distance = distance; | ||
77 | Double _get = p.get(key); | ||
78 | Double _get_1 = q.get(key); | ||
79 | Double _get_2 = p.get(key); | ||
80 | double _divide = DoubleExtensions.operator_divide(_get_1, _get_2); | ||
81 | double _log = Math.log(_divide); | ||
82 | double _multiply = ((_get).doubleValue() * _log); | ||
83 | double _log_1 = Math.log(2); | ||
84 | double _divide_1 = (_multiply / _log_1); | ||
85 | distance = (_distance - _divide_1); | ||
86 | } | ||
87 | } | ||
88 | return distance; | ||
89 | } | ||
90 | |||
91 | @Override | ||
92 | public double mpcDistance(final List<Double> samples) { | ||
93 | final ToDoubleFunction<Double> _function = (Double it) -> { | ||
94 | return (it).doubleValue(); | ||
95 | }; | ||
96 | HashMap<String, Double> map = this.pmfFromSamples(samples.stream().mapToDouble(_function).toArray(), this.formatter); | ||
97 | int _size = map.size(); | ||
98 | boolean _lessThan = (_size < 2); | ||
99 | if (_lessThan) { | ||
100 | return 1; | ||
101 | } | ||
102 | return this.jsDivergence(map, this.mpcPMF); | ||
103 | } | ||
104 | |||
105 | @Override | ||
106 | public double naDistance(final List<Double> samples) { | ||
107 | final ToDoubleFunction<Double> _function = (Double it) -> { | ||
108 | return (it).doubleValue(); | ||
109 | }; | ||
110 | HashMap<String, Double> map = this.pmfFromSamples(samples.stream().mapToDouble(_function).toArray(), this.formatter); | ||
111 | int _size = map.size(); | ||
112 | boolean _lessThan = (_size < 2); | ||
113 | if (_lessThan) { | ||
114 | return 1; | ||
115 | } | ||
116 | return this.jsDivergence(map, this.naPMF); | ||
117 | } | ||
118 | |||
119 | @Override | ||
120 | public double outDegreeDistance(final List<Double> samples) { | ||
121 | final ToDoubleFunction<Double> _function = (Double it) -> { | ||
122 | return (it).doubleValue(); | ||
123 | }; | ||
124 | HashMap<String, Double> map = this.pmfFromSamples(samples.stream().mapToDouble(_function).toArray(), this.formatter); | ||
125 | int _size = map.size(); | ||
126 | boolean _lessThan = (_size < 2); | ||
127 | if (_lessThan) { | ||
128 | return 1; | ||
129 | } | ||
130 | return this.jsDivergence(map, this.outDegreePMF); | ||
131 | } | ||
132 | |||
133 | public double nodeTypeDistance(final HashMap<String, Double> samples) { | ||
134 | return this.klDivergence(samples, this.nodeTypesPMF); | ||
135 | } | ||
136 | } | ||