Class MaterializeKNNPreprocessor<O>

  • Type Parameters:
    O - the type of database objects the preprocessor can be applied to
    All Implemented Interfaces:
    DynamicIndex, 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 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
    • Field Detail

      • LOG

        private static final Logging LOG
        Logger to use.
      • listenerList

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

      • MaterializeKNNPreprocessor

        public MaterializeKNNPreprocessor​(Relation<O> relation,
                                          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​(Relation<O> relation,
                                          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​(DBIDRef id)
        Description copied from interface: DynamicIndex
        Inserts the specified object into this index.
        Specified by:
        insert in interface DynamicIndex
        Parameters:
        id - the object to be inserted
      • insertAll

        public void insertAll​(DBIDs ids)
        Description copied from interface: DynamicIndex
        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 DynamicIndex
        Parameters:
        ids - the objects to be inserted
      • delete

        public boolean delete​(DBIDRef id)
        Description copied from interface: DynamicIndex
        Deletes the specified object from this index.
        Specified by:
        delete in interface DynamicIndex
        Parameters:
        id - Object to remove
        Returns:
        true if this index did contain the object, false otherwise
      • deleteAll

        public void deleteAll​(DBIDs ids)
        Description copied from interface: DynamicIndex
        Deletes the specified objects from this index.
        Specified by:
        deleteAll in interface DynamicIndex
        Parameters:
        ids - Objects to remove
      • objectsInserted

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

        private ArrayDBIDs updateKNNsAfterInsertion​(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 ArrayDBIDs updateKNNsAfterDeletion​(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​(DBIDs ids)
        Called after objects have been removed, updates the materialized neighborhood.
        Parameters:
        ids - the ids of the removed objects
      • fireKNNsInserted

        protected void fireKNNsInserted​(DBIDs insertions,
                                        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​(DBIDs removals,
                                       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