Class MaterializeKNNPreprocessor<O>

  • Type Parameters:
    O - the type of database objects the preprocessor can be applied to
    All Implemented Interfaces:
    elki.index.DynamicIndex, elki.index.Index, elki.index.KNNIndex<O>
    Direct Known Subclasses:
    MaterializeKNNAndRKNNPreprocessor

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

    Automatically added by the query optimizer if memory permits.

    Since:
    0.2
    Author:
    Erich Schubert
    • Constructor Summary

      Constructors 
      Constructor Description
      MaterializeKNNPreprocessor​(elki.database.relation.Relation<O> relation, elki.database.query.distance.DistanceQuery<O> distanceQuery, int k, boolean noopt)
      Constructor with preprocessing step.
      MaterializeKNNPreprocessor​(elki.database.relation.Relation<O> relation, elki.distance.Distance<? super O> distance, int k)
      Constructor with preprocessing step.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addKNNListener​(KNNListener l)
      Adds a KNNListener which will be invoked when the kNNs of objects are changing.
      boolean delete​(elki.database.ids.DBIDRef id)  
      void deleteAll​(elki.database.ids.DBIDs ids)  
      protected void fireKNNsInserted​(elki.database.ids.DBIDs insertions, elki.database.ids.DBIDs updates)
      Informs all registered KNNListener that new kNNs have been inserted and as a result some kNNs have been changed.
      protected void fireKNNsRemoved​(elki.database.ids.DBIDs removals, elki.database.ids.DBIDs updates)
      Informs all registered KNNListener that existing kNNs have been removed and as a result some kNNs have been changed.
      protected elki.logging.Logging getLogger()
      Get the classes static logger.
      void insert​(elki.database.ids.DBIDRef id)  
      void insertAll​(elki.database.ids.DBIDs ids)  
      protected void objectsInserted​(elki.database.ids.DBIDs ids)
      Called after new objects have been inserted, updates the materialized neighborhood.
      protected void objectsRemoved​(elki.database.ids.DBIDs ids)
      Called after objects have been removed, updates the materialized neighborhood.
      protected void preprocess()
      The actual preprocessing step.
      void removeKNNListener​(KNNListener l)
      private elki.database.ids.ArrayDBIDs updateKNNsAfterDeletion​(elki.database.ids.DBIDs ids)
      Updates the kNNs of the RkNNs of the specified ids.
      private elki.database.ids.ArrayDBIDs updateKNNsAfterInsertion​(elki.database.ids.DBIDs ids)
      Updates the kNNs of the RkNNs of the specified ids.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface elki.index.Index

        initialize, logStatistics
    • Field Detail

      • LOG

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

        protected final elki.database.query.knn.KNNSearcher<elki.database.ids.DBIDRef> knnQuery
        KNNSearcher instance to use.
      • listenerList

        protected final javax.swing.event.EventListenerList listenerList
        Holds the listener.
    • Constructor Detail

      • MaterializeKNNPreprocessor

        public MaterializeKNNPreprocessor​(elki.database.relation.Relation<O> relation,
                                          elki.distance.Distance<? super O> distance,
                                          int k)
        Constructor with preprocessing step.
        Parameters:
        relation - Relation to preprocess
        distance - the distance function to use
        k - query k
      • MaterializeKNNPreprocessor

        public MaterializeKNNPreprocessor​(elki.database.relation.Relation<O> relation,
                                          elki.database.query.distance.DistanceQuery<O> distanceQuery,
                                          int k,
                                          boolean noopt)
        Constructor with preprocessing step.
        Parameters:
        relation - Relation to preprocess
        distanceQuery - the distance function to use
        k - query k
        noopt - Flag to disable optimization
    • Method Detail

      • insert

        public final void insert​(elki.database.ids.DBIDRef id)
        Specified by:
        insert in interface elki.index.DynamicIndex
      • insertAll

        public void insertAll​(elki.database.ids.DBIDs ids)
        Specified by:
        insertAll in interface elki.index.DynamicIndex
      • delete

        public boolean delete​(elki.database.ids.DBIDRef id)
        Specified by:
        delete in interface elki.index.DynamicIndex
      • deleteAll

        public void deleteAll​(elki.database.ids.DBIDs ids)
        Specified by:
        deleteAll in interface elki.index.DynamicIndex
      • objectsInserted

        protected void objectsInserted​(elki.database.ids.DBIDs ids)
        Called after new objects have been inserted, updates the materialized neighborhood.
        Parameters:
        ids - the ids of the newly inserted objects
      • updateKNNsAfterInsertion

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

        private elki.database.ids.ArrayDBIDs updateKNNsAfterDeletion​(elki.database.ids.DBIDs ids)
        Updates the kNNs of the RkNNs of the specified ids.
        Parameters:
        ids - the ids of deleted objects causing a change of materialized kNNs
        Returns:
        the RkNNs of the specified ids, i.e. the kNNs which have been updated
      • objectsRemoved

        protected void objectsRemoved​(elki.database.ids.DBIDs ids)
        Called after objects have been removed, updates the materialized neighborhood.
        Parameters:
        ids - the ids of the removed objects
      • fireKNNsInserted

        protected void fireKNNsInserted​(elki.database.ids.DBIDs insertions,
                                        elki.database.ids.DBIDs updates)
        Informs all registered KNNListener that new kNNs have been inserted and as a result some kNNs have been changed.
        Parameters:
        insertions - the ids of the newly inserted kNNs
        updates - the ids of kNNs which have been changed due to the insertions
        See Also:
        KNNListener
      • fireKNNsRemoved

        protected void fireKNNsRemoved​(elki.database.ids.DBIDs removals,
                                       elki.database.ids.DBIDs updates)
        Informs all registered KNNListener that existing kNNs have been removed and as a result some kNNs have been changed.
        Parameters:
        removals - the ids of the removed kNNs
        updates - the ids of kNNs which have been changed due to the removals
        See Also:
        KNNListener