@Test public void testNearest() { System.out.println("nearest"); int recall = 0; double error = 0.0; int hit = 0; for (int i = 0; i < testx.length; i++) { Neighbor neighbor = lsh.nearest(testx[i]); if (neighbor != null) { hit++; Neighbor truth = naive.nearest(testx[i]); if (neighbor.index == truth.index) { recall++; } else { error += Math.abs(neighbor.distance - truth.distance) / truth.distance; } } } error /= (hit - recall); assertEquals(1154, recall); assertEquals(2007, hit); assertEquals(0.1305, error, 1E-4); System.out.format("recall is %.2f%%%n", 100.0 * recall / testx.length); System.out.format("error when miss is %.2f%%%n", 100.0 * error); System.out.format("null rate is %.2f%%%n", 100.0 - 100.0 * hit / testx.length); }
@Override public Neighbor<double[], E> nearest(double[] q) { int index = -1; double nearest = Double.MAX_VALUE; for (int i : getCandidates(q)) { double[] x = keys.get(i); if (q != x) { double distance = MathEx.distance(q, x); if (distance < nearest) { index = i; nearest = distance; } } } return index == -1 ? null : new Neighbor<>(keys.get(index), data.get(index), index, nearest); }
LSH implements NearestNeighborSearch<double[], E>, KNNSearch<double[], E>, RNNSearch<double[], E>, Serializable { @Override public Neighbor<double[], E> nearest(double[] q) { int index = -1; double nearest = Double.MAX_VALUE; for (int i : getCandidates(q)) { double[] x = keys.get(i); if (q != x) { double distance = MathEx.distance(q, x); if (distance < nearest) { index = i; nearest = distance; } } } return index == -1 ? null : new Neighbor<>(keys.get(index), data.get(index), index, nearest); } }
LSH implements NearestNeighborSearch<double[], E>, KNNSearch<double[], E>, RNNSearch<double[], E>, Serializable { @Override public Neighbor<double[], E> nearest(double[] q) { int index = -1; double nearest = Double.MAX_VALUE; for (int i : getCandidates(q)) { double[] x = keys.get(i); if (q != x) { double distance = MathEx.distance(q, x); if (distance < nearest) { index = i; nearest = distance; } } } return index == -1 ? null : new Neighbor<>(keys.get(index), data.get(index), index, nearest); } LSH(double[][] keys, E[] data, double w);  LSH(double[][] keys, E[] data, double w, int H);  LSH(int d, int L, int k, double w);  LSH(int d, int L, int k, double w, int H); }
LSH implements NearestNeighborSearch<double[], E>, KNNSearch<double[], E>, RNNSearch<double[], E>, Serializable { @Override public Neighbor<double[], E> nearest(double[] q) { int index = -1; double nearest = Double.MAX_VALUE; for (int i : getCandidates(q)) { double[] x = keys.get(i); if (q != x) { double distance = MathEx.distance(q, x); if (distance < nearest) { index = i; nearest = distance; } } } return index == -1 ? null : new Neighbor<>(keys.get(index), data.get(index), index, nearest); } LSH(double[][] keys, E[] data, double w);  LSH(double[][] keys, E[] data, double w, int H);  LSH(int d, int L, int k, double w);  LSH(int d, int L, int k, double w, int H); @Override String toString(); void put(double[] key, E value); @Override Neighbor<double[], E> nearest(double[] q); @Override @SuppressWarnings("unchecked") Neighbor<double[], E>[] knn(double[] q, int k); @Override void range(double[] q, double radius, List<Neighbor<double[], E>> neighbors); }
LSH implements NearestNeighborSearch<double[], E>, KNNSearch<double[], E>, RNNSearch<double[], E>, Serializable { @Override public Neighbor<double[], E> nearest(double[] q) { int index = -1; double nearest = Double.MAX_VALUE; for (int i : getCandidates(q)) { double[] x = keys.get(i); if (q != x) { double distance = MathEx.distance(q, x); if (distance < nearest) { index = i; nearest = distance; } } } return index == -1 ? null : new Neighbor<>(keys.get(index), data.get(index), index, nearest); } LSH(double[][] keys, E[] data, double w);  LSH(double[][] keys, E[] data, double w, int H);  LSH(int d, int L, int k, double w);  LSH(int d, int L, int k, double w, int H); @Override String toString(); void put(double[] key, E value); @Override Neighbor<double[], E> nearest(double[] q); @Override @SuppressWarnings("unchecked") Neighbor<double[], E>[] knn(double[] q, int k); @Override void range(double[] q, double radius, List<Neighbor<double[], E>> neighbors);  }