de.lmu.ifi.dbs.elki.index.preprocessed.knn
Class MaterializeKNNAndRKNNPreprocessor<O,D extends Distance<D>>

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.index.AbstractIndex<O>
      extended by de.lmu.ifi.dbs.elki.index.preprocessed.AbstractPreprocessorIndex<O,List<DistanceResultPair<D>>>
          extended by de.lmu.ifi.dbs.elki.index.preprocessed.knn.AbstractMaterializeKNNPreprocessor<O,D>
              extended by de.lmu.ifi.dbs.elki.index.preprocessed.knn.MaterializeKNNPreprocessor<O,D>
                  extended by de.lmu.ifi.dbs.elki.index.preprocessed.knn.MaterializeKNNAndRKNNPreprocessor<O,D>
Type Parameters:
O - the type of database objects the preprocessor can be applied to
D - the type of distance the used distance function will return
All Implemented Interfaces:
Index, KNNIndex<O>, RKNNIndex<O>, Result

@Title(value="Materialize kNN and RkNN Neighborhood preprocessor")
@Description(value="Materializes the k nearest neighbors and the reverse k nearest neighbors of objects of a database.")
public class MaterializeKNNAndRKNNPreprocessor<O,D extends Distance<D>>
extends MaterializeKNNPreprocessor<O,D>
implements RKNNIndex<O>

A preprocessor for annotation of the k nearest neighbors and the reverse k nearest neighbors (and their distances) to each database object.


Nested Class Summary
static class MaterializeKNNAndRKNNPreprocessor.Factory<O,D extends Distance<D>>
          The parameterizable factory.
 
Field Summary
private static Logging logger
          Logger to use.
private  WritableDataStore<SortedSet<DistanceResultPair<D>>> materialized_RkNN
          Additional data storage for RkNN.
 
Fields inherited from class de.lmu.ifi.dbs.elki.index.preprocessed.knn.MaterializeKNNPreprocessor
knnQuery
 
Fields inherited from class de.lmu.ifi.dbs.elki.index.preprocessed.knn.AbstractMaterializeKNNPreprocessor
distanceFunction, distanceQuery, k, listenerList
 
Fields inherited from class de.lmu.ifi.dbs.elki.index.preprocessed.AbstractPreprocessorIndex
storage
 
Fields inherited from class de.lmu.ifi.dbs.elki.index.AbstractIndex
relation
 
Constructor Summary
MaterializeKNNAndRKNNPreprocessor(Relation<O> relation, DistanceFunction<? super O,D> distanceFunction, int k)
          Constructor.
 
Method Summary
 List<DistanceResultPair<D>> getKNN(DBID id)
          Returns the materialized kNNs of the specified id.
protected  Logging getLogger()
          Get the classes static logger.
 String getLongName()
          A "pretty" name for the result, for use in titles, captions and menus.
 List<DistanceResultPair<D>> getRKNN(DBID id)
          Returns the materialized RkNNs of the specified id.
<S extends Distance<S>>
RKNNQuery<O,S>
getRKNNQuery(DistanceQuery<O,S> distanceQuery, Object... hints)
          Get a KNN query object for the given distance query and k.
 String getShortName()
          A short name for the result, useful for file names.
private  void materializeKNNAndRKNNs(ArrayDBIDs ids, FiniteProgress progress)
          Materializes the kNNs and RkNNs of the specified object IDs.
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.
private  ArrayDBIDs updateKNNsAndRkNNs(DBIDs ids)
          Updates the kNNs and RkNNs after insertion of the specified ids.
 
Methods inherited from class de.lmu.ifi.dbs.elki.index.preprocessed.knn.MaterializeKNNPreprocessor
addKNNListener, delete, deleteAll, extractAndRemoveIDs, fireKNNsInserted, fireKNNsRemoved, get, insert, insertAll, removeKNNListener
 
Methods inherited from class de.lmu.ifi.dbs.elki.index.preprocessed.knn.AbstractMaterializeKNNPreprocessor
getDistanceFactory, getDistanceQuery, getK, getKNNQuery
 
Methods inherited from class de.lmu.ifi.dbs.elki.index.AbstractIndex
getPageFileStatistics
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.lmu.ifi.dbs.elki.index.Index
delete, deleteAll, getPageFileStatistics, insert, insertAll
 

Field Detail

logger

private static final Logging logger
Logger to use.


materialized_RkNN

private WritableDataStore<SortedSet<DistanceResultPair<D extends Distance<D>>>> materialized_RkNN
Additional data storage for RkNN.

Constructor Detail

MaterializeKNNAndRKNNPreprocessor

public MaterializeKNNAndRKNNPreprocessor(Relation<O> relation,
                                         DistanceFunction<? super O,D> distanceFunction,
                                         int k)
Constructor.

Parameters:
relation - Relation to process
distanceFunction - the distance function to use
k - query k
Method Detail

preprocess

protected void preprocess()
Description copied from class: MaterializeKNNPreprocessor
The actual preprocessing step.

Overrides:
preprocess in class MaterializeKNNPreprocessor<O,D extends Distance<D>>

materializeKNNAndRKNNs

private void materializeKNNAndRKNNs(ArrayDBIDs ids,
                                    FiniteProgress progress)
Materializes the kNNs and RkNNs of the specified object IDs.

Parameters:
ids - the IDs of the objects

objectsInserted

protected void objectsInserted(DBIDs ids)
Description copied from class: MaterializeKNNPreprocessor
Called after new objects have been inserted, updates the materialized neighborhood.

Overrides:
objectsInserted in class MaterializeKNNPreprocessor<O,D extends Distance<D>>
Parameters:
ids - the ids of the newly inserted objects

updateKNNsAndRkNNs

private ArrayDBIDs updateKNNsAndRkNNs(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(DBIDs ids)
Description copied from class: MaterializeKNNPreprocessor
Called after objects have been removed, updates the materialized neighborhood.

Overrides:
objectsRemoved in class MaterializeKNNPreprocessor<O,D extends Distance<D>>
Parameters:
ids - the ids of the removed objects

getKNN

public List<DistanceResultPair<D>> getKNN(DBID id)
Returns the materialized kNNs of the specified id.

Parameters:
id - the query id
Returns:
the kNNs

getRKNN

public List<DistanceResultPair<D>> getRKNN(DBID id)
Returns the materialized RkNNs of the specified id.

Parameters:
id - the query id
Returns:
the RkNNs

getRKNNQuery

public <S extends Distance<S>> RKNNQuery<O,S> getRKNNQuery(DistanceQuery<O,S> distanceQuery,
                                                           Object... hints)
Description copied from interface: RKNNIndex
Get a KNN query object for the given distance query and k. This function MAY return null, when the given distance is not supported!

Specified by:
getRKNNQuery in interface RKNNIndex<O>
Type Parameters:
S - Distance type
Parameters:
distanceQuery - Distance query
hints - Hints for the optimizer
Returns:
KNN Query object or null

getLongName

public String getLongName()
Description copied from interface: Result
A "pretty" name for the result, for use in titles, captions and menus.

Specified by:
getLongName in interface Result
Overrides:
getLongName in class MaterializeKNNPreprocessor<O,D extends Distance<D>>
Returns:
result name

getShortName

public String getShortName()
Description copied from interface: Result
A short name for the result, useful for file names.

Specified by:
getShortName in interface Result
Overrides:
getShortName in class MaterializeKNNPreprocessor<O,D extends Distance<D>>
Returns:
result name

getLogger

protected Logging getLogger()
Description copied from class: AbstractPreprocessorIndex
Get the classes static logger.

Overrides:
getLogger in class MaterializeKNNPreprocessor<O,D extends Distance<D>>
Returns:
Logger

Release 0.4.0 (2011-09-20_1324)