MCPcopy Create free account
hub / github.com/antlr/codebuff / classify

Method classify

src/org/antlr/codebuff/kNNClassifier.java:86–107  ·  view source on GitHub ↗
(int k, int[] unknown, double distanceThreshold)

Source from the content-addressed store, hash-verified

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;

Callers 1

processTokenMethod · 0.45

Calls 5

kNNMethod · 0.95
getMethod · 0.65
putMethod · 0.65

Tested by

no test coverage detected