public class DoubleDistanceKNNHeap extends AbstractKNNHeap<DoubleDistanceDBIDPair,DoubleDistance>
KNNUtil.newHeap(de.lmu.ifi.dbs.elki.distance.distancefunction.DistanceFunction<?, D>, int)
!
Experiments have shown that it can be much more performant to track the
knndistance outside of the heap, and do comparisons on the stack:
The reason probably is thatdouble knndist = Double.POSITIVE_INFINITY; DoubleDistanceKNNHeap heap = new DoubleDistanceKNNHeap(k); for (DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) { double dist = computeDistance(iditer, ...); if (dist < knndist) { heap.add(dist, iditer); if (heap.size() >= k) { max = heap.doubleKNNDistance(); } } }
knndist
resides on the stack and can be
better optimized by the hotspot compiler.Modifier and Type | Class and Description |
---|---|
protected static class |
DoubleDistanceKNNHeap.Comp
Comparator to use.
|
Modifier and Type | Field and Description |
---|---|
static Comparator<DoubleDistanceDBIDPair> |
COMPARATOR
Comparator class.
|
protected double |
knndistance
Cached distance to k nearest neighbor (to avoid going through
AbstractKNNHeap.peek()
too often). |
heap
Constructor and Description |
---|
DoubleDistanceKNNHeap(int k)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(double distance,
DBIDRef id)
Add a distance-id pair to the heap unless the distance is too large.
|
void |
add(Double distance,
DBIDRef id)
Add a distance-id pair to the heap unless the distance is too large.
|
void |
add(DoubleDistanceDBIDPair e)
Add a pair to the heap.
|
void |
add(DoubleDistance dist,
DBIDRef id)
Deprecated.
if you know your distances are double-valued, you should be
using the primitive type.
|
double |
doubleKNNDistance()
Get the distance to the k nearest neighbor, or maxdist otherwise.
|
DoubleDistance |
getKNNDistance()
Deprecated.
if you know your distances are double-valued, you should be
using the primitive type.
|
protected void |
heapModified() |
DoubleDistanceKNNList |
toKNNList()
Serialize to a
DoubleDistanceKNNList . |
public static final Comparator<DoubleDistanceDBIDPair> COMPARATOR
protected double knndistance
AbstractKNNHeap.peek()
too often).public DoubleDistanceKNNHeap(int k)
KNNUtil.newHeap(de.lmu.ifi.dbs.elki.distance.distancefunction.DistanceFunction<?, D>, int)
!k
- Heap sizepublic DoubleDistanceKNNList toKNNList()
DoubleDistanceKNNList
. This empties the heap!public final void add(double distance, DBIDRef id)
distance
- Distance valueid
- ID numberpublic final void add(Double distance, DBIDRef id)
distance
- Distance valueid
- ID numberprotected void heapModified()
public void add(DoubleDistanceDBIDPair e)
AbstractKNNHeap
add
in class AbstractKNNHeap<DoubleDistanceDBIDPair,DoubleDistance>
e
- Pair to add.@Deprecated public void add(DoubleDistance dist, DBIDRef id)
dist
- Distance valueid
- ID numberpublic double doubleKNNDistance()
@Deprecated public DoubleDistance getKNNDistance()