use of de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry in project elki by elki-project.
the class AbstractXTree method computeHeight.
/**
* Computes the height of this XTree. Is called by the constructor. and should
* be overwritten by subclasses if necessary.
*
* @return the height of this XTree
*/
@Override
protected int computeHeight() {
N node = getRoot();
int tHeight = 1;
// compute height
while (!node.isLeaf() && node.getNumEntries() != 0) {
SpatialEntry entry = node.getEntry(0);
node = getNode(entry);
tHeight++;
}
return tHeight;
}
use of de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry in project elki by elki-project.
the class RStarTreeKNNQuery method batchNN.
/**
* Performs a batch knn query.
*
* @param node the node for which the query should be performed
* @param knnLists a map containing the knn lists for each query objects
*/
protected void batchNN(AbstractRStarTreeNode<?, ?> node, Map<DBID, KNNHeap> knnLists) {
if (node.isLeaf()) {
for (int i = 0; i < node.getNumEntries(); i++) {
SpatialEntry p = node.getEntry(i);
for (Entry<DBID, KNNHeap> ent : knnLists.entrySet()) {
final DBID q = ent.getKey();
final KNNHeap knns_q = ent.getValue();
double knn_q_maxDist = knns_q.getKNNDistance();
DBID pid = ((LeafEntry) p).getDBID();
// FIXME: objects are NOT accessible by DBID in a plain R-tree
// context!
double dist_pq = distanceFunction.distance(relation.get(pid), relation.get(q));
tree.statistics.countDistanceCalculation();
if (dist_pq <= knn_q_maxDist) {
knns_q.insert(dist_pq, pid);
}
}
}
} else {
ModifiableDBIDs ids = DBIDUtil.newArray(knnLists.size());
for (DBID id : knnLists.keySet()) {
ids.add(id);
}
List<DoubleDistanceEntry> entries = getSortedEntries(node, ids);
for (DoubleDistanceEntry distEntry : entries) {
double minDist = distEntry.distance;
for (Entry<DBID, KNNHeap> ent : knnLists.entrySet()) {
final KNNHeap knns_q = ent.getValue();
double knn_q_maxDist = knns_q.getKNNDistance();
if (minDist <= knn_q_maxDist) {
SpatialEntry entry = distEntry.entry;
AbstractRStarTreeNode<?, ?> child = tree.getNode(((DirectoryEntry) entry).getPageID());
batchNN(child, knnLists);
break;
}
}
}
}
}
use of de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry in project elki by elki-project.
the class RStarTreeKNNQuery method getSortedEntries.
/**
* Sorts the entries of the specified node according to their minimum distance
* to the specified objects.
*
* @param node the node
* @param ids the id of the objects
* @return a list of the sorted entries
*/
protected List<DoubleDistanceEntry> getSortedEntries(AbstractRStarTreeNode<?, ?> node, DBIDs ids) {
List<DoubleDistanceEntry> result = new ArrayList<>();
for (int i = 0; i < node.getNumEntries(); i++) {
SpatialEntry entry = node.getEntry(i);
double minMinDist = Double.MAX_VALUE;
for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
double minDist = distanceFunction.minDist(entry, relation.get(iter));
tree.statistics.countDistanceCalculation();
minMinDist = Math.min(minDist, minMinDist);
}
result.add(new DoubleDistanceEntry(entry, minMinDist));
}
Collections.sort(result);
return result;
}
use of de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry in project elki by elki-project.
the class FlatRStarTree method bulkLoad.
/**
* Performs a bulk load on this RTree with the specified data. Is called by
* the constructor and should be overwritten by subclasses if necessary.
*/
@Override
protected void bulkLoad(List<SpatialEntry> spatialObjects) {
if (!initialized) {
initialize(spatialObjects.get(0));
}
// create leaf nodes
getFile().setNextPageID(getRootID() + 1);
List<SpatialEntry> nodes = createBulkLeafNodes(spatialObjects);
int numNodes = nodes.size();
if (LOG.isDebugging()) {
LOG.debugFine(" numLeafNodes = " + numNodes);
}
// create root
root = createNewDirectoryNode();
root.setPageID(getRootID());
for (SpatialEntry entry : nodes) {
root.addDirectoryEntry(entry);
}
numNodes++;
setHeight(2);
if (LOG.isDebugging()) {
StringBuilder msg = new StringBuilder();
msg.append(" root = ").append(getRoot());
msg.append("\n numNodes = ").append(numNodes);
msg.append("\n height = ").append(getHeight());
LOG.debugFine(msg.toString() + "\n");
}
doExtraIntegrityChecks();
}
use of de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry in project elki by elki-project.
the class FlatRStarTreeIndex method insertAll.
/**
* Inserts the specified objects into this index. If a bulk load mode is
* implemented, the objects are inserted in one bulk.
*
* @param ids the objects to be inserted
*/
@Override
public final void insertAll(DBIDs ids) {
if (ids.isEmpty() || (ids.size() == 1)) {
return;
}
// Make an example leaf
if (canBulkLoad()) {
List<SpatialEntry> leafs = new ArrayList<>(ids.size());
for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
leafs.add(createNewLeafEntry(DBIDUtil.deref(iter)));
}
bulkLoad(leafs);
} else {
for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
insert(iter);
}
}
doExtraIntegrityChecks();
}
Aggregations