Search in sources :

Example 1 with XTreeDirectoryEntry

use of de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.xtree.XTreeDirectoryEntry in project elki by elki-project.

the class XSplitter method getCommonSplitDimensions.

/**
 * Determine the common split dimensions from a list of entries.
 *
 * @param node node for which to determine the common split
 *        dimensions
 * @return common split dimensions
 */
private IntIterator getCommonSplitDimensions(N node) {
    Collection<SplitHistory> splitHistories = new ArrayList<>(node.getNumEntries());
    for (int i = 0; i < node.getNumEntries(); i++) {
        SpatialEntry entry = node.getEntry(i);
        if (!(entry instanceof XTreeDirectoryEntry)) {
            throw new RuntimeException("Wrong entry type to derive split dimension from: " + entry.getClass().getName());
        }
        splitHistories.add(((XTreeDirectoryEntry) entry).getSplitHistory());
    }
    return SplitHistory.getCommonDimensions(splitHistories);
}
Also used : XTreeDirectoryEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.xtree.XTreeDirectoryEntry) ArrayList(java.util.ArrayList) SpatialEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)

Example 2 with XTreeDirectoryEntry

use of de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.xtree.XTreeDirectoryEntry in project elki by elki-project.

the class XSplitter method minimumOverlapSplit.

/**
 * Perform an minimum overlap split. The
 * {@link #chooseMinimumOverlapSplit(int, int, int, boolean) minimum overlap
 * split} calculates the partition for the split dimension determined by
 * {@link #chooseSplitAxis(Iterable, int, int) chooseSplitAxis}
 * <code>(common split
 * history, minFanout, maxEntries - minFanout + 1)</code> with the minimum
 * overlap. This range may have been tested before (by the
 * {@link #topologicalSplit()}), but for the minimum overlap test we need to
 * test that anew. Note that this method returns <code>null</code>, if the
 * minimum overlap split has a volume which is larger than the allowed
 * <code>maxOverlap</code> ratio or if the tree's minimum fanout is not larger
 * than the minimum directory size.
 *
 * @return distribution resulting from the minimum overlap split
 */
public SplitSorting minimumOverlapSplit() {
    if (node.getEntry(0) instanceof LeafEntry) {
        throw new IllegalArgumentException("The minimum overlap split will only be performed on directory nodes");
    }
    if (node.getNumEntries() < 2) {
        throw new IllegalArgumentException("Splitting less than two entries is pointless.");
    }
    int maxEntries = tree.getDirCapacity() - 1;
    int minFanout = tree.get_min_fanout();
    if (node.getNumEntries() < maxEntries) {
        throw new IllegalArgumentException("This entry list has not yet reached the maximum limit: " + node.getNumEntries() + "<=" + maxEntries);
    }
    assert !(node.getEntry(0) instanceof LeafEntry);
    if (minFanout >= tree.getDirMinimum()) {
        // minFanout not set for allowing underflowing nodes
        return null;
    }
    IntIterator dimensionListing;
    if (node.getEntry(0) instanceof XTreeDirectoryEntry) {
        // filter common split dimensions
        dimensionListing = getCommonSplitDimensions(node);
        if (!dimensionListing.hasNext()) {
            // no common dimensions
            return null;
        }
    } else {
        // test all dimensions
        dimensionListing = new IntegerRangeIterator(0, node.getEntry(0).getDimensionality());
    }
    int formerSplitAxis = this.splitAxis;
    // = maximum left-hand size
    maxEntries = maxEntries + 1 - minFanout;
    chooseSplitAxis(dimensionListing, minFanout, maxEntries);
    // find the best split point
    if (formerSplitAxis == this.splitAxis && tree.getDirMinimum() > minFanout) {
        // remember: this follows an unsuccessful topological split
        // avoid duplicate computations of {minEntries, ..., maxEntries}
        double minOverlap = pastOverlap;
        // test {minFanout, ..., minEntries - 1}
        SplitSorting ret1 = chooseMinimumOverlapSplit(this.splitAxis, minFanout, tree.getDirMinimum() - 1, false);
        if (ret1 != null && pastOverlap < minOverlap) {
            // this is a valid choice
            minOverlap = pastOverlap;
        }
        // test {maxEntries - minEntries + 2, ..., maxEntries - minFanout + 1}
        SplitSorting ret2 = chooseMinimumOverlapSplit(this.splitAxis, minFanout, tree.getDirMinimum() - 1, true);
        if (ret2 == null) {
            // accept first range regardless of whether or not there is one
            pastOverlap = minOverlap;
            return ret1;
        }
        if (pastOverlap < minOverlap) {
            // the second range is better
            return ret2;
        }
        // the first range is better
        pastOverlap = minOverlap;
        return ret1;
    } else {
        return chooseMinimumOverlapSplit(this.splitAxis, minFanout, maxEntries, false);
    }
}
Also used : XTreeDirectoryEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.xtree.XTreeDirectoryEntry) IntIterator(it.unimi.dsi.fastutil.ints.IntIterator) LeafEntry(de.lmu.ifi.dbs.elki.index.tree.LeafEntry)

Aggregations

XTreeDirectoryEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.xtree.XTreeDirectoryEntry)2 LeafEntry (de.lmu.ifi.dbs.elki.index.tree.LeafEntry)1 SpatialEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)1 IntIterator (it.unimi.dsi.fastutil.ints.IntIterator)1 ArrayList (java.util.ArrayList)1