Search in sources :

Example 6 with KNNList

use of de.lmu.ifi.dbs.elki.database.ids.KNNList in project elki by elki-project.

the class PreprocessorKNNQuery method getKNNForDBID.

@Override
public KNNList getKNNForDBID(DBIDRef id, int k) {
    if (!warned && k > preprocessor.getK()) {
        getLogger().warning("Requested more neighbors than preprocessed: requested " + k + " preprocessed " + preprocessor.getK(), new Throwable());
        warned = true;
    }
    KNNList dr = preprocessor.get(id);
    if (k < preprocessor.getK() && k < dr.size()) {
        return getSublist(dr, k);
    }
    return dr;
}
Also used : KNNList(de.lmu.ifi.dbs.elki.database.ids.KNNList)

Example 7 with KNNList

use of de.lmu.ifi.dbs.elki.database.ids.KNNList in project elki by elki-project.

the class MkMaxTreeIndex method createNewLeafEntry.

/**
 * @return a new MkMaxLeafEntry representing the specified data object
 */
protected MkMaxLeafEntry createNewLeafEntry(DBID id, O object, double parentDistance) {
    KNNList knns = knnq.getKNNForObject(object, getKmax() - 1);
    double knnDistance = knns.getKNNDistance();
    return new MkMaxLeafEntry(id, parentDistance, knnDistance);
}
Also used : KNNList(de.lmu.ifi.dbs.elki.database.ids.KNNList)

Example 8 with KNNList

use of de.lmu.ifi.dbs.elki.database.ids.KNNList in project elki by elki-project.

the class MkTabTree method kNNdistanceAdjustment.

@Override
protected void kNNdistanceAdjustment(MkTabEntry entry, Map<DBID, KNNList> knnLists) {
    MkTabTreeNode<O> node = getNode(entry);
    double[] knnDistances_node = initKnnDistanceList();
    if (node.isLeaf()) {
        for (int i = 0; i < node.getNumEntries(); i++) {
            MkTabEntry leafEntry = node.getEntry(i);
            KNNList knns = knnLists.get(getPageID(leafEntry));
            double[] distances = new double[knns.size()];
            int j = 0;
            for (DoubleDBIDListIter iter = knns.iter(); iter.valid(); iter.advance(), j++) {
                distances[j] = iter.doubleValue();
            }
            leafEntry.setKnnDistances(distances);
            // FIXME: save copy
            knnDistances_node = max(knnDistances_node, leafEntry.getKnnDistances());
        }
    } else {
        for (int i = 0; i < node.getNumEntries(); i++) {
            MkTabEntry dirEntry = node.getEntry(i);
            kNNdistanceAdjustment(dirEntry, knnLists);
            // FIXME: save copy
            knnDistances_node = max(knnDistances_node, dirEntry.getKnnDistances());
        }
    }
    entry.setKnnDistances(knnDistances_node);
}
Also used : DoubleDBIDListIter(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter) KNNList(de.lmu.ifi.dbs.elki.database.ids.KNNList)

Example 9 with KNNList

use of de.lmu.ifi.dbs.elki.database.ids.KNNList in project elki by elki-project.

the class MkAppTree method insertAll.

/**
 * Inserts the specified objects into this MkApp-Tree.
 *
 * @param entries the entries to be inserted
 */
@Override
public void insertAll(List<MkAppEntry> entries) {
    if (entries.isEmpty()) {
        return;
    }
    if (LOG.isDebugging()) {
        LOG.debugFine("insert " + entries + "\n");
    }
    if (!initialized) {
        initialize(entries.get(0));
    }
    ModifiableDBIDs ids = DBIDUtil.newArray(entries.size());
    // insert
    for (MkAppEntry entry : entries) {
        ids.add(entry.getRoutingObjectID());
        // insert the object
        super.insert(entry, false);
    }
    // do batch nn
    Map<DBID, KNNList> knnLists = batchNN(getRoot(), ids, settings.kmax + 1);
    // adjust the knn distances
    adjustApproximatedKNNDistances(getRootEntry(), knnLists);
    if (EXTRA_INTEGRITY_CHECKS) {
        getRoot().integrityCheck(this, getRootEntry());
    }
}
Also used : KNNList(de.lmu.ifi.dbs.elki.database.ids.KNNList) DBID(de.lmu.ifi.dbs.elki.database.ids.DBID) ArrayModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs) ModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)

Example 10 with KNNList

use of de.lmu.ifi.dbs.elki.database.ids.KNNList in project elki by elki-project.

the class MkAppTree method getMeanKNNList.

private double[] getMeanKNNList(DBIDs ids, Map<DBID, KNNList> knnLists) {
    double[] means = new double[settings.kmax];
    for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
        DBID id = DBIDUtil.deref(iter);
        KNNList knns = knnLists.get(id);
        int k = 0;
        for (DoubleDBIDListIter it = knns.iter(); k < settings.kmax && it.valid(); it.advance(), k++) {
            means[k] += it.doubleValue();
        }
    }
    for (int k = 0; k < settings.kmax; k++) {
        means[k] /= ids.size();
    }
    return means;
}
Also used : DoubleDBIDListIter(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter) KNNList(de.lmu.ifi.dbs.elki.database.ids.KNNList) DBID(de.lmu.ifi.dbs.elki.database.ids.DBID) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Aggregations

KNNList (de.lmu.ifi.dbs.elki.database.ids.KNNList)80 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)53 DoubleDBIDListIter (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter)38 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)32 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)21 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)20 DoubleRelation (de.lmu.ifi.dbs.elki.database.relation.DoubleRelation)18 MaterializedDoubleRelation (de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation)18 OutlierResult (de.lmu.ifi.dbs.elki.result.outlier.OutlierResult)18 OutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.OutlierScoreMeta)18 DoubleMinMax (de.lmu.ifi.dbs.elki.math.DoubleMinMax)15 ArrayList (java.util.ArrayList)11 ArrayDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs)10 ModifiableDoubleDBIDList (de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList)9 BasicOutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.BasicOutlierScoreMeta)9 DBID (de.lmu.ifi.dbs.elki.database.ids.DBID)8 KNNHeap (de.lmu.ifi.dbs.elki.database.ids.KNNHeap)8 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)8 MeanVariance (de.lmu.ifi.dbs.elki.math.MeanVariance)8 ArrayModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs)6