/** * Add a new Vector to the Searcher that will be checked when getting * the nearest neighbors. * <p/> * The vector IS NOT CLONED. Do not modify the vector externally otherwise the internal * Searcher data structures could be invalidated. */ @Override public void add(Vector vector) { initialize(vector.size()); pendingAdditions.add(vector); }
/** * This iterates on the snapshot of the contents first instantiated regardless of any future modifications. * Changes done after the iterator is created will not be visible to the iterator but will be visible * when searching. * @return iterator through the vectors in this searcher. */ @Override public Iterator<Vector> iterator() { reindex(true); return new AbstractIterator<Vector>() { private final Iterator<WeightedThing<Vector>> data = scalarProjections.get(0).iterator(); @Override protected Vector computeNext() { do { if (!data.hasNext()) { return endOfData(); } WeightedThing<Vector> next = data.next(); if (next.getValue() != null) { return next.getValue(); } } while (true); } }; } }
@Override public boolean remove(Vector vector, double epsilon) { WeightedThing<Vector> closestPair = searchFirst(vector, false); if (distanceMeasure.distance(closestPair.getValue(), vector) > epsilon) { return false;
@Parameters public static List<Object[]> generateData() { return Arrays.asList(new Object[][] { {new ProjectionSearch(new SquaredEuclideanDistanceMeasure(), NUM_PROJECTIONS, SEARCH_SIZE), true}, {new FastProjectionSearch(new SquaredEuclideanDistanceMeasure(), NUM_PROJECTIONS, SEARCH_SIZE), true}, {new ProjectionSearch(new SquaredEuclideanDistanceMeasure(), NUM_PROJECTIONS, SEARCH_SIZE), false}, {new FastProjectionSearch(new SquaredEuclideanDistanceMeasure(), NUM_PROJECTIONS, SEARCH_SIZE), false}, }); }
@Override public boolean remove(Vector vector, double epsilon) { WeightedThing<Vector> closestPair = searchFirst(vector, false); if (distanceMeasure.distance(closestPair.getValue(), vector) > epsilon) { return false;
@Parameterized.Parameters public static List<Object[]> generateData() { RandomUtils.useTestSeed(); Matrix dataPoints = LumpyData.lumpyRandomData(NUM_DATA_POINTS, NUM_DIMENSIONS); Matrix queries = LumpyData.lumpyRandomData(NUM_QUERIES, NUM_DIMENSIONS); DistanceMeasure distanceMeasure = new CosineDistanceMeasure(); Searcher bruteSearcher = new BruteSearch(distanceMeasure); bruteSearcher.addAll(dataPoints); Pair<List<List<WeightedThing<Vector>>>, Long> reference = getResultsAndRuntime(bruteSearcher, queries); Pair<List<WeightedThing<Vector>>, Long> referenceSearchFirst = getResultsAndRuntimeSearchFirst(bruteSearcher, queries); double bruteSearchAvgTime = reference.getSecond() / (queries.numRows() * 1.0); System.out.printf("BruteSearch: avg_time(1 query) %f[s]\n", bruteSearchAvgTime); return Arrays.asList(new Object[][]{ // NUM_PROJECTIONS = 3 // SEARCH_SIZE = 10 {new ProjectionSearch(distanceMeasure, 3, 10), dataPoints, queries, reference, referenceSearchFirst}, {new FastProjectionSearch(distanceMeasure, 3, 10), dataPoints, queries, reference, referenceSearchFirst}, // NUM_PROJECTIONS = 5 // SEARCH_SIZE = 5 {new ProjectionSearch(distanceMeasure, 5, 5), dataPoints, queries, reference, referenceSearchFirst}, {new FastProjectionSearch(distanceMeasure, 5, 5), dataPoints, queries, reference, referenceSearchFirst}, } ); }
/** * This iterates on the snapshot of the contents first instantiated regardless of any future modifications. * Changes done after the iterator is created will not be visible to the iterator but will be visible * when searching. * @return iterator through the vectors in this searcher. */ @Override public Iterator<Vector> iterator() { reindex(true); return new AbstractIterator<Vector>() { private final Iterator<WeightedThing<Vector>> data = scalarProjections.get(0).iterator(); @Override protected Vector computeNext() { do { if (!data.hasNext()) { return endOfData(); } WeightedThing<Vector> next = data.next(); if (next.getValue() != null) { return next.getValue(); } } while (true); } }; } }
/** * Add a new Vector to the Searcher that will be checked when getting * the nearest neighbors. * <p/> * The vector IS NOT CLONED. Do not modify the vector externally otherwise the internal * Searcher data structures could be invalidated. */ @Override public void add(Vector vector) { initialize(vector.size()); pendingAdditions.add(vector); }
@Override public boolean remove(Vector vector, double epsilon) { WeightedThing<Vector> closestPair = searchFirst(vector, false); if (distanceMeasure.distance(closestPair.getValue(), vector) > epsilon) { return false;
@Parameterized.Parameters public static List<Object[]> generateData() { RandomUtils.useTestSeed(); Matrix dataPoints = multiNormalRandomData(NUM_DATA_POINTS, NUM_DIMENSIONS); return Arrays.asList(new Object[][]{ {new ProjectionSearch(new EuclideanDistanceMeasure(), NUM_PROJECTIONS, SEARCH_SIZE), dataPoints}, {new FastProjectionSearch(new EuclideanDistanceMeasure(), NUM_PROJECTIONS, SEARCH_SIZE), dataPoints}, {new LocalitySensitiveHashSearch(new EuclideanDistanceMeasure(), SEARCH_SIZE), dataPoints}, }); }
/** * This iterates on the snapshot of the contents first instantiated regardless of any future modifications. * Changes done after the iterator is created will not be visible to the iterator but will be visible * when searching. * @return iterator through the vectors in this searcher. */ @Override public Iterator<Vector> iterator() { reindex(true); return new AbstractIterator<Vector>() { private final Iterator<WeightedThing<Vector>> data = scalarProjections.get(0).iterator(); @Override protected Vector computeNext() { do { if (!data.hasNext()) { return endOfData(); } WeightedThing<Vector> next = data.next(); if (next.getValue() != null) { return next.getValue(); } } while (true); } }; } }
/** * Add a new Vector to the Searcher that will be checked when getting * the nearest neighbors. * <p/> * The vector IS NOT CLONED. Do not modify the vector externally otherwise the internal * Searcher data structures could be invalidated. */ @Override public void add(Vector vector) { initialize(vector.size()); pendingAdditions.add(vector); }