@Test public void testDistances() { INDArray indArray = Nd4j.create(new float[][]{{3, 4}, {1, 2}, {5, 6}}); INDArray record = Nd4j.create(new float[][]{{7, 6}}); VPTree vpTree = new VPTree(indArray, "euclidean", false); VPTreeFillSearch vpTreeFillSearch = new VPTreeFillSearch(vpTree, 3, record); vpTreeFillSearch.search(); System.out.println(vpTreeFillSearch.getDistances()); }
public List<NearestNeighborsResult> search() { INDArray input = points.slice(record.getInputIndex()); List<NearestNeighborsResult> results = new ArrayList<>(); if (input.isVector()) { List<DataPoint> add = new ArrayList<>(); List<Double> distances = new ArrayList<>(); tree.search(input, record.getK(), add, distances); if (add.size() != distances.size()) { throw new IllegalStateException( String.format("add.size == %d != %d == distances.size", add.size(), distances.size())); } for (int i=0; i<add.size(); i++) { results.add(new NearestNeighborsResult(add.get(i).getIndex(), distances.get(i))); } } return results; }
NearestNeighbor { public List<NearestNeighborsResult> search() { INDArray input = points.slice(record.getInputIndex()); List<NearestNeighborsResult> results = new ArrayList<>(); if (input.isVector()) { List<DataPoint> add = new ArrayList<>(); List<Double> distances = new ArrayList<>(); tree.search(input, record.getK(), add, distances); if (add.size() != distances.size()) { throw new IllegalStateException( String.format("add.size == %d != %d == distances.size", add.size(), distances.size())); } for (int i=0; i<add.size(); i++) { results.add(new NearestNeighborsResult(add.get(i).getIndex(), distances.get(i))); } } return results; } }
NearestNeighbor { public List<NearestNeighborsResult> search() { INDArray input = points.slice(record.getInputIndex()); List<NearestNeighborsResult> results = new ArrayList<>(); if (input.isVector()) { List<DataPoint> add = new ArrayList<>(); List<Double> distances = new ArrayList<>(); tree.search(input, record.getK(), add, distances); if (add.size() != distances.size()) { throw new IllegalStateException( String.format("add.size == %d != %d == distances.size", add.size(), distances.size())); } for (int i=0; i<add.size(); i++) { results.add(new NearestNeighborsResult(add.get(i).getIndex(), distances.get(i))); } } return results; }  }
NearestNeighbor { public List<NearestNeighborsResult> search() { INDArray input = points.slice(record.getInputIndex()); List<NearestNeighborsResult> results = new ArrayList<>(); if (input.isVector()) { List<DataPoint> add = new ArrayList<>(); List<Double> distances = new ArrayList<>(); tree.search(input, record.getK(), add, distances); if (add.size() != distances.size()) { throw new IllegalStateException( String.format("add.size == %d != %d == distances.size", add.size(), distances.size())); } for (int i=0; i<add.size(); i++) { results.add(new NearestNeighborsResult(add.get(i).getIndex(), distances.get(i))); } } return results; }  List<NearestNeighborsResult> search(); }
NearestNeighbor { public List<NearestNeighborsResult> search() { INDArray input = points.slice(record.getInputIndex()); List<NearestNeighborsResult> results = new ArrayList<>(); if (input.isVector()) { List<DataPoint> add = new ArrayList<>(); List<Double> distances = new ArrayList<>(); tree.search(input, record.getK(), add, distances); if (add.size() != distances.size()) { throw new IllegalStateException( String.format("add.size == %d != %d == distances.size", add.size(), distances.size())); } for (int i=0; i<add.size(); i++) { results.add(new NearestNeighborsResult(add.get(i).getIndex(), distances.get(i))); } } return results; }  List<NearestNeighborsResult> search();  }