org.apache.mahout.math.neighborhood
Class BruteSearch

java.lang.Object
  extended by org.apache.mahout.math.neighborhood.Searcher
      extended by org.apache.mahout.math.neighborhood.UpdatableSearcher
          extended by org.apache.mahout.math.neighborhood.BruteSearch
All Implemented Interfaces:
Iterable<Vector>

public class BruteSearch
extends UpdatableSearcher

Search for nearest neighbors using a complete search (i.e. looping through the references and comparing each vector to the query).


Field Summary
 
Fields inherited from class org.apache.mahout.math.neighborhood.Searcher
distanceMeasure
 
Constructor Summary
BruteSearch(DistanceMeasure distanceMeasure)
           
 
Method Summary
 void add(Vector vector)
          Add a new Vector to the Searcher that will be checked when getting the nearest neighbors.
 void clear()
           
 Iterator<Vector> iterator()
           
 boolean remove(Vector query, double epsilon)
           
 List<List<WeightedThing<Vector>>> search(Iterable<WeightedVector> queries, int limit, int numThreads)
          Searches with a list full of queries in a threaded fashion.
 List<WeightedThing<Vector>> search(Vector query, int limit)
          Scans the list of reference vectors one at a time for @limit neighbors of the query vector.
 WeightedThing<Vector> searchFirst(Vector query, boolean differentThanQuery)
          Returns the closest vector to the query.
 int size()
          Returns the number of WeightedVectors being searched for nearest neighbors.
 
Methods inherited from class org.apache.mahout.math.neighborhood.Searcher
addAll, addAllMatrixSlices, addAllMatrixSlicesAsWeightedVectors, getCandidateQueue, getDistanceMeasure, search, searchFirst
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BruteSearch

public BruteSearch(DistanceMeasure distanceMeasure)
Method Detail

add

public void add(Vector vector)
Description copied from class: Searcher
Add a new Vector to the Searcher that will be checked when getting the nearest neighbors. The vector IS NOT CLONED. Do not modify the vector externally otherwise the internal Searcher data structures could be invalidated.

Specified by:
add in class Searcher

size

public int size()
Description copied from class: Searcher
Returns the number of WeightedVectors being searched for nearest neighbors.

Specified by:
size in class Searcher

search

public List<WeightedThing<Vector>> search(Vector query,
                                          int limit)
Scans the list of reference vectors one at a time for @limit neighbors of the query vector. The weights of the WeightedVectors are not taken into account.

Specified by:
search in class Searcher
Parameters:
query - The query vector.
limit - The number of results to returned; must be at least 1.
Returns:
A list of the closest @limit neighbors for the given query.

searchFirst

public WeightedThing<Vector> searchFirst(Vector query,
                                         boolean differentThanQuery)
Returns the closest vector to the query. When only one the nearest vector is needed, use this method, NOT search(query, limit) because it's faster (less overhead).

Specified by:
searchFirst in class Searcher
Parameters:
query - the vector to search for
differentThanQuery - if true, returns the closest vector different than the query (this only matters if the query is among the searched vectors), otherwise, returns the closest vector to the query (even the same vector).
Returns:
the weighted vector closest to the query

search

public List<List<WeightedThing<Vector>>> search(Iterable<WeightedVector> queries,
                                                int limit,
                                                int numThreads)
                                         throws InterruptedException
Searches with a list full of queries in a threaded fashion.

Parameters:
queries - The queries to search for.
limit - The number of results to return.
numThreads - Number of threads to use in searching.
Returns:
A list of result lists.
Throws:
InterruptedException

iterator

public Iterator<Vector> iterator()

remove

public boolean remove(Vector query,
                      double epsilon)
Specified by:
remove in class UpdatableSearcher

clear

public void clear()
Specified by:
clear in class UpdatableSearcher


Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.