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

Method getVotesBag

src/org/antlr/codebuff/kNNClassifier.java:127–145  ·  view source on GitHub ↗
(Neighbor[] kNN, int k, int[] unknown, List<Integer> Y)

Source from the content-addressed store, hash-verified

125 }
126
127 public HashBag<Integer> getVotesBag(Neighbor[] kNN, int k, int[] unknown, List<Integer> Y) {
128 HashBag<Integer> votes = new HashBag<>();
129 for (int i = 0; i<k && i<kNN.length; i++) {
130 votes.add(Y.get(kNN[i].corpusVectorIndex));
131 }
132 if ( dumpVotes && kNN.length>0 ) {
133 System.out.print(Trainer.featureNameHeader(FEATURES));
134 InputDocument firstDoc = corpus.documentsPerExemplar.get(kNN[0].corpusVectorIndex); // pick any neighbor to get parser
135 System.out.println(Trainer._toString(FEATURES, firstDoc, unknown)+"->"+votes);
136 kNN = Arrays.copyOfRange(kNN, 0, Math.min(k, kNN.length));
137 StringBuilder buf = new StringBuilder();
138 for (Neighbor n : kNN) {
139 buf.append(n.toString(FEATURES, Y));
140 buf.append("\n");
141 }
142 System.out.println(buf);
143 }
144 return votes;
145 }
146
147 // get category similarity (1.0-distance) so we can weight votes. Just add up similarity.
148 // I.e., weight votes with similarity 1 (distances of 0) more than votes with lower similarity

Callers 1

votesMethod · 0.95

Calls 8

addMethod · 0.95
featureNameHeaderMethod · 0.95
_toStringMethod · 0.95
printMethod · 0.80
getMethod · 0.65
toStringMethod · 0.65
minMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected