(int k, int[] unknown, double distanceThreshold)
| 84 | } |
| 85 | |
| 86 | public int classify(int k, int[] unknown, double distanceThreshold) { |
| 87 | FeatureVectorAsObject key = new FeatureVectorAsObject(unknown, FEATURES); |
| 88 | Integer catI = classifyCache.get(key); |
| 89 | nClassifyCalls++; |
| 90 | if ( catI!=null ) { |
| 91 | nClassifyCacheHits++; |
| 92 | return catI; |
| 93 | } |
| 94 | Neighbor[] kNN = kNN(unknown, k, distanceThreshold); |
| 95 | Map<Integer,MutableDouble> similarities = getCategoryToSimilarityMap(kNN, k, Y); |
| 96 | int cat = getCategoryWithMaxValue(similarities); |
| 97 | |
| 98 | if ( cat==-1 ) { |
| 99 | // try with less strict match threshold to get some indication of alignment |
| 100 | kNN = kNN(unknown, k, MAX_CONTEXT_DIFF_THRESHOLD2); |
| 101 | similarities = getCategoryToSimilarityMap(kNN, k, Y); |
| 102 | cat = getCategoryWithMaxValue(similarities); |
| 103 | } |
| 104 | |
| 105 | classifyCache.put(key, cat); |
| 106 | return cat; |
| 107 | } |
| 108 | |
| 109 | public static int getCategoryWithMostVotes(HashBag<Integer> votes) { |
| 110 | int max = Integer.MIN_VALUE; |
no test coverage detected