Class RdKNNTree<O extends elki.data.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:
elki.index.DistancePriorityIndex<O>,elki.index.DynamicIndex,elki.index.Index,elki.index.KNNIndex<O>,elki.index.RangeIndex<O>,elki.index.RKNNIndex<O>
public class RdKNNTree<O extends elki.data.NumberVector> extends NonFlatRStarTree<RdKNNNode,RdKNNEntry,RdkNNSettings> implements elki.index.DistancePriorityIndex<O>, elki.index.RKNNIndex<O>, elki.index.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 elki.database.query.distance.SpatialDistanceQuery<O>distanceQueryThe distance function.protected elki.database.query.knn.KNNSearcher<elki.database.ids.DBIDRef>knnQueryInternal knn query object, for updating the rKNN.private static elki.logging.LoggingLOGThe logger for this class.private elki.database.relation.Relation<O>relationThe relation we query.-
Fields inherited from class elki.index.tree.spatial.rstarvariants.AbstractRStarTree
EXTRA_INTEGRITY_CHECKS, height, settings, statistics
-
-
Constructor Summary
Constructors Constructor Description RdKNNTree(elki.database.relation.Relation<O> relation, elki.persistent.PageFile<RdKNNNode> pagefile, RdkNNSettings settings)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidadjustKNNDistances(RdKNNEntry entry, elki.database.ids.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(elki.distance.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 elki.index.tree.TreeIndexHeadercreateHeader()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(elki.database.ids.DBID id)protected RdKNNNodecreateNewLeafNode()Creates a new leaf node with the specified capacity.protected RdKNNEntrycreateRootEntry()Creates an entry representing the root node.booleandelete(elki.database.ids.DBIDRef id)Deletes the specified object from this index.voiddeleteAll(elki.database.ids.DBIDs ids)private voiddoReverseKNN(RdKNNNode node, elki.database.ids.DBID oid, elki.database.ids.ModifiableDoubleDBIDList result)Performs a reverse knn query in the specified subtree.protected elki.logging.LogginggetLogger()protected java.util.List<elki.utilities.pairs.DoubleObjPair<RdKNNEntry>>getSortedEntries(AbstractRStarTreeNode<?,?> node, elki.data.spatial.SpatialComparable q, elki.distance.SpatialPrimitiveDistance<?> distance)Sorts the entries of the specified node according to their minimum distance to the specified object.voidinitialize()protected voidinitializeCapacities(RdKNNEntry exampleLeaf)voidinsert(elki.database.ids.DBIDRef id)Inserts the specified real vector object into this index.voidinsertAll(elki.database.ids.DBIDs ids)Inserts the specified objects into this index.elki.database.query.knn.KNNSearcher<O>kNNByObject(elki.database.query.distance.DistanceQuery<O> distanceQuery, int maxk, int flags)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, elki.database.ids.KNNHeap knns_q)Adapts the knn distances before insertion of entry q.elki.database.query.PrioritySearcher<O>priorityByObject(elki.database.query.distance.DistanceQuery<O> distanceQuery, double maxradius, int flags)elki.database.query.range.RangeSearcher<O>rangeByObject(elki.database.query.distance.DistanceQuery<O> distanceQuery, double maxradius, int flags)elki.database.ids.DoubleDBIDListreverseKNNQuery(elki.database.ids.DBID oid, int k, elki.distance.SpatialPrimitiveDistance<? super O> distance)elki.database.query.rknn.RKNNSearcher<elki.database.ids.DBIDRef>rkNNByDBID(elki.database.query.distance.DistanceQuery<O> distanceQuery, int maxk, int flags)elki.database.query.rknn.RKNNSearcher<O>rkNNByObject(elki.database.query.distance.DistanceQuery<O> distanceQuery, int maxk, int flags)-
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
-
-
-
-
Field Detail
-
LOG
private static final elki.logging.Logging LOG
The logger for this class.
-
distanceQuery
private elki.database.query.distance.SpatialDistanceQuery<O extends elki.data.NumberVector> distanceQuery
The distance function.
-
knnQuery
protected elki.database.query.knn.KNNSearcher<elki.database.ids.DBIDRef> knnQuery
Internal knn query object, for updating the rKNN.
-
relation
private elki.database.relation.Relation<O extends elki.data.NumberVector> relation
The relation we query.
-
-
Constructor Detail
-
RdKNNTree
public RdKNNTree(elki.database.relation.Relation<O> relation, elki.persistent.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 classelki.index.tree.IndexTree<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 classelki.index.tree.IndexTree<RdKNNNode,RdKNNEntry>
-
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 elki.database.ids.DoubleDBIDList reverseKNNQuery(elki.database.ids.DBID oid, int k, elki.distance.SpatialPrimitiveDistance<? super O> distance)
-
createHeader
protected elki.index.tree.TreeIndexHeader createHeader()
- Overrides:
createHeaderin classelki.index.tree.IndexTree<RdKNNNode,RdKNNEntry>
-
initializeCapacities
protected void initializeCapacities(RdKNNEntry exampleLeaf)
- Overrides:
initializeCapacitiesin classAbstractRStarTree<RdKNNNode,RdKNNEntry,RdkNNSettings>
-
getSortedEntries
protected java.util.List<elki.utilities.pairs.DoubleObjPair<RdKNNEntry>> getSortedEntries(AbstractRStarTreeNode<?,?> node, elki.data.spatial.SpatialComparable q, elki.distance.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, elki.database.ids.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, elki.database.ids.DBID oid, elki.database.ids.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, elki.database.ids.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 classelki.index.tree.IndexTree<RdKNNNode,RdKNNEntry>- Returns:
- a new leaf node
-
createNewDirectoryNode
protected RdKNNNode createNewDirectoryNode()
Creates a new directory node with the specified capacity.- Specified by:
createNewDirectoryNodein classelki.index.tree.IndexTree<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 classelki.index.tree.IndexTree<RdKNNNode,RdKNNEntry>- Returns:
- an entry representing the root node
-
checkDistance
private void checkDistance(elki.distance.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(elki.database.ids.DBID id)
-
initialize
public void initialize()
- Specified by:
initializein interfaceelki.index.Index- Overrides:
initializein classelki.index.tree.IndexTree<RdKNNNode,RdKNNEntry>
-
insert
public final void insert(elki.database.ids.DBIDRef id)
Inserts the specified real vector object into this index.- Specified by:
insertin interfaceelki.index.DynamicIndex- Parameters:
id- the object id that was inserted
-
insertAll
public final void insertAll(elki.database.ids.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 interfaceelki.index.DynamicIndex- Parameters:
ids- the objects to be inserted
-
delete
public final boolean delete(elki.database.ids.DBIDRef id)
Deletes the specified object from this index.- Specified by:
deletein interfaceelki.index.DynamicIndex- Returns:
- true if this index did contain the object with the specified id, false otherwise
-
deleteAll
public void deleteAll(elki.database.ids.DBIDs ids)
- Specified by:
deleteAllin interfaceelki.index.DynamicIndex
-
kNNByObject
public elki.database.query.knn.KNNSearcher<O> kNNByObject(elki.database.query.distance.DistanceQuery<O> distanceQuery, int maxk, int flags)
-
rangeByObject
public elki.database.query.range.RangeSearcher<O> rangeByObject(elki.database.query.distance.DistanceQuery<O> distanceQuery, double maxradius, int flags)
-
priorityByObject
public elki.database.query.PrioritySearcher<O> priorityByObject(elki.database.query.distance.DistanceQuery<O> distanceQuery, double maxradius, int flags)
- Specified by:
priorityByObjectin interfaceelki.index.DistancePriorityIndex<O extends elki.data.NumberVector>
-
rkNNByObject
public elki.database.query.rknn.RKNNSearcher<O> rkNNByObject(elki.database.query.distance.DistanceQuery<O> distanceQuery, int maxk, int flags)
- Specified by:
rkNNByObjectin interfaceelki.index.RKNNIndex<O extends elki.data.NumberVector>
-
rkNNByDBID
public elki.database.query.rknn.RKNNSearcher<elki.database.ids.DBIDRef> rkNNByDBID(elki.database.query.distance.DistanceQuery<O> distanceQuery, int maxk, int flags)
- Specified by:
rkNNByDBIDin interfaceelki.index.RKNNIndex<O extends elki.data.NumberVector>
-
getLogger
protected elki.logging.Logging getLogger()
- Specified by:
getLoggerin classelki.index.tree.IndexTree<RdKNNNode,RdKNNEntry>
-
-