@Test public void testFullSearch() throws Exception { int numRows = 1000; int numCols = 100; int numNeighbors = 42; INDArray points = Nd4j.rand(numRows, numCols); VPTree tree = new VPTree(points); INDArray query = Nd4j.rand(new int[] {1, numCols}); VPTreeFillSearch fillSearch = new VPTreeFillSearch(tree, numNeighbors, query); fillSearch.search(); List<DataPoint> results = fillSearch.getResults(); List<Double> distances = fillSearch.getDistances(); assertEquals(numNeighbors, distances.size()); assertEquals(numNeighbors, results.size()); }
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();  }