@Test public void testNearest() { System.out.println("nearest"); double[][] data = Matrix.randn(1000, 10).toArray(); CoverTree<double[]> coverTree = new CoverTree<>(data, new EuclideanDistance()); LinearSearch<double[]> naive = new LinearSearch<>(data, new EuclideanDistance()); for (int i = 0; i < data.length; i++) { Neighbor n1 = coverTree.nearest(data[i]); Neighbor n2 = naive.nearest(data[i]); assertEquals(n1.index, n2.index); assertEquals(n1.value, n2.value); assertEquals(n1.distance, n2.distance, 1E-7); } }
@Override public Neighbor<E, E> nearest(E q) { return knn(q, 1)[0]; }
CoverTree implements NearestNeighborSearch<E, E>, KNNSearch<E, E>, RNNSearch<E, E>, Serializable { @Override public Neighbor<E, E> nearest(E q) { return knn(q, 1)[0]; } }
CoverTree implements NearestNeighborSearch<E, E>, KNNSearch<E, E>, RNNSearch<E, E>, Serializable { @Override public Neighbor<E, E> nearest(E q) { return knn(q, 1)[0]; } CoverTree(E[] dataset, Metric<E> distance);  CoverTree(E[] dataset, Metric<E> distance, double base); }
CoverTree implements NearestNeighborSearch<E, E>, KNNSearch<E, E>, RNNSearch<E, E>, Serializable { @Override public Neighbor<E, E> nearest(E q) { return knn(q, 1)[0]; } CoverTree(E[] dataset, Metric<E> distance);  CoverTree(E[] dataset, Metric<E> distance, double base); @Override String toString(); @Override Neighbor<E, E> nearest(E q); @Override Neighbor<E, E>[] knn(E q, int k); @Override void range(E q, double radius, List<Neighbor<E, E>> neighbors); }
CoverTree implements NearestNeighborSearch<E, E>, KNNSearch<E, E>, RNNSearch<E, E>, Serializable { @Override public Neighbor<E, E> nearest(E q) { return knn(q, 1)[0]; } CoverTree(E[] dataset, Metric<E> distance);  CoverTree(E[] dataset, Metric<E> distance, double base); @Override String toString(); @Override Neighbor<E, E> nearest(E q); @Override Neighbor<E, E>[] knn(E q, int k); @Override void range(E q, double radius, List<Neighbor<E, E>> neighbors);  }