use of de.lmu.ifi.dbs.elki.utilities.datastructures.heap.TiedTopBoundedHeap in project elki by elki-project.
the class SOD method getNearestNeighbors.
/**
* Get the k nearest neighbors in terms of the shared nearest neighbor
* distance.
*
* The query object is excluded from the knn list.
*
* FIXME: move this to the database layer.
*
* @param relation the database holding the objects
* @param simQ similarity function
* @param queryObject the query object for which the kNNs should be determined
* @return the k nearest neighbors in terms of the shared nearest neighbor
* distance without the query object
*/
private DBIDs getNearestNeighbors(Relation<V> relation, SimilarityQuery<V> simQ, DBIDRef queryObject) {
Heap<DoubleDBIDPair> nearestNeighbors = new TiedTopBoundedHeap<>(knn);
for (DBIDIter iter = relation.iterDBIDs(); iter.valid(); iter.advance()) {
if (DBIDUtil.equal(iter, queryObject)) {
continue;
}
double sim = simQ.similarity(queryObject, iter);
if (sim > 0.) {
nearestNeighbors.add(DBIDUtil.newPair(sim, iter));
}
}
// Collect DBIDs
ArrayModifiableDBIDs dbids = DBIDUtil.newArray(nearestNeighbors.size());
while (nearestNeighbors.size() > 0) {
dbids.add(nearestNeighbors.poll());
}
return dbids;
}
Aggregations