Search in sources :

Example 6 with DBID

use of de.lmu.ifi.dbs.elki.database.ids.DBID 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 7 with DBID

use of de.lmu.ifi.dbs.elki.database.ids.DBID 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)

Example 8 with DBID

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

the class MkAppTreeIndex method initialize.

@Override
public void initialize() {
    super.initialize();
    List<MkAppEntry> objs = new ArrayList<>(relation.size());
    for (DBIDIter iter = relation.iterDBIDs(); iter.valid(); iter.advance()) {
        DBID id = DBIDUtil.deref(iter);
        final O object = relation.get(id);
        objs.add(createNewLeafEntry(id, object, Double.NaN));
    }
    insertAll(objs);
}
Also used : DBID(de.lmu.ifi.dbs.elki.database.ids.DBID) ArrayList(java.util.ArrayList) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 9 with DBID

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

the class MkCoPTree method reverseKNNQuery.

/**
 * Performs a reverse k-nearest neighbor query for the given object ID. The
 * query result is in ascending order to the distance to the query object.
 *
 * @param id the query object id
 * @param k the number of nearest neighbors to be returned
 * @return a List of the query results
 */
@Override
public DoubleDBIDList reverseKNNQuery(DBIDRef id, int k) {
    if (k > settings.kmax) {
        throw new IllegalArgumentException("Parameter k has to be less or equal than " + "parameter kmax of the MCop-Tree!");
    }
    ModifiableDoubleDBIDList result = DBIDUtil.newDistanceDBIDList();
    ModifiableDBIDs candidates = DBIDUtil.newArray();
    doReverseKNNQuery(k, id, result, candidates);
    // refinement of candidates
    Map<DBID, KNNList> knnLists = batchNN(getRoot(), candidates, k);
    result.sort();
    for (DBIDIter iter = candidates.iter(); iter.valid(); iter.advance()) {
        DBID cid = DBIDUtil.deref(iter);
        KNNList cands = knnLists.get(cid);
        for (DoubleDBIDListIter iter2 = cands.iter(); iter2.valid(); iter2.advance()) {
            if (DBIDUtil.equal(id, iter2)) {
                result.add(iter2.doubleValue(), cid);
                break;
            }
        }
    }
    result.sort();
    // rkNNStatistics.addResults(result.size());
    return result;
}
Also used : DoubleDBIDListIter(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter) ModifiableDoubleDBIDList(de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList) KNNList(de.lmu.ifi.dbs.elki.database.ids.KNNList) DBID(de.lmu.ifi.dbs.elki.database.ids.DBID) ModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 10 with DBID

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

the class MkCoPTreeIndex method initialize.

@Override
public void initialize() {
    super.initialize();
    List<MkCoPEntry> objs = new ArrayList<>(relation.size());
    for (DBIDIter iter = relation.iterDBIDs(); iter.valid(); iter.advance()) {
        // FIXME: expensive
        DBID id = DBIDUtil.deref(iter);
        final O object = relation.get(id);
        objs.add(createNewLeafEntry(id, object, Double.NaN));
    }
    insertAll(objs);
}
Also used : DBID(de.lmu.ifi.dbs.elki.database.ids.DBID) ArrayList(java.util.ArrayList) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Aggregations

DBID (de.lmu.ifi.dbs.elki.database.ids.DBID)42 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)20 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)11 ArrayList (java.util.ArrayList)10 KNNList (de.lmu.ifi.dbs.elki.database.ids.KNNList)9 ModifiableDoubleDBIDList (de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList)9 DoubleDBIDListIter (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter)6 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)5 HashSetModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.HashSetModifiableDBIDs)5 Database (de.lmu.ifi.dbs.elki.database.Database)4 ArrayModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs)4 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)4 HashMap (java.util.HashMap)4 KNNHeap (de.lmu.ifi.dbs.elki.database.ids.KNNHeap)3 MTreeEntry (de.lmu.ifi.dbs.elki.index.tree.metrical.mtreevariants.MTreeEntry)3 Test (org.junit.Test)3 AbstractClusterAlgorithmTest (de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest)2 SLINK (de.lmu.ifi.dbs.elki.algorithm.clustering.hierarchical.SLINK)2 CutDendrogramByHeight (de.lmu.ifi.dbs.elki.algorithm.clustering.hierarchical.extraction.CutDendrogramByHeight)2 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)2