Search in sources :

Example 6 with SpatialEntry

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

the class AbstractXTreeNode method readSuperNode.

/**
 * Reads the id of this supernode, the numEntries and the entries array from
 * the specified stream.
 *
 * @param in the stream to read data from in order to restore the object
 * @param tree the tree this supernode is to be assigned to
 * @throws java.io.IOException if I/O errors occur
 * @throws ClassNotFoundException If the class for an object being restored
 *         cannot be found.
 * @throws IllegalStateException if the parameters of the file's supernode do
 *         not match this
 */
public <T extends AbstractXTree<N>> void readSuperNode(ObjectInput in, T tree) throws IOException, ClassNotFoundException {
    readExternal(in);
    if (capacity_to_be_filled <= 0 || !isSuperNode()) {
        throw new IllegalStateException("This node does not appear to be a supernode");
    }
    if (isLeaf) {
        throw new IllegalStateException("A supernode is cannot be a leaf");
    }
    // TODO: verify
    entries = new Entry[capacity_to_be_filled];
    // old way:
    // entries = (E[]) new XDirectoryEntry[capacity_to_be_filled];
    capacity_to_be_filled = 0;
    for (int i = 0; i < numEntries; i++) {
        SpatialEntry s = new SpatialDirectoryEntry();
        s.readExternal(in);
        entries[i] = s;
    }
    N n = tree.getSupernodes().put((long) getPageID(), (N) this);
    if (n != null) {
        Logging.getLogger(this.getClass()).fine("Warning: this supernode should only be read once. Now a node of size " + entries.length + " has replaced a node of size " + n.entries.length + " for id " + getPageID());
    }
}
Also used : SpatialDirectoryEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialDirectoryEntry) SpatialEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)

Example 7 with SpatialEntry

use of de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry 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 8 with SpatialEntry

use of de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry 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 9 with SpatialEntry

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

the class IndexPurity method processNewResult.

@Override
public void processNewResult(ResultHierarchy hier, Result newResult) {
    Database database = ResultUtil.findDatabase(hier);
    final ArrayList<SpatialIndexTree<?, ?>> indexes = ResultUtil.filterResults(hier, newResult, SpatialIndexTree.class);
    if (indexes == null || indexes.isEmpty()) {
        return;
    }
    Relation<String> lblrel = DatabaseUtil.guessLabelRepresentation(database);
    for (SpatialIndexTree<?, ?> index : indexes) {
        List<? extends SpatialEntry> leaves = index.getLeaves();
        MeanVariance mv = new MeanVariance();
        for (SpatialEntry e : leaves) {
            SpatialDirectoryEntry leaf = (SpatialDirectoryEntry) e;
            Node<?> n = index.getNode(leaf.getPageID());
            final int total = n.getNumEntries();
            HashMap<String, Integer> map = new HashMap<>(total);
            for (int i = 0; i < total; i++) {
                DBID id = ((SpatialPointLeafEntry) n.getEntry(i)).getDBID();
                String label = lblrel.get(id);
                Integer val = map.get(label);
                if (val == null) {
                    val = 1;
                } else {
                    val += 1;
                }
                map.put(label, val);
            }
            double gini = 0.0;
            for (Entry<String, Integer> ent : map.entrySet()) {
                double rel = ent.getValue() / (double) total;
                gini += rel * rel;
            }
            mv.put(gini);
        }
        Collection<double[]> col = new ArrayList<>();
        col.add(new double[] { mv.getMean(), mv.getSampleStddev() });
        database.getHierarchy().add((Result) index, new CollectionResult<>("Gini coefficient of index", "index-gini", col));
    }
}
Also used : SpatialPointLeafEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialPointLeafEntry) HashMap(java.util.HashMap) DBID(de.lmu.ifi.dbs.elki.database.ids.DBID) ArrayList(java.util.ArrayList) SpatialIndexTree(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialIndexTree) SpatialEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry) MeanVariance(de.lmu.ifi.dbs.elki.math.MeanVariance) SpatialDirectoryEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialDirectoryEntry) Database(de.lmu.ifi.dbs.elki.database.Database)

Example 10 with SpatialEntry

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

the class DeLiClu method reinsertExpanded.

private void reinsertExpanded(SpatialPrimitiveDistanceFunction<NV> distFunction, DeLiCluTree index, List<IndexTreePath<DeLiCluEntry>> path, int pos, DeLiCluEntry parentEntry, Relation<KNNList> knns) {
    DeLiCluNode parentNode = index.getNode(parentEntry);
    SpatialEntry entry2 = path.get(pos).getEntry();
    if (entry2 instanceof LeafEntry) {
        assert (pos == 0);
        for (int i = 0; i < parentNode.getNumEntries(); i++) {
            DeLiCluEntry entry1 = parentNode.getEntry(i);
            if (entry1.hasHandled()) {
                continue;
            }
            double distance = distFunction.minDist(entry1, entry2);
            double reach = MathUtil.max(distance, knns.get(((LeafEntry) entry2).getDBID()).getKNNDistance());
            SpatialObjectPair dataPair = new SpatialObjectPair(reach, entry1, entry2, false);
            heap.add(dataPair);
        }
        return;
    }
    IntSet expanded = index.getExpanded(entry2);
    for (int i = 0; i < parentNode.getNumEntries(); i++) {
        DeLiCluDirectoryEntry entry1 = (DeLiCluDirectoryEntry) parentNode.getEntry(i);
        // not yet expanded
        if (!expanded.contains(entry1.getPageID())) {
            double distance = distFunction.minDist(entry1, entry2);
            SpatialObjectPair nodePair = new SpatialObjectPair(distance, entry1, entry2, true);
            heap.add(nodePair);
        } else // already expanded
        {
            reinsertExpanded(distFunction, index, path, pos - 1, entry1, knns);
        }
    }
}
Also used : DeLiCluEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.deliclu.DeLiCluEntry) LeafEntry(de.lmu.ifi.dbs.elki.index.tree.LeafEntry) IntSet(it.unimi.dsi.fastutil.ints.IntSet) DeLiCluDirectoryEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.deliclu.DeLiCluDirectoryEntry) DeLiCluNode(de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.deliclu.DeLiCluNode) SpatialEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)

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