@Test public void testKNN_4() { float[] data = new float[]{2, 3}; List<Pair<Float, INDArray>> result = kdTree.knn(Nd4j.createFromArray(data), 5.0f); assertEquals(2.0, result.get(0).getSecond().getFloat(0), 1e-5); assertEquals(3.0, result.get(0).getSecond().getFloat(1), 1e-5); assertEquals(5.0, result.get(1).getSecond().getFloat(0), 1e-5); assertEquals(4.0, result.get(1).getSecond().getFloat(1), 1e-5); assertEquals(4.0, result.get(2).getSecond().getFloat(0), 1e-5); assertEquals(7.0, result.get(2).getSecond().getFloat(1), 1e-5); }
public List<Pair<Float, INDArray>> knn(INDArray point, float distance) { List<Pair<Float, INDArray>> best = new ArrayList<>(); currentDistance = distance; currentPoint = point; knn(root, rect, best, 0); Collections.sort(best, new Comparator<Pair<Float, INDArray>>() { @Override public int compare(Pair<Float, INDArray> o1, Pair<Float, INDArray> o2) { return Float.compare(o1.getKey(), o2.getKey()); } }); return best; }
KDTree implements Serializable { public List<Pair<Float, INDArray>> knn(INDArray point, float distance) { List<Pair<Float, INDArray>> best = new ArrayList<>(); currentDistance = distance; currentPoint = point; knn(root, rect, best, 0); Collections.sort(best, new Comparator<Pair<Float, INDArray>>() { @Override public int compare(Pair<Float, INDArray> o1, Pair<Float, INDArray> o2) { return Float.compare(o1.getKey(), o2.getKey()); } }); return best; } }
KDTree implements Serializable { public List<Pair<Float, INDArray>> knn(INDArray point, float distance) { List<Pair<Float, INDArray>> best = new ArrayList<>(); currentDistance = distance; currentPoint = point; knn(root, rect, best, 0); Collections.sort(best, new Comparator<Pair<Float, INDArray>>() { @Override public int compare(Pair<Float, INDArray> o1, Pair<Float, INDArray> o2) { return Float.compare(o1.getKey(), o2.getKey()); } }); return best; } KDTree(int dims); }
KDTree implements Serializable { public List<Pair<Float, INDArray>> knn(INDArray point, float distance) { List<Pair<Float, INDArray>> best = new ArrayList<>(); currentDistance = distance; currentPoint = point; knn(root, rect, best, 0); Collections.sort(best, new Comparator<Pair<Float, INDArray>>() { @Override public int compare(Pair<Float, INDArray> o1, Pair<Float, INDArray> o2) { return Float.compare(o1.getKey(), o2.getKey()); } }); return best; } 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 List<Pair<Float, INDArray>> knn(INDArray point, float distance) { List<Pair<Float, INDArray>> best = new ArrayList<>(); currentDistance = distance; currentPoint = point; knn(root, rect, best, 0); Collections.sort(best, new Comparator<Pair<Float, INDArray>>() { @Override public int compare(Pair<Float, INDArray> o1, Pair<Float, INDArray> o2) { return Float.compare(o1.getKey(), o2.getKey()); } }); return best; } 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; }