Neighbor<AbstractSentence, E> neighbor = new Neighbor<>(null, null, 0, Double.MAX_VALUE); for (int i = 0; i < k; i++) { heap.add(neighbor); double distance = HammingDistance.d(fpq, sign); if (distance < heap.peek().distance) { heap.add(new Neighbor<>(keys.get(index), data.get(index), index, distance)); hit++;
@Override public Neighbor<double[], E>[] knn(double[] q, int k) { if (k <= 0) { throw new IllegalArgumentException("Invalid k: " + k); } if (k > keys.length) { throw new IllegalArgumentException("Neighbor array length is larger than the dataset size"); } Neighbor<double[], E> neighbor = new Neighbor<>(null, null, 0, Double.MAX_VALUE); @SuppressWarnings("unchecked") Neighbor<double[], E>[] neighbors = (Neighbor<double[], E>[]) java.lang.reflect.Array.newInstance(neighbor.getClass(), k); HeapSelect<Neighbor<double[], E>> heap = new HeapSelect<>(neighbors); for (int i = 0; i < k; i++) { heap.add(neighbor); neighbor = new Neighbor<>(null, null, 0, Double.MAX_VALUE); } search(q, root, heap); heap.sort(); for (int i = 0; i < neighbors.length; i++) { neighbors[i].distance = Math.sqrt(neighbors[i].distance); } return neighbors; }
for (Node neuron : nodes) { neuron.dist = Math.squaredDistance(neuron.w, x); heap.add(neuron);
HeapSelect<Neighbor<T,T>> heap = new HeapSelect<>(neighbors); for (int i = 0; i < k; i++) { heap.add(neighbor); neighbor = new SimpleNeighbor<>(null, 0, Double.MAX_VALUE);
heap.add(new Neighbor(e.neuron, distance)); hit++;