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());
}
}
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());
}
}
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);
}
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));
}
}
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);
}
}
}
Aggregations