Class MaterializeKNNAndRKNNPreprocessor<O>

  • Type Parameters:
    O - the type of database objects the preprocessor can be applied to the type of distance the used distance function will return
    All Implemented Interfaces:
    elki.index.DynamicIndex, elki.index.Index, elki.index.KNNIndex<O>, elki.index.RKNNIndex<O>

    @Title("Materialize kNN and RkNN Neighborhood preprocessor")
    @Description("Materializes the k nearest neighbors and the reverse k nearest neighbors of objects of a database.")
    public class MaterializeKNNAndRKNNPreprocessor<O>
    extends MaterializeKNNPreprocessor<O>
    implements elki.index.RKNNIndex<O>
    A preprocessor for annotation of the k nearest neighbors and the reverse k nearest neighbors (and their distances) to each database object.

    BUG: This class currently does not seem able to correctly keep track of the nearest neighbors?

    TODO: for better performance, we would need some ModifiableDoubleDBIDHashSet or TreeSet to store the rkNN.

    Since:
    0.4.0
    Author:
    Elke Achtert
    • Field Detail

      • LOG

        private static final elki.logging.Logging LOG
        Logger to use.
      • storageRkNN

        private elki.database.datastore.WritableDataStore<elki.database.ids.ModifiableDoubleDBIDList> storageRkNN
        Additional data storage for RkNN.
    • Constructor Detail

      • MaterializeKNNAndRKNNPreprocessor

        public MaterializeKNNAndRKNNPreprocessor​(elki.database.relation.Relation<O> relation,
                                                 elki.distance.Distance<? super O> distance,
                                                 int k)
        Constructor.
        Parameters:
        relation - Relation to process
        distance - the distance function to use
        k - query k
    • Method Detail

      • materializeKNNAndRKNNs

        private void materializeKNNAndRKNNs​(elki.database.ids.ArrayDBIDs ids,
                                            elki.logging.progress.FiniteProgress progress)
        Materializes the kNNs and RkNNs of the specified object IDs.
        Parameters:
        ids - the IDs of the objects
      • objectsInserted

        protected void objectsInserted​(elki.database.ids.DBIDs ids)
        Description copied from class: MaterializeKNNPreprocessor
        Called after new objects have been inserted, updates the materialized neighborhood.
        Overrides:
        objectsInserted in class MaterializeKNNPreprocessor<O>
        Parameters:
        ids - the ids of the newly inserted objects
      • updateKNNsAndRkNNs

        private elki.database.ids.DBIDs updateKNNsAndRkNNs​(elki.database.ids.DBIDs ids)
        Updates the kNNs and RkNNs after insertion of the specified ids.
        Parameters:
        ids - the ids of newly inserted objects causing a change of materialized kNNs and RkNNs
        Returns:
        the RkNNs of the specified ids, i.e. the kNNs which have been updated
      • objectsRemoved

        protected void objectsRemoved​(elki.database.ids.DBIDs ids)
        Description copied from class: MaterializeKNNPreprocessor
        Called after objects have been removed, updates the materialized neighborhood.
        Overrides:
        objectsRemoved in class MaterializeKNNPreprocessor<O>
        Parameters:
        ids - the ids of the removed objects
      • getKNN

        public elki.database.ids.KNNList getKNN​(elki.database.ids.DBID id)
        Returns the materialized kNNs of the specified id.
        Parameters:
        id - the query id
        Returns:
        the kNNs
      • getRKNN

        public elki.database.ids.DoubleDBIDList getRKNN​(elki.database.ids.DBIDRef id)
        Returns the materialized RkNNs of the specified id.
        Parameters:
        id - the query id
        Returns:
        the RkNNs
      • 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>
      • 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>