Class InMemoryInvertedIndex<V extends NumberVector>

  • 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
    • Constructor Detail

      • InMemoryInvertedIndex

        public InMemoryInvertedIndex​(Relation<V> relation)
        Constructor.
        Parameters:
        relation - Data.
    • Method Detail

      • initialize

        public void initialize()
        Description copied from interface: Index
        Initialize the index. For static indexes, this is the moment the index is bulk loaded.
        Specified by:
        initialize in interface Index
      • indexSparse

        private void indexSparse​(DBIDRef ref,
                                 SparseNumberVector obj)
        Index a single (sparse) instance.
        Parameters:
        ref - Object reference
        obj - Object to index.
      • indexDense

        private void indexDense​(DBIDRef ref,
                                V obj)
        Index a single (dense) instance.
        Parameters:
        ref - Object reference
        obj - Object to index.
      • getOrCreateColumn

        private ModifiableDoubleDBIDList getOrCreateColumn​(int dim)
        Get (or create) a column.
        Parameters:
        dim - Dimension
        Returns:
        Column
      • naiveQuery

        private double naiveQuery​(V obj,
                                  WritableDoubleDataStore scores,
                                  HashSetModifiableDBIDs cands)
        Query the most similar objects, abstract version.
        Parameters:
        obj - Query object
        scores - 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: Index
        Send 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:
        logStatistics in interface Index
      • kNNByObject

        public KNNSearcher<V> kNNByObject​(DistanceQuery<V> distanceQuery,
                                          int maxk,
                                          int flags)
        Description copied from interface: KNNIndex
        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:
        kNNByObject in interface KNNIndex<V extends NumberVector>
        Parameters:
        distanceQuery - Distance query
        maxk - Maximum value of k
        flags - 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: RangeIndex
        Get 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:
        rangeByObject in interface RangeIndex<V extends NumberVector>
        Parameters:
        distanceQuery - Distance query
        maxradius - Maximum range
        flags - Hints for the optimizer
        Returns:
        KNN Query object or null