@Test public void testNearestNeighbors() { NearestNeighbors<ClusterablePoint> tree = new NearestNeighbors<>(setupTree(), new EuclideanDistance()); ClusterablePoint a = new ClusterablePoint(3, 3); ClusterablePoint b = new ClusterablePoint(5, 9); ClusterablePoint c = new ClusterablePoint(8, 4); List<ClusterablePoint> nearest = tree.nearest(a, 3).toList(); assertEquals(3, nearest.size()); assertTrue(nearest.contains(aPoints.get(0))); assertTrue(nearest.contains(aPoints.get(1))); assertTrue(nearest.contains(aPoints.get(2))); nearest = tree.nearest(a, 5).toList(); assertEquals(5, nearest.size()); assertEquals(new HashSet<>(aPoints), new HashSet<>(nearest)); nearest = tree.nearest(b, 5).toList(); assertEquals(5, nearest.size()); assertEquals(new HashSet<>(bPoints), new HashSet<>(nearest)); nearest = tree.nearest(c, 4).toList(); assertEquals(4, nearest.size()); assertEquals(new HashSet<>(cPoints), new HashSet<>(nearest)); }
public MaxHeap<T> nearest(double[] point, double maxDist, DistanceMetric metric) { final BinaryHeap.Min<KDNode<T>> paths = new BinaryHeap.Min<>(); final BinaryHeap.Max<T> points = new BinaryHeap.Max<>(); paths.offer(0, root); do { searchNeighbors(paths, points, maxDist, metric, point); } while (paths.size() > 0 && (paths.getMinKey() < maxDist)); return points; }
KDTree { public MaxHeap<T> nearest(double[] point, double maxDist, DistanceMetric metric) { final BinaryHeap.Min<KDNode<T>> paths = new BinaryHeap.Min<>(); final BinaryHeap.Max<T> points = new BinaryHeap.Max<>(); paths.offer(0, root); do { searchNeighbors(paths, points, maxDist, metric, point); } while (paths.size() > 0 && (paths.getMinKey() < maxDist)); return points; } }
KDTree { public MaxHeap<T> nearest(double[] point, double maxDist, DistanceMetric metric) { final BinaryHeap.Min<KDNode<T>> paths = new BinaryHeap.Min<>(); final BinaryHeap.Max<T> points = new BinaryHeap.Max<>(); paths.offer(0, root); do { searchNeighbors(paths, points, maxDist, metric, point); } while (paths.size() > 0 && (paths.getMinKey() < maxDist)); return points; } KDTree(int dimensions);  KDTree(int dimensions, int bucketCapacity); }
KDTree { public MaxHeap<T> nearest(double[] point, double maxDist, DistanceMetric metric) { final BinaryHeap.Min<KDNode<T>> paths = new BinaryHeap.Min<>(); final BinaryHeap.Max<T> points = new BinaryHeap.Max<>(); paths.offer(0, root); do { searchNeighbors(paths, points, maxDist, metric, point); } while (paths.size() > 0 && (paths.getMinKey() < maxDist)); return points; } KDTree(int dimensions);  KDTree(int dimensions, int bucketCapacity); void addPoint(double[] point, T value); NearestNeighborIterator<T> getNearestNeighborIterator(double[] point, int maxPoints, DistanceMetric metric); MaxHeap<T> nearest(double[] point, double maxDist, DistanceMetric metric); MaxHeap<T> nearest(double[] searchPoint, int maxPoints, DistanceMetric metric); static KDTree<T> createTree(Iterable<T> points, int dimensionality); static KDTree<T> createTree(List<T> points); }
KDTree { public MaxHeap<T> nearest(double[] point, double maxDist, DistanceMetric metric) { final BinaryHeap.Min<KDNode<T>> paths = new BinaryHeap.Min<>(); final BinaryHeap.Max<T> points = new BinaryHeap.Max<>(); paths.offer(0, root); do { searchNeighbors(paths, points, maxDist, metric, point); } while (paths.size() > 0 && (paths.getMinKey() < maxDist)); return points; } KDTree(int dimensions);  KDTree(int dimensions, int bucketCapacity); void addPoint(double[] point, T value); NearestNeighborIterator<T> getNearestNeighborIterator(double[] point, int maxPoints, DistanceMetric metric); MaxHeap<T> nearest(double[] point, double maxDist, DistanceMetric metric); MaxHeap<T> nearest(double[] searchPoint, int maxPoints, DistanceMetric metric); static KDTree<T> createTree(Iterable<T> points, int dimensionality); static KDTree<T> createTree(List<T> points);  }