Skip to content

Commit a35fbd2

Browse files
committed
no message
1 parent f3788f0 commit a35fbd2

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/main/java/com/github/felipexw/classifiers/neighbors/SimpleKNNClassifier.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,17 @@ protected void calculateFeatureSimilarities() {
136136
}
137137

138138
protected List<Neighbor> getNeighborsWithDistanceFromARootNeighboor(Neighbor neighbor, int threshold) {
139-
140-
141-
// LabeledInstance<Double, String> t = new LabeledInstance<>("2");
142-
143-
144139
Neighbor nei = new Neighbor(null, 0d, featureExtractor);
145140
List<Neighbor> neighbors = new ArrayList<>();
146141

147142
LabeledInstance instance = neighbor.getInstance();
148143

149144
for (int j = -1; j < instances.size() - 1; j++) {
150145
LabeledInstance neighborInstance = instances.get(j + 1);
151-
// double similarity = similarityCalculator.calculate(instance.getFeatures(), neighborInstance.getFeatures());
152-
double similarity = 0d;
146+
double similarity = similarityCalculator.calculate(instance.getFeatures(), neighborInstance.getFeatures());
153147
Neighbor neighborRoot = new Neighbor(neighborInstance, similarity, new DoubleFeatureExtractor());
154148
neighbors.add(neighborRoot);
149+
155150
if (neighbors.size() == threshold)
156151
return neighbors;
157152
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.github.felipexw.evaluations.metrics;
22

3+
import java.util.List;
4+
35
/**
46
* Created by felipe.appio on 30/08/2016.
57
*/
68
public class ChebyshevSimilarityCalculator implements SimilarityCalculator{
79
@Override
8-
public double calculate(double[] a, double[] b) {
10+
public double calculate(List<Double> a, List<Double> b) {
911
return 0;
1012
}
1113
}

src/main/java/com/github/felipexw/evaluations/metrics/CosineSimilarityCalculator.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
package com.github.felipexw.evaluations.metrics;
22

3+
import java.util.List;
4+
35
/**
46
* Created by felipe.appio on 25/08/2016.
57
*/
68
public class CosineSimilarityCalculator implements SimilarityCalculator{
79
@Override
8-
public double calculate(double[] a, double[] b) {
9-
if (a == null || b == null || (a.length != b.length))
10-
throw new IllegalArgumentException("args can't be invalid");
10+
public double calculate(List<Double> a, List<Double> b) {
11+
if (a == null || a.isEmpty() || (a.size()!= b.size()))
12+
throw new IllegalArgumentException("The params can't be null or empty.");
1113

1214
double numerator = 0d;
1315
double denominator = 0d;
1416
double aFeatures = 0d;
1517
double bFeatures = 0d;
1618

17-
for(int i =0; i < a.length; i++){
18-
numerator += a[i] * b[i];
19-
denominator += (Math.pow(a[i], 2)) * (Math.pow(b[i], 2));
19+
for(int i =0; i < a.size(); i++){
20+
numerator += a.get(i) * b.get(i);
21+
denominator += (Math.pow(a.get(i), 2)) * (Math.pow(a.get(i), 2));
2022
}
2123

2224
// denominator = (Math.sqrt(aFeatures)) * (Math.sqrt(bFeatures));

0 commit comments

Comments
 (0)