Search in sources :

Example 1 with HyperBoundingBox

use of de.lmu.ifi.dbs.elki.data.HyperBoundingBox in project elki by elki-project.

the class AbstractUncertainObject method computeBounds.

/**
 * Compute the bounding box for some samples.
 *
 * @param samples Samples
 * @return Bounding box.
 */
protected static HyperBoundingBox computeBounds(NumberVector[] samples) {
    assert (samples.length > 0) : "Cannot compute bounding box of empty set.";
    // Compute bounds:
    final int dimensions = samples[0].getDimensionality();
    final double[] min = new double[dimensions];
    final double[] max = new double[dimensions];
    NumberVector first = samples[0];
    for (int d = 0; d < dimensions; d++) {
        min[d] = max[d] = first.doubleValue(d);
    }
    for (int i = 1; i < samples.length; i++) {
        NumberVector v = samples[i];
        for (int d = 0; d < dimensions; d++) {
            final double c = v.doubleValue(d);
            min[d] = c < min[d] ? c : min[d];
            max[d] = c > max[d] ? c : max[d];
        }
    }
    return new HyperBoundingBox(min, max);
}
Also used : NumberVector(de.lmu.ifi.dbs.elki.data.NumberVector) HyperBoundingBox(de.lmu.ifi.dbs.elki.data.HyperBoundingBox)

Example 2 with HyperBoundingBox

use of de.lmu.ifi.dbs.elki.data.HyperBoundingBox in project elki by elki-project.

the class AbstractXTree method createNewRoot.

/**
 * Creates a new root node that points to the two specified child nodes and
 * return the path to the new root.
 *
 * @param oldRoot the old root of this RTree
 * @param newNode the new split node
 * @param splitAxis the split axis used for the split causing this new root
 * @return the path to the new root node that points to the two specified
 *         child nodes
 */
protected IndexTreePath<SpatialEntry> createNewRoot(final N oldRoot, final N newNode, int splitAxis) {
    N root = createNewDirectoryNode();
    writeNode(root);
    // get split history
    SplitHistory sh = null;
    // TODO: see whether root entry is ALWAYS a directory entry .. it SHOULD!
    sh = ((XTreeDirectoryEntry) getRootEntry()).getSplitHistory();
    if (sh == null) {
        sh = new SplitHistory(getDimensionality());
    }
    sh.setDim(splitAxis);
    // switch the ids
    oldRoot.setPageID(root.getPageID());
    if (!oldRoot.isLeaf()) {
        // TODO: test whether this is neccessary
        for (int i = 0; i < oldRoot.getNumEntries(); i++) {
            N node = getNode(oldRoot.getEntry(i));
            writeNode(node);
        }
    }
    // adjust supernode id
    if (oldRoot.isSuperNode()) {
        supernodes.remove(new Long(getRootID()));
        supernodes.put(new Long(oldRoot.getPageID()), oldRoot);
    }
    root.setPageID(getRootID());
    SpatialEntry oldRootEntry = createNewDirectoryEntry(oldRoot);
    SpatialEntry newNodeEntry = createNewDirectoryEntry(newNode);
    ((SplitHistorySpatialEntry) oldRootEntry).setSplitHistory(sh);
    try {
        ((SplitHistorySpatialEntry) newNodeEntry).setSplitHistory((SplitHistory) sh.clone());
    } catch (CloneNotSupportedException e) {
        throw new RuntimeException("Clone of a split history should not throw an Exception", e);
    }
    root.addDirectoryEntry(oldRootEntry);
    root.addDirectoryEntry(newNodeEntry);
    writeNode(root);
    writeNode(oldRoot);
    writeNode(newNode);
    if (getLogger().isDebugging()) {
        getLogger().debugFine(// 
        new StringBuilder(1000).append("Create new Root: ID=").append(root.getPageID()).append("\nchild1 ").append(oldRoot).append(' ').append(// 
        new HyperBoundingBox(oldRootEntry)).append("\nchild2 ").append(newNode).append(' ').append(new HyperBoundingBox(newNodeEntry)));
    }
    // the root entry still needs to be set to the new root node's MBR
    return new IndexTreePath<>(null, getRootEntry(), 0);
}
Also used : IndexTreePath(de.lmu.ifi.dbs.elki.index.tree.IndexTreePath) ModifiableHyperBoundingBox(de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox) HyperBoundingBox(de.lmu.ifi.dbs.elki.data.HyperBoundingBox) SplitHistory(de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.xtree.util.SplitHistory) SpatialEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)

Example 3 with HyperBoundingBox

use of de.lmu.ifi.dbs.elki.data.HyperBoundingBox in project elki by elki-project.

the class AbstractXTreeNode method integrityCheckParameters.

/**
 * Tests, if the parameters of the entry representing this node, are correctly
 * set. Subclasses may need to overwrite this method.
 *
 * @param parent the parent holding the entry representing this node
 * @param index the index of the entry in the parents child array
 */
@Override
protected void integrityCheckParameters(N parent, int index) {
    // test if mbr is correctly set
    SpatialEntry entry = parent.getEntry(index);
    HyperBoundingBox mbr = computeMBR();
    if (/*entry.getMBR() == null && */
    mbr == null) {
        return;
    }
    if (!SpatialUtil.equals(entry, mbr)) {
        String soll = mbr.toString();
        String ist = (new HyperBoundingBox(entry)).toString();
        throw new RuntimeException("Wrong MBR in node " + parent.getPageID() + " at index " + index + " (child " + entry + ")" + "\nsoll: " + soll + ",\n ist: " + ist);
    }
    if (isSuperNode() && isLeaf()) {
        throw new RuntimeException("Node " + toString() + " is a supernode and a leaf");
    }
    if (isSuperNode() && !parent.isSuperNode() && parent.getCapacity() >= getCapacity()) {
        throw new RuntimeException("Supernode " + toString() + " has capacity " + getCapacity() + "; its non-super parent node has capacity " + parent.getCapacity());
    }
}
Also used : HyperBoundingBox(de.lmu.ifi.dbs.elki.data.HyperBoundingBox) SpatialEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)

Example 4 with HyperBoundingBox

use of de.lmu.ifi.dbs.elki.data.HyperBoundingBox in project elki by elki-project.

the class SimpleGaussianUncertainifier method newFeatureVector.

@Override
public <A> SimpleGaussianContinuousUncertainObject newFeatureVector(Random rand, A array, NumberArrayAdapter<?, A> adapter) {
    final int dim = adapter.size(array);
    double[] min = new double[dim], max = new double[dim];
    if (symmetric) {
        for (int i = 0; i < dim; ++i) {
            double v = adapter.getDouble(array, i);
            double width = rand.nextDouble() * (maxDev - minDev) + minDev;
            min[i] = v - width;
            max[i] = v + width;
        }
    } else {
        for (int i = 0; i < dim; ++i) {
            // Choose standard deviation
            final double s = rand.nextDouble() * (maxDev - minDev) + minDev;
            // Assume our center is off by a standard deviation of s.
            double v = adapter.getDouble(array, i) + rand.nextGaussian() * s;
            min[i] = v - s;
            max[i] = v + s;
        }
    }
    return new SimpleGaussianContinuousUncertainObject(new HyperBoundingBox(min, max));
}
Also used : HyperBoundingBox(de.lmu.ifi.dbs.elki.data.HyperBoundingBox) SimpleGaussianContinuousUncertainObject(de.lmu.ifi.dbs.elki.data.uncertain.SimpleGaussianContinuousUncertainObject)

Example 5 with HyperBoundingBox

use of de.lmu.ifi.dbs.elki.data.HyperBoundingBox in project elki by elki-project.

the class UniformUncertainifier method newFeatureVector.

@Override
public <A> UniformContinuousUncertainObject newFeatureVector(Random rand, A array, NumberArrayAdapter<?, A> adapter) {
    final int dim = adapter.size(array);
    double[] min = new double[dim], max = new double[dim];
    if (symmetric) {
        for (int i = 0; i < dim; ++i) {
            double v = adapter.getDouble(array, i);
            double width = rand.nextDouble() * (maxDev - minDev) + minDev;
            min[i] = v - width;
            max[i] = v + width;
        }
    } else {
        for (int i = 0; i < dim; ++i) {
            double v = adapter.getDouble(array, i);
            min[i] = v - (rand.nextDouble() * (maxDev - minDev) + minDev);
            max[i] = v + (rand.nextDouble() * (maxDev - minDev) + minDev);
        }
    }
    return new UniformContinuousUncertainObject(new HyperBoundingBox(min, max));
}
Also used : UniformContinuousUncertainObject(de.lmu.ifi.dbs.elki.data.uncertain.UniformContinuousUncertainObject) HyperBoundingBox(de.lmu.ifi.dbs.elki.data.HyperBoundingBox)

Aggregations

HyperBoundingBox (de.lmu.ifi.dbs.elki.data.HyperBoundingBox)14 ModifiableHyperBoundingBox (de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox)6 SpatialEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)4 SpatialComparable (de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable)3 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)2 SplitHistory (de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.xtree.util.SplitHistory)2 TopBoundedHeap (de.lmu.ifi.dbs.elki.utilities.datastructures.heap.TopBoundedHeap)2 DoubleIntPair (de.lmu.ifi.dbs.elki.utilities.pairs.DoubleIntPair)2 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)1 SimpleGaussianContinuousUncertainObject (de.lmu.ifi.dbs.elki.data.uncertain.SimpleGaussianContinuousUncertainObject)1 UniformContinuousUncertainObject (de.lmu.ifi.dbs.elki.data.uncertain.UniformContinuousUncertainObject)1 DBID (de.lmu.ifi.dbs.elki.database.ids.DBID)1 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)1 IndexTreePath (de.lmu.ifi.dbs.elki.index.tree.IndexTreePath)1 LeafEntry (de.lmu.ifi.dbs.elki.index.tree.LeafEntry)1 Heap (de.lmu.ifi.dbs.elki.utilities.datastructures.heap.Heap)1 ArrayList (java.util.ArrayList)1