Permalink
Browse files

similarity distance

  • Loading branch information...
1 parent 81d708f commit 540151d572daac80a5232c7c9b00400d784422a0 @sontek sontek committed Mar 24, 2012
Showing with 10 additions and 9 deletions.
  1. +6 −5 src/com/trinity/stooges/KNN.java
  2. +4 −4 src/com/trinity/stooges/ValueComparator.java
@@ -7,20 +7,21 @@
class KNN {
public ArrayList<String> closestNeighbour(SongEntity seed_song, SongEntity[] songs, int number) {
- HashMap<String,Double> map = new HashMap<String,Double>();
+ HashMap<String,Float> map = new HashMap<String,Float>();
ValueComparator bvc = new ValueComparator(map);
- TreeMap<String,Double> sorted_map = new TreeMap<String, Double>(bvc);
+ TreeMap<String,Float> sorted_map = new TreeMap<String, Float>(bvc);
ArrayList<String> distances = new ArrayList<String>();
for (int i = 0; i < songs.length; i++) {
- map.put(songs[i].get_id(), (double) computeDistance(seed_song, songs[i]));
+ map.put(songs[i].get_id(), (float) computeDistance(seed_song, songs[i]));
}
sorted_map.putAll(map);
- sorted_map.descendingMap();
+// sorted_map.descendingMap();
int count = 0;
for (String key :sorted_map.keySet()) {
- if(count != number) {
+ if(count >= (songs.length - number)) {
distances.add(key);
}
+ count++;
}
return distances;
}
@@ -5,16 +5,16 @@
public class ValueComparator implements Comparator<Object> {
- Map<String, Double> base;
- public ValueComparator(Map<String, Double> base) {
+ Map<String, Float> base;
+ public ValueComparator(Map<String, Float> base) {
this.base = base;
}
public int compare(Object a, Object b) {
- if((Double)base.get(a) < (Double)base.get(b)) {
+ if((Float)base.get(a) < (Float)base.get(b)) {
return 1;
}
- else if((Double)base.get(a) == (Double)base.get(b)) {
+ else if((Float)base.get(a) == (Float)base.get(b)) {
return 0;
}
else {

0 comments on commit 540151d

Please sign in to comment.