@Test public void testNN() { int n = 10; KDTree kdTree = new KDTree(n); for (int i = -1; i < n; i++) { List<Double> vec = new ArrayList<>(n); for (int k = 0; k < n; k++) { vec.add((k == i) ? 1.0 : 0.0); } INDArray indVec = Nd4j.create(Doubles.toArray(vec), new long[]{1, vec.size()}, DataType.FLOAT); kdTree.insert(indVec); } Random rand = new Random(); List<Double> pt = new ArrayList(n); for (int k = 0; k < n; k++) { pt.add(rand.nextDouble()); } Pair<Double, INDArray> result = kdTree.nn(Nd4j.create(Doubles.toArray(pt), new long[]{1, pt.size()}, DataType.FLOAT)); assertTrue(result.getKey() < Double.MAX_VALUE); }
public Pair<Double, INDArray> nn(INDArray point) { return nn(root, point, rect, Double.POSITIVE_INFINITY, null, 0); }
KDTree implements Serializable { public Pair<Double, INDArray> nn(INDArray point) { return nn(root, point, rect, Double.POSITIVE_INFINITY, null, 0); } }
KDTree implements Serializable { public Pair<Double, INDArray> nn(INDArray point) { return nn(root, point, rect, Double.POSITIVE_INFINITY, null, 0); } KDTree(int dims); }
KDTree implements Serializable { public Pair<Double, INDArray> nn(INDArray point) { return nn(root, point, rect, Double.POSITIVE_INFINITY, null, 0); } KDTree(int dims); void insert(INDArray point); INDArray delete(INDArray point); List<Pair<Float, INDArray>> knn(INDArray point, float distance); Pair<Double, INDArray> nn(INDArray point); int size(); }
KDTree implements Serializable { public Pair<Double, INDArray> nn(INDArray point) { return nn(root, point, rect, Double.POSITIVE_INFINITY, null, 0); } KDTree(int dims); void insert(INDArray point); INDArray delete(INDArray point); List<Pair<Float, INDArray>> knn(INDArray point, float distance); Pair<Double, INDArray> nn(INDArray point); int size(); final static int GREATER; final static int LESS; }