Package elki.index.invertedlist
Class InMemoryInvertedIndex<V extends NumberVector>
- java.lang.Object
-
- elki.index.invertedlist.InMemoryInvertedIndex<V>
-
- Type Parameters:
V- Vector type
- All Implemented Interfaces:
Index,KNNIndex<V>,RangeIndex<V>
public class InMemoryInvertedIndex<V extends NumberVector> extends java.lang.Object implements KNNIndex<V>, RangeIndex<V>
Simple index using inverted lists, for cosine distance only.TODO: support additional distances.
- Since:
- 0.7.0
- Author:
- Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classInMemoryInvertedIndex.ArcCosineKNNQuerykNN query object, for arc cosine distance.protected classInMemoryInvertedIndex.ArcCosineRangeQueryRange query object, for cosine distance.protected classInMemoryInvertedIndex.CosineKNNQuerykNN query object, for cosine distance.protected classInMemoryInvertedIndex.CosineRangeQuerykNN query object, for cosine distance.static classInMemoryInvertedIndex.Factory<V extends NumberVector>Index factory
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ArrayList<ModifiableDoubleDBIDList>indexInverted index.protected WritableDoubleDataStorelengthLength storage.private static LoggingLOGClass logger.protected Relation<V>relationThe representation we are bound to.
-
Constructor Summary
Constructors Constructor Description InMemoryInvertedIndex(Relation<V> relation)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private ModifiableDoubleDBIDListgetOrCreateColumn(int dim)Get (or create) a column.private voidindexDense(DBIDRef ref, V obj)Index a single (dense) instance.private voidindexSparse(DBIDRef ref, SparseNumberVector obj)Index a single (sparse) instance.voidinitialize()Initialize the index.KNNSearcher<V>kNNByObject(DistanceQuery<V> distanceQuery, int maxk, int flags)Get a KNN query object for the given distance query and k.voidlogStatistics()Send statistics to the logger, if enabled.private doublenaiveQuery(V obj, WritableDoubleDataStore scores, HashSetModifiableDBIDs cands)Query the most similar objects, abstract version.private doublenaiveQueryDense(NumberVector obj, WritableDoubleDataStore scores, HashSetModifiableDBIDs cands)Query the most similar objects, dense version.private doublenaiveQuerySparse(SparseNumberVector obj, WritableDoubleDataStore scores, HashSetModifiableDBIDs cands)Query the most similar objects, sparse version.RangeSearcher<V>rangeByObject(DistanceQuery<V> distanceQuery, double maxradius, int flags)Get a range query object for the given distance query and k.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface elki.index.RangeIndex
rangeByDBID
-
-
-
-
Field Detail
-
LOG
private static final Logging LOG
Class logger.
-
relation
protected final Relation<V extends NumberVector> relation
The representation we are bound to.
-
index
protected java.util.ArrayList<ModifiableDoubleDBIDList> index
Inverted index.
-
length
protected WritableDoubleDataStore length
Length storage.
-
-
Method Detail
-
initialize
public void initialize()
Description copied from interface:IndexInitialize the index. For static indexes, this is the moment the index is bulk loaded.- Specified by:
initializein interfaceIndex
-
indexSparse
private void indexSparse(DBIDRef ref, SparseNumberVector obj)
Index a single (sparse) instance.- Parameters:
ref- Object referenceobj- Object to index.
-
indexDense
private void indexDense(DBIDRef ref, V obj)
Index a single (dense) instance.- Parameters:
ref- Object referenceobj- Object to index.
-
getOrCreateColumn
private ModifiableDoubleDBIDList getOrCreateColumn(int dim)
Get (or create) a column.- Parameters:
dim- Dimension- Returns:
- Column
-
naiveQuerySparse
private double naiveQuerySparse(SparseNumberVector obj, WritableDoubleDataStore scores, HashSetModifiableDBIDs cands)
Query the most similar objects, sparse version.- Parameters:
obj- Query objectscores- Score storagecands- Non-zero objects set- Returns:
- Result
-
naiveQueryDense
private double naiveQueryDense(NumberVector obj, WritableDoubleDataStore scores, HashSetModifiableDBIDs cands)
Query the most similar objects, dense version.- Parameters:
obj- Query objectscores- Score storagecands- Non-zero objects set- Returns:
- Result
-
naiveQuery
private double naiveQuery(V obj, WritableDoubleDataStore scores, HashSetModifiableDBIDs cands)
Query the most similar objects, abstract version.- Parameters:
obj- Query objectscores- Score storage (must be initialized with zeros!)cands- Non-zero objects set (must be empty)- Returns:
- Result
-
logStatistics
public void logStatistics()
Description copied from interface:IndexSend statistics to the logger, if enabled.Note: you must have set the logging level appropriately before initializing the index! Otherwise, the index might not have collected the desired statistics.
- Specified by:
logStatisticsin interfaceIndex
-
kNNByObject
public KNNSearcher<V> kNNByObject(DistanceQuery<V> distanceQuery, int maxk, int flags)
Description copied from interface:KNNIndexGet 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:
kNNByObjectin interfaceKNNIndex<V extends NumberVector>- Parameters:
distanceQuery- Distance querymaxk- Maximum value of kflags- Hints for the optimizer- Returns:
- KNN Query object or
null
-
rangeByObject
public RangeSearcher<V> rangeByObject(DistanceQuery<V> distanceQuery, double maxradius, int flags)
Description copied from interface:RangeIndexGet a range query object for the given distance query and k.This function MAY return null, when the given distance is not supported!
- Specified by:
rangeByObjectin interfaceRangeIndex<V extends NumberVector>- Parameters:
distanceQuery- Distance querymaxradius- Maximum rangeflags- Hints for the optimizer- Returns:
- KNN Query object or
null
-
-