Search in sources :

Example 6 with SpatialDirectoryEntry

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

the class EuclideanRStarTreeRangeQuery method getRangeForObject.

@Override
public void getRangeForObject(O object, double range, ModifiableDoubleDBIDList result) {
    tree.statistics.countRangeQuery();
    final double sqepsilon = range * range;
    // Processing queue.
    int[] pq = new int[101];
    int ps = 0;
    pq[ps++] = tree.getRootID();
    // search in tree
    while (ps > 0) {
        // Pop last.
        int pqNode = pq[--ps];
        AbstractRStarTreeNode<?, ?> node = tree.getNode(pqNode);
        final int numEntries = node.getNumEntries();
        if (node.isLeaf()) {
            for (int i = 0; i < numEntries; i++) {
                SpatialPointLeafEntry entry = (SpatialPointLeafEntry) node.getEntry(i);
                double distance = SQUARED.minDist(object, entry);
                tree.statistics.countDistanceCalculation();
                if (distance <= sqepsilon) {
                    result.add(FastMath.sqrt(distance), entry.getDBID());
                }
            }
        } else {
            for (int i = 0; i < numEntries; i++) {
                SpatialDirectoryEntry entry = (SpatialDirectoryEntry) node.getEntry(i);
                double distance = SQUARED.minDist(object, entry);
                if (distance <= sqepsilon) {
                    if (ps == pq.length) {
                        // Resize:
                        pq = Arrays.copyOf(pq, pq.length + (pq.length >>> 1));
                    }
                    pq[ps++] = entry.getPageID();
                }
            }
        }
    }
}
Also used : SpatialPointLeafEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialPointLeafEntry) SpatialDirectoryEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialDirectoryEntry)

Example 7 with SpatialDirectoryEntry

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

the class RStarTreeRangeQuery method getRangeForObject.

@Override
public void getRangeForObject(O obj, double range, ModifiableDoubleDBIDList result) {
    tree.statistics.countRangeQuery();
    // Processing queue.
    int[] pq = new int[101];
    int ps = 0;
    pq[ps++] = tree.getRootID();
    // search in tree
    while (ps > 0) {
        // Pop last.
        int pqNode = pq[--ps];
        AbstractRStarTreeNode<?, ?> node = tree.getNode(pqNode);
        final int numEntries = node.getNumEntries();
        if (node.isLeaf()) {
            for (int i = 0; i < numEntries; i++) {
                SpatialPointLeafEntry entry = (SpatialPointLeafEntry) node.getEntry(i);
                double distance = distanceFunction.minDist(obj, entry);
                tree.statistics.countDistanceCalculation();
                if (distance <= range) {
                    result.add(distance, entry.getDBID());
                }
            }
        } else {
            for (int i = 0; i < numEntries; i++) {
                SpatialDirectoryEntry entry = (SpatialDirectoryEntry) node.getEntry(i);
                double distance = distanceFunction.minDist(obj, entry);
                if (distance <= range) {
                    if (ps == pq.length) {
                        pq = Arrays.copyOf(pq, pq.length + (pq.length >>> 1));
                    }
                    pq[ps++] = entry.getPageID();
                }
            }
        }
    }
}
Also used : SpatialPointLeafEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialPointLeafEntry) SpatialDirectoryEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialDirectoryEntry)

Example 8 with SpatialDirectoryEntry

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

the class AbstractRStarTree method initializeCapacities.

@Override
protected void initializeCapacities(E exampleLeaf) {
    /* Simulate the creation of a leaf page to get the page capacity */
    try {
        int cap = 0;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        SpatialPointLeafEntry sl = new SpatialPointLeafEntry(DBIDUtil.importInteger(0), new double[exampleLeaf.getDimensionality()]);
        while (baos.size() <= getPageSize()) {
            sl.writeExternal(oos);
            oos.flush();
            cap++;
        }
        // the last one caused the page to overflow.
        leafCapacity = cap - 1;
    } catch (IOException e) {
        throw new AbortException("Error determining page sizes.", e);
    }
    /* Simulate the creation of a directory page to get the capacity */
    try {
        int cap = 0;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        ModifiableHyperBoundingBox hb = new ModifiableHyperBoundingBox(new double[exampleLeaf.getDimensionality()], new double[exampleLeaf.getDimensionality()]);
        SpatialDirectoryEntry sl = new SpatialDirectoryEntry(0, hb);
        while (baos.size() <= getPageSize()) {
            sl.writeExternal(oos);
            oos.flush();
            cap++;
        }
        dirCapacity = cap - 1;
    } catch (IOException e) {
        throw new AbortException("Error determining page sizes.", e);
    }
    if (dirCapacity <= 2) {
        throw new IllegalArgumentException("Node size of " + getPageSize() + " bytes is chosen too small!");
    }
    final Logging log = getLogger();
    if (dirCapacity < 10) {
        log.warning("Page size is choosen very small! Maximum number of entries in a directory node = " + dirCapacity);
    }
    // minimum entries per directory node
    dirMinimum = (int) Math.floor(dirCapacity * settings.relativeMinFill);
    if (dirMinimum < 1) {
        dirMinimum = 1;
    }
    if (leafCapacity <= 2) {
        throw new IllegalArgumentException("Node size of " + getPageSize() + " bytes is chosen too small!");
    }
    if (leafCapacity < 10) {
        log.warning("Page size is choosen very small! Maximum number of entries in a leaf node = " + leafCapacity);
    }
    // minimum entries per leaf node
    leafMinimum = (int) Math.floor(leafCapacity * settings.relativeMinFill);
    if (leafMinimum < 1) {
        leafMinimum = 1;
    }
}
Also used : Logging(de.lmu.ifi.dbs.elki.logging.Logging) SpatialPointLeafEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialPointLeafEntry) SpatialDirectoryEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialDirectoryEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ModifiableHyperBoundingBox(de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox) ObjectOutputStream(java.io.ObjectOutputStream) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)

Example 9 with SpatialDirectoryEntry

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

the class AbstractRStarTreeNode method adjustEntry.

/**
 * Adjusts the parameters of the entry representing this node.
 *
 * @param entry the entry representing this node
 */
public boolean adjustEntry(E entry) {
    final SpatialDirectoryEntry se = (SpatialDirectoryEntry) entry;
    final ModifiableHyperBoundingBox mbr = computeMBR();
    boolean changed = false;
    if (se.hasMBR()) {
        final int dim = se.getDimensionality();
        // Test for changes
        for (int i = 0; i < dim; i++) {
            if (Math.abs(se.getMin(i) - mbr.getMin(i)) > Float.MIN_NORMAL) {
                changed = true;
                break;
            }
            if (Math.abs(se.getMax(i) - mbr.getMax(i)) > Float.MIN_NORMAL) {
                changed = true;
                break;
            }
        }
    } else {
        // No preexisting MBR.
        changed = true;
    }
    if (changed) {
        se.setMBR(mbr);
    }
    return changed;
}
Also used : SpatialDirectoryEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialDirectoryEntry) ModifiableHyperBoundingBox(de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox)

Example 10 with SpatialDirectoryEntry

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

the class AbstractRStarTreeNode method readExternal.

/**
 * Reads the id of this node, the numEntries and the entries array from the
 * specified stream.
 *
 * @param in the stream to read data from in order to restore the object
 * @throws java.io.IOException if I/O errors occur
 * @throws ClassNotFoundException If the class for an object being restored
 *         cannot be found.
 */
@Override
@SuppressWarnings("unchecked")
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    super.readExternal(in);
    // TODO: do we need to write/read the capacity?
    final int capacity = in.readInt();
    if (isLeaf()) {
        entries = (E[]) new SpatialPointLeafEntry[capacity];
        for (int i = 0; i < numEntries; i++) {
            SpatialPointLeafEntry s = new SpatialPointLeafEntry();
            s.readExternal(in);
            entries[i] = (E) s;
        }
    } else {
        entries = (E[]) new SpatialDirectoryEntry[capacity];
        for (int i = 0; i < numEntries; i++) {
            SpatialDirectoryEntry s = new SpatialDirectoryEntry();
            s.readExternal(in);
            entries[i] = (E) s;
        }
    }
}
Also used : SpatialPointLeafEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialPointLeafEntry) SpatialDirectoryEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialDirectoryEntry)

Aggregations

SpatialDirectoryEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialDirectoryEntry)11 SpatialPointLeafEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialPointLeafEntry)7 ModifiableHyperBoundingBox (de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox)3 DBID (de.lmu.ifi.dbs.elki.database.ids.DBID)2 SpatialEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)2 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)2 Database (de.lmu.ifi.dbs.elki.database.Database)1 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)1 KNNList (de.lmu.ifi.dbs.elki.database.ids.KNNList)1 SpatialPrimitiveDistanceFunction (de.lmu.ifi.dbs.elki.distance.distancefunction.SpatialPrimitiveDistanceFunction)1 LeafEntry (de.lmu.ifi.dbs.elki.index.tree.LeafEntry)1 SpatialIndexTree (de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialIndexTree)1 DeLiCluEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.deliclu.DeLiCluEntry)1 DeLiCluTreeIndex (de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.deliclu.DeLiCluTreeIndex)1 Logging (de.lmu.ifi.dbs.elki.logging.Logging)1 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)1 MeanVariance (de.lmu.ifi.dbs.elki.math.MeanVariance)1 MissingPrerequisitesException (de.lmu.ifi.dbs.elki.utilities.exceptions.MissingPrerequisitesException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1