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 class
MaterializeKNNPreprocessor.Factory<O>
The parameterizable factory.
-
Field Summary
Fields Modifier and Type Field Description protected KNNSearcher<DBIDRef>
knnQuery
KNNSearcher instance to use.protected javax.swing.event.EventListenerList
listenerList
Holds the listener.private static Logging
LOG
Logger 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 void
addKNNListener(KNNListener l)
Adds aKNNListener
which will be invoked when the kNNs of objects are changing.boolean
delete(DBIDRef id)
Deletes the specified object from this index.void
deleteAll(DBIDs ids)
Deletes the specified objects from this index.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.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.protected Logging
getLogger()
Get the classes static logger.void
insert(DBIDRef id)
Inserts the specified object into this index.void
insertAll(DBIDs ids)
Inserts the specified objects into this index.protected void
objectsInserted(DBIDs ids)
Called after new objects have been inserted, updates the materialized neighborhood.protected void
objectsRemoved(DBIDs ids)
Called after objects have been removed, updates the materialized neighborhood.protected void
preprocess()
The actual preprocessing step.void
removeKNNListener(KNNListener l)
Removes aKNNListener
previously added withaddKNNListener(elki.index.preprocessed.knn.KNNListener)
.private ArrayDBIDs
updateKNNsAfterDeletion(DBIDs ids)
Updates the kNNs of the RkNNs of the specified ids.private ArrayDBIDs
updateKNNsAfterInsertion(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:
preprocess
in classAbstractMaterializeKNNPreprocessor<O>
-
insert
public final void insert(DBIDRef id)
Description copied from interface:DynamicIndex
Inserts the specified object into this index.- Specified by:
insert
in interfaceDynamicIndex
- 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 interfaceDynamicIndex
- 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 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:DynamicIndex
Deletes the specified objects from this index.- Specified by:
deleteAll
in 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 aKNNListener
which 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 aKNNListener
previously 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:AbstractMaterializeKNNPreprocessor
Get the classes static logger.- Specified by:
getLogger
in classAbstractMaterializeKNNPreprocessor<O>
- Returns:
- Logger
-
-