Search in sources :

Example 16 with SpatialEntry

use of de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry in project elki by elki-project.

the class AbstractXTree method computeHeight.

/**
 * Computes the height of this XTree. Is called by the constructor. and should
 * be overwritten by subclasses if necessary.
 *
 * @return the height of this XTree
 */
@Override
protected int computeHeight() {
    N node = getRoot();
    int tHeight = 1;
    // compute height
    while (!node.isLeaf() && node.getNumEntries() != 0) {
        SpatialEntry entry = node.getEntry(0);
        node = getNode(entry);
        tHeight++;
    }
    return tHeight;
}
Also used : SpatialEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)

Example 17 with SpatialEntry

use of de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry in project elki by elki-project.

the class RStarTreeKNNQuery method batchNN.

/**
 * Performs a batch knn query.
 *
 * @param node the node for which the query should be performed
 * @param knnLists a map containing the knn lists for each query objects
 */
protected void batchNN(AbstractRStarTreeNode<?, ?> node, Map<DBID, KNNHeap> knnLists) {
    if (node.isLeaf()) {
        for (int i = 0; i < node.getNumEntries(); i++) {
            SpatialEntry p = node.getEntry(i);
            for (Entry<DBID, KNNHeap> ent : knnLists.entrySet()) {
                final DBID q = ent.getKey();
                final KNNHeap knns_q = ent.getValue();
                double knn_q_maxDist = knns_q.getKNNDistance();
                DBID pid = ((LeafEntry) p).getDBID();
                // FIXME: objects are NOT accessible by DBID in a plain R-tree
                // context!
                double dist_pq = distanceFunction.distance(relation.get(pid), relation.get(q));
                tree.statistics.countDistanceCalculation();
                if (dist_pq <= knn_q_maxDist) {
                    knns_q.insert(dist_pq, pid);
                }
            }
        }
    } else {
        ModifiableDBIDs ids = DBIDUtil.newArray(knnLists.size());
        for (DBID id : knnLists.keySet()) {
            ids.add(id);
        }
        List<DoubleDistanceEntry> entries = getSortedEntries(node, ids);
        for (DoubleDistanceEntry distEntry : entries) {
            double minDist = distEntry.distance;
            for (Entry<DBID, KNNHeap> ent : knnLists.entrySet()) {
                final KNNHeap knns_q = ent.getValue();
                double knn_q_maxDist = knns_q.getKNNDistance();
                if (minDist <= knn_q_maxDist) {
                    SpatialEntry entry = distEntry.entry;
                    AbstractRStarTreeNode<?, ?> child = tree.getNode(((DirectoryEntry) entry).getPageID());
                    batchNN(child, knnLists);
                    break;
                }
            }
        }
    }
}
Also used : SpatialPointLeafEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialPointLeafEntry) LeafEntry(de.lmu.ifi.dbs.elki.index.tree.LeafEntry) SpatialEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)

Example 18 with SpatialEntry

use of de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry in project elki by elki-project.

the class RStarTreeKNNQuery method getSortedEntries.

/**
 * Sorts the entries of the specified node according to their minimum distance
 * to the specified objects.
 *
 * @param node the node
 * @param ids the id of the objects
 * @return a list of the sorted entries
 */
protected List<DoubleDistanceEntry> getSortedEntries(AbstractRStarTreeNode<?, ?> node, DBIDs ids) {
    List<DoubleDistanceEntry> result = new ArrayList<>();
    for (int i = 0; i < node.getNumEntries(); i++) {
        SpatialEntry entry = node.getEntry(i);
        double minMinDist = Double.MAX_VALUE;
        for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
            double minDist = distanceFunction.minDist(entry, relation.get(iter));
            tree.statistics.countDistanceCalculation();
            minMinDist = Math.min(minDist, minMinDist);
        }
        result.add(new DoubleDistanceEntry(entry, minMinDist));
    }
    Collections.sort(result);
    return result;
}
Also used : SpatialEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)

Example 19 with SpatialEntry

use of de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry in project elki by elki-project.

the class FlatRStarTree 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<SpatialEntry> spatialObjects) {
    if (!initialized) {
        initialize(spatialObjects.get(0));
    }
    // create leaf nodes
    getFile().setNextPageID(getRootID() + 1);
    List<SpatialEntry> nodes = createBulkLeafNodes(spatialObjects);
    int numNodes = nodes.size();
    if (LOG.isDebugging()) {
        LOG.debugFine("  numLeafNodes = " + numNodes);
    }
    // create root
    root = createNewDirectoryNode();
    root.setPageID(getRootID());
    for (SpatialEntry entry : nodes) {
        root.addDirectoryEntry(entry);
    }
    numNodes++;
    setHeight(2);
    if (LOG.isDebugging()) {
        StringBuilder msg = new StringBuilder();
        msg.append("  root = ").append(getRoot());
        msg.append("\n  numNodes = ").append(numNodes);
        msg.append("\n  height = ").append(getHeight());
        LOG.debugFine(msg.toString() + "\n");
    }
    doExtraIntegrityChecks();
}
Also used : SpatialEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)

Example 20 with SpatialEntry

use of de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry in project elki by elki-project.

the class FlatRStarTreeIndex method insertAll.

/**
 * Inserts the specified objects into this index. If a bulk load mode is
 * implemented, the objects are inserted in one bulk.
 *
 * @param ids the objects to be inserted
 */
@Override
public final void insertAll(DBIDs ids) {
    if (ids.isEmpty() || (ids.size() == 1)) {
        return;
    }
    // Make an example leaf
    if (canBulkLoad()) {
        List<SpatialEntry> leafs = new ArrayList<>(ids.size());
        for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
            leafs.add(createNewLeafEntry(DBIDUtil.deref(iter)));
        }
        bulkLoad(leafs);
    } else {
        for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
            insert(iter);
        }
    }
    doExtraIntegrityChecks();
}
Also used : ArrayList(java.util.ArrayList) SpatialEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Aggregations

SpatialEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)21 ModifiableHyperBoundingBox (de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox)5 ArrayList (java.util.ArrayList)5 HyperBoundingBox (de.lmu.ifi.dbs.elki.data.HyperBoundingBox)4 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)4 LeafEntry (de.lmu.ifi.dbs.elki.index.tree.LeafEntry)4 SpatialPointLeafEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialPointLeafEntry)4 SpatialDirectoryEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialDirectoryEntry)3 Database (de.lmu.ifi.dbs.elki.database.Database)2 SplitHistory (de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.xtree.util.SplitHistory)2 MeanVariance (de.lmu.ifi.dbs.elki.math.MeanVariance)2 DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)1 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)1 SpatialComparable (de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable)1 StaticArrayDatabase (de.lmu.ifi.dbs.elki.database.StaticArrayDatabase)1 DBID (de.lmu.ifi.dbs.elki.database.ids.DBID)1 Relation (de.lmu.ifi.dbs.elki.database.relation.Relation)1 BreadthFirstEnumeration (de.lmu.ifi.dbs.elki.index.tree.BreadthFirstEnumeration)1 Entry (de.lmu.ifi.dbs.elki.index.tree.Entry)1 IndexTreePath (de.lmu.ifi.dbs.elki.index.tree.IndexTreePath)1