Search in sources :

Example 1 with RKNNQuery

use of de.lmu.ifi.dbs.elki.database.query.rknn.RKNNQuery in project elki by elki-project.

the class OnlineLOF method getKNNAndRkNNQueries.

/**
 * Get the kNN and rkNN queries for the algorithm.
 *
 * @param relation Data
 * @param stepprog Progress logger
 * @return the kNN and rkNN queries
 */
private Pair<Pair<KNNQuery<O>, KNNQuery<O>>, Pair<RKNNQuery<O>, RKNNQuery<O>>> getKNNAndRkNNQueries(Database database, Relation<O> relation, StepProgress stepprog) {
    DistanceQuery<O> drefQ = database.getDistanceQuery(relation, referenceDistanceFunction);
    // Use "HEAVY" flag, since this is an online algorithm
    KNNQuery<O> kNNRefer = database.getKNNQuery(drefQ, krefer, DatabaseQuery.HINT_HEAVY_USE, DatabaseQuery.HINT_OPTIMIZED_ONLY, DatabaseQuery.HINT_NO_CACHE);
    RKNNQuery<O> rkNNRefer = database.getRKNNQuery(drefQ, DatabaseQuery.HINT_HEAVY_USE, DatabaseQuery.HINT_OPTIMIZED_ONLY, DatabaseQuery.HINT_NO_CACHE);
    // No optimized kNN query or RkNN query - use a preprocessor!
    if (kNNRefer == null || rkNNRefer == null) {
        if (stepprog != null) {
            stepprog.beginStep(1, "Materializing neighborhood w.r.t. reference neighborhood distance function.", LOG);
        }
        MaterializeKNNAndRKNNPreprocessor<O> preproc = new MaterializeKNNAndRKNNPreprocessor<>(relation, referenceDistanceFunction, krefer);
        kNNRefer = preproc.getKNNQuery(drefQ, krefer, DatabaseQuery.HINT_HEAVY_USE);
        rkNNRefer = preproc.getRKNNQuery(drefQ, krefer, DatabaseQuery.HINT_HEAVY_USE);
        // add as index
        database.getHierarchy().add(relation, preproc);
    } else {
        if (stepprog != null) {
            stepprog.beginStep(1, "Optimized neighborhood w.r.t. reference neighborhood distance function provided by database.", LOG);
        }
    }
    DistanceQuery<O> dreachQ = database.getDistanceQuery(relation, reachabilityDistanceFunction);
    KNNQuery<O> kNNReach = database.getKNNQuery(dreachQ, kreach, DatabaseQuery.HINT_HEAVY_USE, DatabaseQuery.HINT_OPTIMIZED_ONLY, DatabaseQuery.HINT_NO_CACHE);
    RKNNQuery<O> rkNNReach = database.getRKNNQuery(dreachQ, DatabaseQuery.HINT_HEAVY_USE, DatabaseQuery.HINT_OPTIMIZED_ONLY, DatabaseQuery.HINT_NO_CACHE);
    if (kNNReach == null || rkNNReach == null) {
        if (stepprog != null) {
            stepprog.beginStep(2, "Materializing neighborhood w.r.t. reachability distance function.", LOG);
        }
        ListParameterization config = new ListParameterization();
        config.addParameter(AbstractMaterializeKNNPreprocessor.Factory.DISTANCE_FUNCTION_ID, reachabilityDistanceFunction);
        config.addParameter(AbstractMaterializeKNNPreprocessor.Factory.K_ID, kreach);
        MaterializeKNNAndRKNNPreprocessor<O> preproc = new MaterializeKNNAndRKNNPreprocessor<>(relation, reachabilityDistanceFunction, kreach);
        kNNReach = preproc.getKNNQuery(dreachQ, kreach, DatabaseQuery.HINT_HEAVY_USE);
        rkNNReach = preproc.getRKNNQuery(dreachQ, kreach, DatabaseQuery.HINT_HEAVY_USE);
        // add as index
        database.getHierarchy().add(relation, preproc);
    }
    Pair<KNNQuery<O>, KNNQuery<O>> kNNPair = new Pair<>(kNNRefer, kNNReach);
    Pair<RKNNQuery<O>, RKNNQuery<O>> rkNNPair = new Pair<>(rkNNRefer, rkNNReach);
    return new Pair<>(kNNPair, rkNNPair);
}
Also used : RKNNQuery(de.lmu.ifi.dbs.elki.database.query.rknn.RKNNQuery) MaterializeKNNAndRKNNPreprocessor(de.lmu.ifi.dbs.elki.index.preprocessed.knn.MaterializeKNNAndRKNNPreprocessor) PreprocessorKNNQuery(de.lmu.ifi.dbs.elki.database.query.knn.PreprocessorKNNQuery) RKNNQuery(de.lmu.ifi.dbs.elki.database.query.rknn.RKNNQuery) KNNQuery(de.lmu.ifi.dbs.elki.database.query.knn.KNNQuery) ListParameterization(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization) Pair(de.lmu.ifi.dbs.elki.utilities.pairs.Pair)

Aggregations

KNNQuery (de.lmu.ifi.dbs.elki.database.query.knn.KNNQuery)1 PreprocessorKNNQuery (de.lmu.ifi.dbs.elki.database.query.knn.PreprocessorKNNQuery)1 RKNNQuery (de.lmu.ifi.dbs.elki.database.query.rknn.RKNNQuery)1 MaterializeKNNAndRKNNPreprocessor (de.lmu.ifi.dbs.elki.index.preprocessed.knn.MaterializeKNNAndRKNNPreprocessor)1 ListParameterization (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization)1 Pair (de.lmu.ifi.dbs.elki.utilities.pairs.Pair)1