Class RdKNNTree<O extends NumberVector>
- java.lang.Object
-
- elki.index.tree.IndexTree<N,E>
-
- elki.index.tree.spatial.rstarvariants.AbstractRStarTree<N,E,S>
-
- elki.index.tree.spatial.rstarvariants.NonFlatRStarTree<RdKNNNode,RdKNNEntry,RdkNNSettings>
-
- elki.index.tree.spatial.rstarvariants.rdknn.RdKNNTree<O>
-
- Type Parameters:
O- Object type
- All Implemented Interfaces:
DistancePriorityIndex<O>,DynamicIndex,Index,KNNIndex<O>,RangeIndex<O>,RKNNIndex<O>
public class RdKNNTree<O extends NumberVector> extends NonFlatRStarTree<RdKNNNode,RdKNNEntry,RdkNNSettings> implements DistancePriorityIndex<O>, RKNNIndex<O>, DynamicIndex
RDkNNTree is a spatial index structure based on the concepts of the R*-Tree supporting efficient processing of reverse k nearest neighbor queries. The k-nn distance is stored in each entry of a node.FIXME: currently does not have a RkNN implementation!
- Since:
- 0.1
- Author:
- Elke Achtert
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class elki.index.tree.spatial.rstarvariants.AbstractRStarTree
AbstractRStarTree.Statistics
-
-
Field Summary
Fields Modifier and Type Field Description private SpatialDistanceQuery<O>distanceQueryThe distance function.protected KNNSearcher<DBIDRef>knnQueryInternal knn query object, for updating the rKNN.private static LoggingLOGThe logger for this class.private Relation<O>relationThe relation we query.-
Fields inherited from class elki.index.tree.spatial.rstarvariants.AbstractRStarTree
EXTRA_INTEGRITY_CHECKS, height, settings, statistics
-
Fields inherited from class elki.index.tree.IndexTree
dirCapacity, dirMinimum, initialized, leafCapacity, leafMinimum
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidadjustKNNDistances(RdKNNEntry entry, ArrayDBIDs ids, double[] kdists)Adjusts the knn distance in the subtree of the specified root entry.protected voidbulkLoad(java.util.List<RdKNNEntry> entries)Performs a bulk load on this RTree with the specified data.private voidcheckDistance(SpatialPrimitiveDistance<? super O> distance)Throws an IllegalArgumentException if the specified distance function is not an instance of the distance function used by this index.protected TreeIndexHeadercreateHeader()Creates a header for this index structure which is an instance ofTreeIndexHeader.protected RdKNNEntrycreateNewDirectoryEntry(RdKNNNode node)Creates a new directory entry representing the specified node.protected RdKNNNodecreateNewDirectoryNode()Creates a new directory node with the specified capacity.protected RdKNNLeafEntrycreateNewLeafEntry(DBID id)protected RdKNNNodecreateNewLeafNode()Creates a new leaf node with the specified capacity.protected RdKNNEntrycreateRootEntry()Creates an entry representing the root node.booleandelete(DBIDRef id)Deletes the specified object from this index.voiddeleteAll(DBIDs ids)Deletes the specified objects from this index.private voiddoReverseKNN(RdKNNNode node, DBID oid, ModifiableDoubleDBIDList result)Performs a reverse knn query in the specified subtree.protected LogginggetLogger()Get the (STATIC) logger for this class.protected java.util.List<DoubleObjPair<RdKNNEntry>>getSortedEntries(AbstractRStarTreeNode<?,?> node, SpatialComparable q, SpatialPrimitiveDistance<?> distance)Sorts the entries of the specified node according to their minimum distance to the specified object.voidinitialize()Initialize the tree if the page file already existed.protected voidinitializeCapacities(RdKNNEntry exampleLeaf)Determines the maximum and minimum number of entries in a node.voidinsert(DBIDRef id)Inserts the specified real vector object into this index.voidinsertAll(DBIDs ids)Inserts the specified objects into this index.KNNSearcher<O>kNNByObject(DistanceQuery<O> distanceQuery, int maxk, int flags)Get a KNN query object for the given distance query and k.protected voidpostDelete(RdKNNEntry entry)Performs necessary operations after deleting the specified object.protected voidpreInsert(RdKNNEntry entry)Performs necessary operations before inserting the specified entry.private voidpreInsert(RdKNNEntry q, RdKNNEntry nodeEntry, KNNHeap knns_q)Adapts the knn distances before insertion of entry q.PrioritySearcher<O>priorityByObject(DistanceQuery<O> distanceQuery, double maxradius, int flags)Get a priority search object.RangeSearcher<O>rangeByObject(DistanceQuery<O> distanceQuery, double maxradius, int flags)Get a range query object for the given distance query and k.DoubleDBIDListreverseKNNQuery(DBID oid, int k, SpatialPrimitiveDistance<? super O> distance)RKNNSearcher<DBIDRef>rkNNByDBID(DistanceQuery<O> distanceQuery, int maxk, int flags)Get a RKNN query object for the given distance query and k.RKNNSearcher<O>rkNNByObject(DistanceQuery<O> distanceQuery, int maxk, int flags)Get a RKNN query object for the given distance query and k.-
Methods inherited from class elki.index.tree.spatial.rstarvariants.NonFlatRStarTree
computeHeight, createEmptyRoot, hasOverflow, hasUnderflow
-
Methods inherited from class elki.index.tree.spatial.rstarvariants.AbstractRStarTree
adjustTree, canBulkLoad, choosePath, containedTest, createBulkLeafNodes, createNewRoot, deletePath, doExtraIntegrityChecks, findPathToObject, getHeight, getLeaves, initializeFromFile, insertEntry, insertLeaf, logStatistics, reInsert, setHeight, toString
-
Methods inherited from class elki.index.tree.IndexTree
deleteNode, getFile, getNode, getNode, getPageID, getPageSize, getRootEntry, getRootID, getRootPath, initialize, isRoot, writeNode
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface elki.index.DistancePriorityIndex
priorityByDBID
-
Methods inherited from interface elki.index.Index
logStatistics
-
Methods inherited from interface elki.index.RangeIndex
rangeByDBID
-
-
-
-
Field Detail
-
LOG
private static final Logging LOG
The logger for this class.
-
distanceQuery
private SpatialDistanceQuery<O extends NumberVector> distanceQuery
The distance function.
-
knnQuery
protected KNNSearcher<DBIDRef> knnQuery
Internal knn query object, for updating the rKNN.
-
relation
private Relation<O extends NumberVector> relation
The relation we query.
-
-
Constructor Detail
-
RdKNNTree
public RdKNNTree(Relation<O> relation, PageFile<RdKNNNode> pagefile, RdkNNSettings settings)
Constructor.- Parameters:
relation- Relation to indexpagefile- Data storagesettings- Tree settings
-
-
Method Detail
-
preInsert
protected void preInsert(RdKNNEntry entry)
Performs necessary operations before inserting the specified entry.- Overrides:
preInsertin classIndexTree<RdKNNNode,RdKNNEntry>- Parameters:
entry- the entry to be inserted
-
postDelete
protected void postDelete(RdKNNEntry entry)
Performs necessary operations after deleting the specified object.- Overrides:
postDeletein classIndexTree<RdKNNNode,RdKNNEntry>- Parameters:
entry- the entry that was removed
-
bulkLoad
protected void bulkLoad(java.util.List<RdKNNEntry> entries)
Performs a bulk load on this RTree with the specified data. Is called by the constructor and should be overwritten by subclasses if necessary.- Overrides:
bulkLoadin classNonFlatRStarTree<RdKNNNode,RdKNNEntry,RdkNNSettings>- Parameters:
entries- Entries to bulk load
-
reverseKNNQuery
public DoubleDBIDList reverseKNNQuery(DBID oid, int k, SpatialPrimitiveDistance<? super O> distance)
-
createHeader
protected TreeIndexHeader createHeader()
Description copied from class:IndexTreeCreates a header for this index structure which is an instance ofTreeIndexHeader. Subclasses may need to overwrite this method if they need a more specialized header.- Overrides:
createHeaderin classIndexTree<RdKNNNode,RdKNNEntry>- Returns:
- a new header for this index structure
-
initializeCapacities
protected void initializeCapacities(RdKNNEntry exampleLeaf)
Description copied from class:IndexTreeDetermines the maximum and minimum number of entries in a node.- Overrides:
initializeCapacitiesin classAbstractRStarTree<RdKNNNode,RdKNNEntry,RdkNNSettings>- Parameters:
exampleLeaf- an object that will be stored in the index
-
getSortedEntries
protected java.util.List<DoubleObjPair<RdKNNEntry>> getSortedEntries(AbstractRStarTreeNode<?,?> node, SpatialComparable q, SpatialPrimitiveDistance<?> distance)
Sorts the entries of the specified node according to their minimum distance to the specified object.- Parameters:
node- the nodeq- the query objectdistance- the distance function for computing the distances- Returns:
- a list of the sorted entries
-
preInsert
private void preInsert(RdKNNEntry q, RdKNNEntry nodeEntry, KNNHeap knns_q)
Adapts the knn distances before insertion of entry q.- Parameters:
q- the entry to be insertednodeEntry- the entry representing the root of the current subtreeknns_q- the knns of q
-
doReverseKNN
private void doReverseKNN(RdKNNNode node, DBID oid, ModifiableDoubleDBIDList result)
Performs a reverse knn query in the specified subtree.- Parameters:
node- the root node of the current subtreeoid- the id of the object for which the rknn query is performedresult- the list containing the query results
-
adjustKNNDistances
private void adjustKNNDistances(RdKNNEntry entry, ArrayDBIDs ids, double[] kdists)
Adjusts the knn distance in the subtree of the specified root entry.- Parameters:
entry- the root entry of the current subtreeids- Sorted list of IDskdists- knn distances
-
createNewLeafNode
protected RdKNNNode createNewLeafNode()
Creates a new leaf node with the specified capacity.- Specified by:
createNewLeafNodein classIndexTree<RdKNNNode,RdKNNEntry>- Returns:
- a new leaf node
-
createNewDirectoryNode
protected RdKNNNode createNewDirectoryNode()
Creates a new directory node with the specified capacity.- Specified by:
createNewDirectoryNodein classIndexTree<RdKNNNode,RdKNNEntry>- Returns:
- a new directory node
-
createNewDirectoryEntry
protected RdKNNEntry createNewDirectoryEntry(RdKNNNode node)
Creates a new directory entry representing the specified node.- Specified by:
createNewDirectoryEntryin classAbstractRStarTree<RdKNNNode,RdKNNEntry,RdkNNSettings>- Parameters:
node- the node to be represented by the new entry- Returns:
- the newly created directory entry
-
createRootEntry
protected RdKNNEntry createRootEntry()
Creates an entry representing the root node.- Specified by:
createRootEntryin classIndexTree<RdKNNNode,RdKNNEntry>- Returns:
- an entry representing the root node
-
checkDistance
private void checkDistance(SpatialPrimitiveDistance<? super O> distance)
Throws an IllegalArgumentException if the specified distance function is not an instance of the distance function used by this index.- Parameters:
distance- the distance function to be checked- Throws:
java.lang.IllegalArgumentException
-
createNewLeafEntry
protected RdKNNLeafEntry createNewLeafEntry(DBID id)
-
initialize
public void initialize()
Description copied from class:IndexTreeInitialize the tree if the page file already existed.- Specified by:
initializein interfaceIndex- Overrides:
initializein classIndexTree<RdKNNNode,RdKNNEntry>
-
insert
public final void insert(DBIDRef id)
Inserts the specified real vector object into this index.- Specified by:
insertin interfaceDynamicIndex- Parameters:
id- the object id that was inserted
-
insertAll
public final void insertAll(DBIDs ids)
Inserts the specified objects into this index. If a bulk load mode is implemented, the objects are inserted in one bulk.- Specified by:
insertAllin interfaceDynamicIndex- Parameters:
ids- the objects to be inserted
-
delete
public final boolean delete(DBIDRef id)
Deletes the specified object from this index.- Specified by:
deletein interfaceDynamicIndex- Parameters:
id- Object to remove- Returns:
- true if this index did contain the object with the specified id, false otherwise
-
deleteAll
public void deleteAll(DBIDs ids)
Description copied from interface:DynamicIndexDeletes the specified objects from this index.- Specified by:
deleteAllin interfaceDynamicIndex- Parameters:
ids- Objects to remove
-
kNNByObject
public KNNSearcher<O> kNNByObject(DistanceQuery<O> distanceQuery, int maxk, int flags)
Description copied from interface:KNNIndexGet a KNN query object for the given distance query and k.This function MAY return null, when the given distance is not supported!
- Specified by:
kNNByObjectin interfaceDistancePriorityIndex<O extends NumberVector>- Specified by:
kNNByObjectin interfaceKNNIndex<O extends NumberVector>- Parameters:
distanceQuery- Distance querymaxk- Maximum value of kflags- Hints for the optimizer- Returns:
- KNN Query object or
null
-
rangeByObject
public RangeSearcher<O> rangeByObject(DistanceQuery<O> distanceQuery, double maxradius, int flags)
Description copied from interface:RangeIndexGet a range query object for the given distance query and k.This function MAY return null, when the given distance is not supported!
- Specified by:
rangeByObjectin interfaceDistancePriorityIndex<O extends NumberVector>- Specified by:
rangeByObjectin interfaceRangeIndex<O extends NumberVector>- Parameters:
distanceQuery- Distance querymaxradius- Maximum rangeflags- Hints for the optimizer- Returns:
- KNN Query object or
null
-
priorityByObject
public PrioritySearcher<O> priorityByObject(DistanceQuery<O> distanceQuery, double maxradius, int flags)
Description copied from interface:DistancePriorityIndexGet a priority search object.- Specified by:
priorityByObjectin interfaceDistancePriorityIndex<O extends NumberVector>- Parameters:
distanceQuery- Distance querymaxradius- Maximum search range (may beDouble.POSITIVE_INFINITYflags- Optimizer hints- Returns:
- Priority searcher
-
rkNNByObject
public RKNNSearcher<O> rkNNByObject(DistanceQuery<O> distanceQuery, int maxk, int flags)
Description copied from interface:RKNNIndexGet a RKNN query object for the given distance query and k.This function MAY return null, when the given distance is not supported!
- Specified by:
rkNNByObjectin interfaceRKNNIndex<O extends NumberVector>- Parameters:
distanceQuery- Distance querymaxk- Maximum k for RkNN queryflags- Hints for the optimizer- Returns:
- RKNN Query object or
null
-
rkNNByDBID
public RKNNSearcher<DBIDRef> rkNNByDBID(DistanceQuery<O> distanceQuery, int maxk, int flags)
Description copied from interface:RKNNIndexGet a RKNN query object for the given distance query and k.This function MAY return null, when the given distance is not supported!
- Specified by:
rkNNByDBIDin interfaceRKNNIndex<O extends NumberVector>- Parameters:
distanceQuery- Distance querymaxk- Maximum k for RkNN queryflags- Hints for the optimizer- Returns:
- RKNN Query object or
null
-
-