Class MaterializeKNNAndRKNNPreprocessor<O>

  • Type Parameters:
    O - the type of database objects the preprocessor can be applied to the type of distance the used distance function will return
    All Implemented Interfaces:
    DynamicIndex, Index, KNNIndex<O>, RKNNIndex<O>

    @Title("Materialize kNN and RkNN Neighborhood preprocessor")
    @Description("Materializes the k nearest neighbors and the reverse k nearest neighbors of objects of a database.")
    public class MaterializeKNNAndRKNNPreprocessor<O>
    extends MaterializeKNNPreprocessor<O>
    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.

    BUG: This class currently does not seem able to correctly keep track of the nearest neighbors?

    TODO: for better performance, we would need some ModifiableDoubleDBIDHashSet or TreeSet to store the rkNN.

    Since:
    0.4.0
    Author:
    Elke Achtert
    • Constructor Detail

      • MaterializeKNNAndRKNNPreprocessor

        public MaterializeKNNAndRKNNPreprocessor​(Relation<O> relation,
                                                 Distance<? super O> distance,
                                                 int k)
        Constructor.
        Parameters:
        relation - Relation to process
        distance - the distance function to use
        k - query k
    • Method Detail

      • 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
      • updateKNNsAndRkNNs

        private DBIDs 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
      • getKNN

        public KNNList getKNN​(DBID id)
        Returns the materialized kNNs of the specified id.
        Parameters:
        id - the query id
        Returns:
        the kNNs
      • getRKNN

        public DoubleDBIDList getRKNN​(DBIDRef id)
        Returns the materialized RkNNs of the specified id.
        Parameters:
        id - the query id
        Returns:
        the RkNNs
      • rkNNByObject

        public RKNNSearcher<O> rkNNByObject​(DistanceQuery<O> distanceQuery,
                                            int maxk,
                                            int flags)
        Description copied from interface: RKNNIndex
        Get a RKNN query object for the given distance query and k.

        This function MAY return null, when the given distance is not supported!

        Specified by:
        rkNNByObject in interface RKNNIndex<O>
        Parameters:
        distanceQuery - Distance query
        maxk - Maximum k for RkNN query
        flags - Hints for the optimizer
        Returns:
        RKNN Query object or null
      • rkNNByDBID

        public RKNNSearcher<DBIDRef> rkNNByDBID​(DistanceQuery<O> distanceQuery,
                                                int maxk,
                                                int flags)
        Description copied from interface: RKNNIndex
        Get a RKNN query object for the given distance query and k.

        This function MAY return null, when the given distance is not supported!

        Specified by:
        rkNNByDBID in interface RKNNIndex<O>
        Parameters:
        distanceQuery - Distance query
        maxk - Maximum k for RkNN query
        flags - Hints for the optimizer
        Returns:
        RKNN Query object or null