@Test public void testNearestNeighborsDistance() { 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); Pair<ClusterablePoint, Double> max = tree.nearestWithDistance(a, 1).getFirst(); assertEquals(aPoints.get(1), max.first()); assertEquals(0.5, max.second(), 0.00001); max = tree.nearestWithDistance(b, 1).getFirst(); assertEquals(bPoints.get(0), max.first()); assertEquals(sqrt(2) / 2, max.second(), 0.00001); max = tree.nearestWithDistance(c, 1).getFirst(); assertEquals(cPoints.get(1), max.first()); assertEquals(sqrt(2), max.second(), 0.00001); List<Pair<ClusterablePoint, Double>> points = tree.nearestWithDistance(a, sqrt(3)).toList(); assertEquals(3, points.size()); assertEquals(aPoints.get(2), points.get(0).first()); assertEquals(aPoints.get(0), points.get(1).first()); assertEquals(aPoints.get(1), points.get(2).first()); List<ClusterablePoint> n = tree.nearest(a, 3).toList(); assertEquals(3, n.size()); assertEquals(aPoints.get(2), n.get(0)); assertEquals(aPoints.get(0), n.get(1)); assertEquals(aPoints.get(1), n.get(2)); n = tree.nearest(a, sqrt(3)).toList(); assertEquals(3, n.size()); assertEquals(aPoints.get(2), n.get(0)); assertEquals(aPoints.get(0), n.get(1)); assertEquals(aPoints.get(1), n.get(2)); }
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);  }