public class DoubleDistanceDBIDPairKNNHeap extends AbstractKNNHeap<DoubleDistanceDBIDPair,DoubleDistance> implements DoubleDistanceKNNHeap
DBIDUtil.newHeap(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; DoubleDistanceDBIDPairKNNHeap heap = new DoubleDistanceDBIDPairKNNHeap(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 |
DoubleDistanceDBIDPairKNNHeap.Comp
Comparator to use.
|
protected static class |
DoubleDistanceDBIDPairKNNHeap.RComp
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). |
static Comparator<DoubleDistanceDBIDPair> |
REVERSE_COMPARATOR
Reverse comparator.
|
heap
Constructor and Description |
---|
DoubleDistanceDBIDPairKNNHeap(int k)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
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() |
double |
insert(double distance,
DBIDRef id)
Add a distance-id pair to the heap unless the distance is too large.
|
void |
insert(Double distance,
DBIDRef id)
Deprecated.
|
void |
insert(DoubleDistanceDBIDPair e)
Add a pair to the heap.
|
void |
insert(DoubleDistance dist,
DBIDRef id)
Deprecated.
if you know your distances are double-valued, you should be
using the primitive type.
|
DoubleDistanceDBIDPairKNNList |
toKNNList()
Serialize to a
DoubleDistanceDBIDPairKNNList . |
clear, getK, isEmpty, peek, poll, size
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
peek, poll
public static final Comparator<DoubleDistanceDBIDPair> COMPARATOR
public static final Comparator<DoubleDistanceDBIDPair> REVERSE_COMPARATOR
protected double knndistance
AbstractKNNHeap.peek()
too often).public DoubleDistanceDBIDPairKNNHeap(int k)
DBIDUtil.newHeap(D, int)
!k
- Heap sizepublic DoubleDistanceDBIDPairKNNList toKNNList()
DoubleDistanceDBIDPairKNNList
. This empties the
heap!toKNNList
in interface DoubleDistanceKNNHeap
toKNNList
in interface KNNHeap<DoubleDistance>
public final double insert(double distance, DBIDRef id)
insert
in interface DoubleDistanceKNNHeap
distance
- Distance valueid
- ID number@Deprecated public final void insert(Double distance, DBIDRef id)
insert
in interface DoubleDistanceKNNHeap
distance
- Distance valueid
- ID numberprotected void heapModified()
public void insert(DoubleDistanceDBIDPair e)
AbstractKNNHeap
insert
in interface DoubleDistanceKNNHeap
insert
in class AbstractKNNHeap<DoubleDistanceDBIDPair,DoubleDistance>
e
- Pair to add.@Deprecated public void insert(DoubleDistance dist, DBIDRef id)
insert
in interface DoubleDistanceKNNHeap
insert
in interface KNNHeap<DoubleDistance>
dist
- Distance valueid
- ID numberpublic double doubleKNNDistance()
doubleKNNDistance
in interface DoubleDistanceKNNHeap
@Deprecated public DoubleDistance getKNNDistance()
getKNNDistance
in interface DoubleDistanceKNNHeap
getKNNDistance
in interface KNNHeap<DoubleDistance>