Class RdKNNTree<O extends elki.data.NumberVector>

  • 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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private elki.database.query.distance.SpatialDistanceQuery<O> distanceQuery
      The distance function.
      protected elki.database.query.knn.KNNSearcher<elki.database.ids.DBIDRef> knnQuery
      Internal knn query object, for updating the rKNN.
      private static elki.logging.Logging LOG
      The logger for this class.
      private elki.database.relation.Relation<O> relation
      The relation we query.
      • Fields inherited from class elki.index.tree.IndexTree

        dirCapacity, dirMinimum, initialized, leafCapacity, leafMinimum
    • 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 void adjustKNNDistances​(RdKNNEntry entry, elki.database.ids.ArrayDBIDs ids, double[] kdists)
      Adjusts the knn distance in the subtree of the specified root entry.
      protected void bulkLoad​(java.util.List<RdKNNEntry> entries)
      Performs a bulk load on this RTree with the specified data.
      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.
      protected elki.index.tree.TreeIndexHeader createHeader()  
      protected RdKNNEntry createNewDirectoryEntry​(RdKNNNode node)
      Creates a new directory entry representing the specified node.
      protected RdKNNNode createNewDirectoryNode()
      Creates a new directory node with the specified capacity.
      protected RdKNNLeafEntry createNewLeafEntry​(elki.database.ids.DBID id)  
      protected RdKNNNode createNewLeafNode()
      Creates a new leaf node with the specified capacity.
      protected RdKNNEntry createRootEntry()
      Creates an entry representing the root node.
      boolean delete​(elki.database.ids.DBIDRef id)
      Deletes the specified object from this index.
      void deleteAll​(elki.database.ids.DBIDs ids)  
      private void doReverseKNN​(RdKNNNode node, elki.database.ids.DBID oid, elki.database.ids.ModifiableDoubleDBIDList result)
      Performs a reverse knn query in the specified subtree.
      protected elki.logging.Logging getLogger()  
      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.
      void initialize()  
      protected void initializeCapacities​(RdKNNEntry exampleLeaf)  
      void insert​(elki.database.ids.DBIDRef id)
      Inserts the specified real vector object into this index.
      void insertAll​(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 void postDelete​(RdKNNEntry entry)
      Performs necessary operations after deleting the specified object.
      protected void preInsert​(RdKNNEntry entry)
      Performs necessary operations before inserting the specified entry.
      private void preInsert​(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.DoubleDBIDList reverseKNNQuery​(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.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.KNNIndex

        kNNByDBID
      • Methods inherited from interface elki.index.RangeIndex

        rangeByDBID
    • 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 index
        pagefile - Data storage
        settings - Tree settings
    • Method Detail

      • preInsert

        protected void preInsert​(RdKNNEntry entry)
        Performs necessary operations before inserting the specified entry.
        Overrides:
        preInsert in class elki.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:
        postDelete in class elki.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:
        bulkLoad in class NonFlatRStarTree<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:
        createHeader in class elki.index.tree.IndexTree<RdKNNNode,​RdKNNEntry>
      • 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 node
        q - the query object
        distance - 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 inserted
        nodeEntry - the entry representing the root of the current subtree
        knns_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 subtree
        oid - the id of the object for which the rknn query is performed
        result - 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 subtree
        ids - Sorted list of IDs
        kdists - knn distances
      • createNewLeafNode

        protected RdKNNNode createNewLeafNode()
        Creates a new leaf node with the specified capacity.
        Specified by:
        createNewLeafNode in class elki.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:
        createNewDirectoryNode in class elki.index.tree.IndexTree<RdKNNNode,​RdKNNEntry>
        Returns:
        a new directory node
      • createRootEntry

        protected RdKNNEntry createRootEntry()
        Creates an entry representing the root node.
        Specified by:
        createRootEntry in class elki.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:
        initialize in interface elki.index.Index
        Overrides:
        initialize in class elki.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:
        insert in interface elki.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:
        insertAll in interface elki.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:
        delete in interface elki.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:
        deleteAll in interface elki.index.DynamicIndex
      • kNNByObject

        public elki.database.query.knn.KNNSearcher<O> kNNByObject​(elki.database.query.distance.DistanceQuery<O> distanceQuery,
                                                                  int maxk,
                                                                  int flags)
        Specified by:
        kNNByObject in interface elki.index.DistancePriorityIndex<O extends elki.data.NumberVector>
        Specified by:
        kNNByObject in interface elki.index.KNNIndex<O extends elki.data.NumberVector>
      • rangeByObject

        public elki.database.query.range.RangeSearcher<O> rangeByObject​(elki.database.query.distance.DistanceQuery<O> distanceQuery,
                                                                        double maxradius,
                                                                        int flags)
        Specified by:
        rangeByObject in interface elki.index.DistancePriorityIndex<O extends elki.data.NumberVector>
        Specified by:
        rangeByObject in interface elki.index.RangeIndex<O extends elki.data.NumberVector>
      • priorityByObject

        public elki.database.query.PrioritySearcher<O> priorityByObject​(elki.database.query.distance.DistanceQuery<O> distanceQuery,
                                                                        double maxradius,
                                                                        int flags)
        Specified by:
        priorityByObject in interface elki.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:
        rkNNByObject in interface elki.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:
        rkNNByDBID in interface elki.index.RKNNIndex<O extends elki.data.NumberVector>
      • getLogger

        protected elki.logging.Logging getLogger()
        Specified by:
        getLogger in class elki.index.tree.IndexTree<RdKNNNode,​RdKNNEntry>