de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.query
Class DoubleDistanceRStarTreeKNNQuery<O extends SpatialComparable>

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.database.query.AbstractDataBasedQuery<O>
      extended by de.lmu.ifi.dbs.elki.database.query.knn.AbstractDistanceKNNQuery<O,DoubleDistance>
          extended by de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.query.DoubleDistanceRStarTreeKNNQuery<O>
All Implemented Interfaces:
DatabaseQuery, KNNQuery<O,DoubleDistance>

public class DoubleDistanceRStarTreeKNNQuery<O extends SpatialComparable>
extends AbstractDistanceKNNQuery<O,DoubleDistance>

Instance of a KNN query for a particular spatial index.


Nested Class Summary
(package private)  class DoubleDistanceRStarTreeKNNQuery.DoubleDistanceEntry
          Optimized double distance entry implementation.
 
Field Summary
protected  SpatialPrimitiveDoubleDistanceFunction<? super O> distanceFunction
          Spatial primitive distance function
protected  AbstractRStarTree<?,?> tree
          The index to use
 
Fields inherited from class de.lmu.ifi.dbs.elki.database.query.knn.AbstractDistanceKNNQuery
distanceQuery
 
Fields inherited from class de.lmu.ifi.dbs.elki.database.query.AbstractDataBasedQuery
relation
 
Fields inherited from interface de.lmu.ifi.dbs.elki.database.query.DatabaseQuery
HINT_BULK, HINT_EXACT, HINT_HEAVY_USE, HINT_NO_CACHE, HINT_OPTIMIZED_ONLY, HINT_SINGLE
 
Constructor Summary
DoubleDistanceRStarTreeKNNQuery(AbstractRStarTree<?,?> tree, DistanceQuery<O,DoubleDistance> distanceQuery, SpatialPrimitiveDoubleDistanceFunction<? super O> distanceFunction)
          Constructor.
 
Method Summary
protected  void batchNN(AbstractRStarTreeNode<?,?> node, Map<DBID,KNNHeap<DoubleDistance>> knnLists)
          Performs a batch knn query.
protected  void doKNNQuery(O object, KNNHeap<DoubleDistance> knnList)
          Performs a k-nearest neighbor query for the given NumberVector with the given parameter k and the according distance function.
 DoubleDistance getDistanceFactory()
          Get the distance data type of the function.
 List<List<DistanceResultPair<DoubleDistance>>> getKNNForBulkDBIDs(ArrayDBIDs ids, int k)
          Bulk query method
 void getKNNForBulkHeaps(Map<DBID,KNNHeap<DoubleDistance>> heaps)
          Bulk query method configured by a map.
 List<DistanceResultPair<DoubleDistance>> getKNNForDBID(DBID id, int k)
          Get the k nearest neighbors for a particular id.
 List<DistanceResultPair<DoubleDistance>> getKNNForObject(O obj, int k)
          Get the k nearest neighbors for a particular id.
protected  List<DoubleDistanceRStarTreeKNNQuery.DoubleDistanceEntry> getSortedEntries(AbstractRStarTreeNode<?,?> node, DBIDs ids)
          Sorts the entries of the specified node according to their minimum distance to the specified objects.
 
Methods inherited from class de.lmu.ifi.dbs.elki.database.query.knn.AbstractDistanceKNNQuery
getDistanceQuery
 
Methods inherited from class de.lmu.ifi.dbs.elki.database.query.AbstractDataBasedQuery
getRelation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.lmu.ifi.dbs.elki.database.query.knn.KNNQuery
getRelation
 

Field Detail

tree

protected final AbstractRStarTree<?,?> tree
The index to use


distanceFunction

protected final SpatialPrimitiveDoubleDistanceFunction<? super O extends SpatialComparable> distanceFunction
Spatial primitive distance function

Constructor Detail

DoubleDistanceRStarTreeKNNQuery

public DoubleDistanceRStarTreeKNNQuery(AbstractRStarTree<?,?> tree,
                                       DistanceQuery<O,DoubleDistance> distanceQuery,
                                       SpatialPrimitiveDoubleDistanceFunction<? super O> distanceFunction)
Constructor.

Parameters:
tree - Index to use
distanceQuery - Distance query to use
distanceFunction - Distance function
Method Detail

doKNNQuery

protected void doKNNQuery(O object,
                          KNNHeap<DoubleDistance> knnList)
Performs a k-nearest neighbor query for the given NumberVector with the given parameter k and the according distance function. The query result is in ascending order to the distance to the query object.

Parameters:
object - the query object
knnList - the knn list containing the result

batchNN

protected void batchNN(AbstractRStarTreeNode<?,?> node,
                       Map<DBID,KNNHeap<DoubleDistance>> knnLists)
Performs a batch knn query.

Parameters:
node - the node for which the query should be performed
knnLists - a map containing the knn lists for each query objects

getSortedEntries

protected List<DoubleDistanceRStarTreeKNNQuery.DoubleDistanceEntry> getSortedEntries(AbstractRStarTreeNode<?,?> node,
                                                                                     DBIDs ids)
Sorts the entries of the specified node according to their minimum distance to the specified objects.

Parameters:
node - the node
ids - the id of the objects
Returns:
a list of the sorted entries

getKNNForObject

public List<DistanceResultPair<DoubleDistance>> getKNNForObject(O obj,
                                                                int k)
Description copied from interface: KNNQuery
Get the k nearest neighbors for a particular id.

Specified by:
getKNNForObject in interface KNNQuery<O extends SpatialComparable,DoubleDistance>
Specified by:
getKNNForObject in class AbstractDistanceKNNQuery<O extends SpatialComparable,DoubleDistance>
Parameters:
obj - Query object
k - Number of neighbors requested
Returns:
neighbors

getKNNForDBID

public List<DistanceResultPair<DoubleDistance>> getKNNForDBID(DBID id,
                                                              int k)
Description copied from interface: KNNQuery
Get the k nearest neighbors for a particular id.

Specified by:
getKNNForDBID in interface KNNQuery<O extends SpatialComparable,DoubleDistance>
Specified by:
getKNNForDBID in class AbstractDistanceKNNQuery<O extends SpatialComparable,DoubleDistance>
Parameters:
id - query object ID
k - Number of neighbors requested
Returns:
neighbors

getKNNForBulkDBIDs

public List<List<DistanceResultPair<DoubleDistance>>> getKNNForBulkDBIDs(ArrayDBIDs ids,
                                                                         int k)
Description copied from interface: KNNQuery
Bulk query method

Parameters:
ids - query object IDs
k - Number of neighbors requested
Returns:
neighbors

getKNNForBulkHeaps

public void getKNNForBulkHeaps(Map<DBID,KNNHeap<DoubleDistance>> heaps)
Description copied from interface: KNNQuery
Bulk query method configured by a map. Warning: this API is not optimal, and might be removed soon (in fact, it is used in a single place)

Parameters:
heaps - Map of heaps to fill.

getDistanceFactory

public DoubleDistance getDistanceFactory()
Description copied from interface: KNNQuery
Get the distance data type of the function.

Specified by:
getDistanceFactory in interface KNNQuery<O extends SpatialComparable,DoubleDistance>
Overrides:
getDistanceFactory in class AbstractDistanceKNNQuery<O extends SpatialComparable,DoubleDistance>

Release 0.4.0 (2011-09-20_1324)