Feature vectors in X are lumped together as they are read in each document. In kNN, this tends to find features from the same document rather than from across the corpus since we grab k neighbors. For k=11, we might only see exemplars from a single corpus document. If all exemplars fit in k, thi
()
| 164 | * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle |
| 165 | */ |
| 166 | public void randomShuffleInPlace() { |
| 167 | Random r = new Random(); |
| 168 | r.setSeed(FEATURE_VECTOR_RANDOM_SEED); |
| 169 | // for i from n−1 downto 1 do |
| 170 | int n = featureVectors.size(); |
| 171 | for (int i=n-1; i>=1; i--) { |
| 172 | // j ← random integer such that 0 ≤ j ≤ i |
| 173 | int j = r.nextInt(i+1); |
| 174 | // exchange a[j] and a[i] |
| 175 | // Swap X |
| 176 | int[] tmp = featureVectors.get(i); |
| 177 | featureVectors.set(i, featureVectors.get(j)); |
| 178 | featureVectors.set(j, tmp); |
| 179 | // And now swap all prediction lists |
| 180 | Integer tmpI = injectWhitespace.get(i); |
| 181 | injectWhitespace.set(i, injectWhitespace.get(j)); |
| 182 | injectWhitespace.set(j, tmpI); |
| 183 | tmpI = hpos.get(i); |
| 184 | hpos.set(i, hpos.get(j)); |
| 185 | hpos.set(j, tmpI); |
| 186 | // Finally, swap documents |
| 187 | InputDocument tmpD = documentsPerExemplar.get(i); |
| 188 | documentsPerExemplar.set(i, documentsPerExemplar.get(j)); |
| 189 | documentsPerExemplar.set(j, tmpD); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | public void buildTokenContextIndex() { |
| 194 | curAndPrevTokenRuleIndexToExemplarIndexes = new MultiMap<>(); |