Search in sources :

Example 11 with DBID

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

the class MetricalIndexRangeQuery method doRangeQuery.

/**
 * Performs a range query on the specified subtree. It recursively traverses
 * all paths from the specified node, which cannot be excluded from leading to
 * qualifying objects.
 *
 * @param o_p the routing object of the specified node
 * @param node the root of the subtree to be traversed
 * @param q the query object
 * @param r_q the query range
 * @param result the list holding the query results
 */
private void doRangeQuery(DBID o_p, AbstractMTreeNode<O, ?, ?> node, O q, double r_q, ModifiableDoubleDBIDList result) {
    double d1 = 0.;
    if (o_p != null) {
        d1 = distanceQuery.distance(o_p, q);
        index.statistics.countDistanceCalculation();
    }
    if (!node.isLeaf()) {
        for (int i = 0; i < node.getNumEntries(); i++) {
            MTreeEntry entry = node.getEntry(i);
            DBID o_r = entry.getRoutingObjectID();
            double r_or = entry.getCoveringRadius();
            double d2 = o_p != null ? entry.getParentDistance() : 0.;
            double diff = Math.abs(d1 - d2);
            double sum = r_q + r_or;
            if (diff <= sum) {
                double d3 = distanceQuery.distance(o_r, q);
                index.statistics.countDistanceCalculation();
                if (d3 <= sum) {
                    AbstractMTreeNode<O, ?, ?> child = index.getNode(((DirectoryEntry) entry).getPageID());
                    doRangeQuery(o_r, child, q, r_q, result);
                }
            }
        }
    } else {
        for (int i = 0; i < node.getNumEntries(); i++) {
            MTreeEntry entry = node.getEntry(i);
            DBID o_j = entry.getRoutingObjectID();
            double d2 = o_p != null ? entry.getParentDistance() : 0.;
            double diff = Math.abs(d1 - d2);
            if (diff <= r_q) {
                double d3 = distanceQuery.distance(o_j, q);
                index.statistics.countDistanceCalculation();
                if (d3 <= r_q) {
                    result.add(d3, o_j);
                }
            }
        }
    }
}
Also used : DBID(de.lmu.ifi.dbs.elki.database.ids.DBID) MTreeEntry(de.lmu.ifi.dbs.elki.index.tree.metrical.mtreevariants.MTreeEntry)

Example 12 with DBID

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

the class AbstractMkTreeUnified method insertAll.

@Override
public void insertAll(List<E> entries) {
    if (entries.isEmpty()) {
        return;
    }
    if (!initialized) {
        initialize(entries.get(0));
    }
    ModifiableDBIDs ids = DBIDUtil.newArray(entries.size());
    // insert sequentially
    for (E 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);
    // adjust the knn distances
    kNNdistanceAdjustment(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) ModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)

Example 13 with DBID

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

the class RdKNNTree method bulkLoad.

/**
 * Performs a bulk load on this RTree with the specified data. Is called by
 * the constructor and should be overwritten by subclasses if necessary.
 */
@Override
protected void bulkLoad(List<RdKNNEntry> entries) {
    super.bulkLoad(entries);
    // adjust all knn distances
    ArrayModifiableDBIDs ids = DBIDUtil.newArray(entries.size());
    for (RdKNNEntry entry : entries) {
        DBID id = ((RdKNNLeafEntry) entry).getDBID();
        ids.add(id);
    }
    ids.sort();
    List<? extends KNNList> knnLists = knnQuery.getKNNForBulkDBIDs(ids, settings.k_max);
    adjustKNNDistance(getRootEntry(), ids, knnLists);
    // test
    doExtraIntegrityChecks();
}
Also used : ArrayModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs) DBID(de.lmu.ifi.dbs.elki.database.ids.DBID)

Example 14 with DBID

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

the class DeLiClu method run.

public ClusterOrder run(Database database, Relation<NV> relation) {
    Collection<DeLiCluTreeIndex<NV>> indexes = ResultUtil.filterResults(database.getHierarchy(), relation, DeLiCluTreeIndex.class);
    if (indexes.size() != 1) {
        throw new MissingPrerequisitesException("DeLiClu found " + indexes.size() + " DeLiCluTree indexes. DeLiClu needs a special index to operate, therefore you need to add this index to your database.");
    }
    DeLiCluTreeIndex<NV> index = indexes.iterator().next();
    if (!(getDistanceFunction() instanceof SpatialPrimitiveDistanceFunction<?>)) {
        throw new IllegalArgumentException("Distance Function must be an instance of " + SpatialPrimitiveDistanceFunction.class.getName());
    }
    @SuppressWarnings("unchecked") SpatialPrimitiveDistanceFunction<NV> distFunction = (SpatialPrimitiveDistanceFunction<NV>) getDistanceFunction();
    // first do the knn-Join
    if (LOG.isVerbose()) {
        LOG.verbose("knnJoin...");
    }
    Relation<KNNList> knns = knnJoin.run(relation);
    DBIDs ids = relation.getDBIDs();
    final int size = ids.size();
    FiniteProgress progress = LOG.isVerbose() ? new FiniteProgress("DeLiClu", size, LOG) : null;
    ClusterOrder clusterOrder = new ClusterOrder(ids, "DeLiClu Clustering", "deliclu-clustering");
    heap = new UpdatableHeap<>();
    // add start object to cluster order and (root, root) to priority queue
    DBID startID = DBIDUtil.deref(ids.iter());
    clusterOrder.add(startID, Double.POSITIVE_INFINITY, null);
    int numHandled = 1;
    index.setHandled(startID, relation.get(startID));
    SpatialDirectoryEntry rootEntry = (SpatialDirectoryEntry) index.getRootEntry();
    SpatialObjectPair spatialObjectPair = new SpatialObjectPair(0., rootEntry, rootEntry, true);
    heap.add(spatialObjectPair);
    while (numHandled < size) {
        if (heap.isEmpty()) {
            throw new AbortException("DeLiClu heap was empty when it shouldn't have been.");
        }
        SpatialObjectPair dataPair = heap.poll();
        // pair of nodes
        if (dataPair.isExpandable) {
            expandNodes(index, distFunction, dataPair, knns);
        } else // pair of objects
        {
            // set handled
            LeafEntry e1 = (LeafEntry) dataPair.entry1;
            LeafEntry e2 = (LeafEntry) dataPair.entry2;
            final DBID e1id = e1.getDBID();
            IndexTreePath<DeLiCluEntry> path = index.setHandled(e1id, relation.get(e1id));
            if (path == null) {
                throw new RuntimeException("snh: parent(" + e1id + ") = null!!!");
            }
            // add to cluster order
            clusterOrder.add(e1id, dataPair.distance, e2.getDBID());
            numHandled++;
            // reinsert expanded leafs
            reinsertExpanded(distFunction, index, path, knns);
            if (progress != null) {
                progress.setProcessed(numHandled, LOG);
            }
        }
    }
    LOG.ensureCompleted(progress);
    return clusterOrder;
}
Also used : DeLiCluEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.deliclu.DeLiCluEntry) DBID(de.lmu.ifi.dbs.elki.database.ids.DBID) LeafEntry(de.lmu.ifi.dbs.elki.index.tree.LeafEntry) DBIDs(de.lmu.ifi.dbs.elki.database.ids.DBIDs) FiniteProgress(de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress) MissingPrerequisitesException(de.lmu.ifi.dbs.elki.utilities.exceptions.MissingPrerequisitesException) SpatialDirectoryEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialDirectoryEntry) KNNList(de.lmu.ifi.dbs.elki.database.ids.KNNList) DeLiCluTreeIndex(de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.deliclu.DeLiCluTreeIndex) SpatialPrimitiveDistanceFunction(de.lmu.ifi.dbs.elki.distance.distancefunction.SpatialPrimitiveDistanceFunction) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)

Example 15 with DBID

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

the class KNNJoin method processDataPages.

/**
 * Processes the two data pages pr and ps and determines the k-nearest
 * neighbors of pr in ps.
 *
 * @param df the distance function to use
 * @param pr the first data page
 * @param ps the second data page
 * @param pr_heaps the knn lists for each data object
 * @param ps_heaps the knn lists for each data object in ps
 */
private void processDataPages(SpatialPrimitiveDistanceFunction<? super V> df, List<KNNHeap> pr_heaps, List<KNNHeap> ps_heaps, N pr, N ps) {
    // Compare pairwise
    for (int j = 0; j < ps.getNumEntries(); j++) {
        final SpatialPointLeafEntry s_e = (SpatialPointLeafEntry) ps.getEntry(j);
        final KNNHeap hj = ps_heaps != null ? ps_heaps.get(j) : null;
        final DBID s_id = s_e.getDBID();
        for (int i = 0; i < pr.getNumEntries(); i++) {
            final SpatialPointLeafEntry r_e = (SpatialPointLeafEntry) pr.getEntry(i);
            double distance = df.minDist(s_e, r_e);
            pr_heaps.get(i).insert(distance, s_id);
            if (hj != null) {
                hj.insert(distance, r_e.getDBID());
            }
        }
    }
}
Also used : SpatialPointLeafEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialPointLeafEntry) DBID(de.lmu.ifi.dbs.elki.database.ids.DBID) KNNHeap(de.lmu.ifi.dbs.elki.database.ids.KNNHeap)

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