Package elki.index.preprocessed.knn
Class MaterializeKNNPreprocessor<O>
- java.lang.Object
-
- elki.index.preprocessed.knn.AbstractMaterializeKNNPreprocessor<O>
-
- elki.index.preprocessed.knn.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMaterializeKNNPreprocessor.Factory<O>The parameterizable factory.
-
Field Summary
Fields Modifier and Type Field Description protected KNNSearcher<DBIDRef>knnQueryKNNSearcher instance to use.protected javax.swing.event.EventListenerListlistenerListHolds the listener.private static LoggingLOGLogger to use.-
Fields inherited from class elki.index.preprocessed.knn.AbstractMaterializeKNNPreprocessor
distance, distanceQuery, k, relation, storage
-
-
Constructor Summary
Constructors Constructor Description MaterializeKNNPreprocessor(Relation<O> relation, DistanceQuery<O> distanceQuery, int k, boolean noopt)Constructor with preprocessing step.MaterializeKNNPreprocessor(Relation<O> relation, Distance<? super O> distance, int k)Constructor with preprocessing step.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddKNNListener(KNNListener l)Adds aKNNListenerwhich will be invoked when the kNNs of objects are changing.booleandelete(DBIDRef id)Deletes the specified object from this index.voiddeleteAll(DBIDs ids)Deletes the specified objects from this index.protected voidfireKNNsInserted(DBIDs insertions, DBIDs updates)Informs all registered KNNListener that new kNNs have been inserted and as a result some kNNs have been changed.protected voidfireKNNsRemoved(DBIDs removals, DBIDs updates)Informs all registered KNNListener that existing kNNs have been removed and as a result some kNNs have been changed.protected LogginggetLogger()Get the classes static logger.voidinsert(DBIDRef id)Inserts the specified object into this index.voidinsertAll(DBIDs ids)Inserts the specified objects into this index.protected voidobjectsInserted(DBIDs ids)Called after new objects have been inserted, updates the materialized neighborhood.protected voidobjectsRemoved(DBIDs ids)Called after objects have been removed, updates the materialized neighborhood.protected voidpreprocess()The actual preprocessing step.voidremoveKNNListener(KNNListener l)Removes aKNNListenerpreviously added withaddKNNListener(elki.index.preprocessed.knn.KNNListener).private ArrayDBIDsupdateKNNsAfterDeletion(DBIDs ids)Updates the kNNs of the RkNNs of the specified ids.private ArrayDBIDsupdateKNNsAfterInsertion(DBIDs ids)Updates the kNNs of the RkNNs of the specified ids.-
Methods inherited from class elki.index.preprocessed.knn.AbstractMaterializeKNNPreprocessor
createStorage, get, getDistanceQuery, getK, initialize, kNNByDBID, kNNByObject
-
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 Logging LOG
Logger to use.
-
knnQuery
protected final KNNSearcher<DBIDRef> knnQuery
KNNSearcher instance 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 preprocessdistance- the distance function to usek- query k
-
MaterializeKNNPreprocessor
public MaterializeKNNPreprocessor(Relation<O> relation, DistanceQuery<O> distanceQuery, int k, boolean noopt)
Constructor with preprocessing step.- Parameters:
relation- Relation to preprocessdistanceQuery- the distance function to usek- query knoopt- Flag to disable optimization
-
-
Method Detail
-
preprocess
protected void preprocess()
The actual preprocessing step.- Specified by:
preprocessin classAbstractMaterializeKNNPreprocessor<O>
-
insert
public final void insert(DBIDRef id)
Description copied from interface:DynamicIndexInserts the specified object into this index.- Specified by:
insertin interfaceDynamicIndex- Parameters:
id- the object to be inserted
-
insertAll
public void insertAll(DBIDs ids)
Description copied from interface:DynamicIndexInserts the specified objects into this index. If a bulk load mode is implemented, the objects are inserted in one bulk.- Specified by:
insertAllin interfaceDynamicIndex- Parameters:
ids- the objects to be inserted
-
delete
public boolean delete(DBIDRef id)
Description copied from interface:DynamicIndexDeletes the specified object from this index.- Specified by:
deletein interfaceDynamicIndex- 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:DynamicIndexDeletes the specified objects from this index.- Specified by:
deleteAllin interfaceDynamicIndex- 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 kNNsupdates- 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 kNNsupdates- the ids of kNNs which have been changed due to the removals- See Also:
KNNListener
-
addKNNListener
public void addKNNListener(KNNListener l)
Adds aKNNListenerwhich will be invoked when the kNNs of objects are changing.- Parameters:
l- the listener to add- See Also:
removeKNNListener(elki.index.preprocessed.knn.KNNListener),KNNListener
-
removeKNNListener
public void removeKNNListener(KNNListener l)
Removes aKNNListenerpreviously added withaddKNNListener(elki.index.preprocessed.knn.KNNListener).- Parameters:
l- the listener to remove- See Also:
addKNNListener(elki.index.preprocessed.knn.KNNListener),KNNListener
-
getLogger
protected Logging getLogger()
Description copied from class:AbstractMaterializeKNNPreprocessorGet the classes static logger.- Specified by:
getLoggerin classAbstractMaterializeKNNPreprocessor<O>- Returns:
- Logger
-
-