Class SmallMemoryKDTree<O extends NumberVector>
- java.lang.Object
-
- elki.index.tree.spatial.kd.SmallMemoryKDTree<O>
-
- Type Parameters:
O- Vector type
- All Implemented Interfaces:
DistancePriorityIndex<O>,Index,KNNIndex<O>,RangeIndex<O>
@Reference(authors="J. L. Bentley", title="Multidimensional binary search trees used for associative searching", booktitle="Communications of the ACM 18(9)", url="https://doi.org/10.1145/361002.361007", bibkey="DBLP:journals/cacm/Bentley75") @Priority(-101) public class SmallMemoryKDTree<O extends NumberVector> extends java.lang.Object implements DistancePriorityIndex<O>
Simple implementation of a static in-memory K-D-tree. Does not support dynamic updates or anything, but also is very simple and memory efficient: all it uses is oneModifiableDoubleDBIDListto sort the data in a serialized tree and store the current attribute value.It needs about 3 times as much memory as
MinimalisticMemoryKDTreebut it is also considerably faster because it does not need to lookup this value from the vectors.MemoryKDTreeneeds even more memory, but uses much better splits and hence is usually the best choice.Reference:
J. L. Bentley
Multidimensional binary search trees used for associative searching
Communications of the ACM 18(9)The search uses an improved search strategy published by:
S. Arya and D. M. Mount
Algorithms for fast vector quantization
Proc. DCC '93: Data Compression ConferenceTODO: add support for weighted Minkowski distances.
- Since:
- 0.7.0
- Author:
- Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSmallMemoryKDTree.Factory<O extends NumberVector>Factory classclassSmallMemoryKDTree.KDTreeKNNSearcherkNN query for the k-d-tree.classSmallMemoryKDTree.KDTreePrioritySearcherPriority search for the k-d-tree.classSmallMemoryKDTree.KDTreeRangeSearcherRange query for the k-d-tree.private static classSmallMemoryKDTree.PrioritySearchBranchSearch position for priority search.
-
Field Summary
Fields Modifier and Type Field Description protected intdimsThe number of dimensions.protected CounterdistcalcCounter for distance computations.protected intleafsizeMaximum size of leaf nodes.private static LoggingLOGClass loggerprotected CounterobjaccessCounter for comparisons.protected Relation<O>relationThe representation we are bound to.protected ModifiableDoubleDBIDListsortedThe actual "tree" as a sorted array.
-
Constructor Summary
Constructors Constructor Description SmallMemoryKDTree(Relation<O> relation, int leafsize)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidbuildTree(int left, int right, int axis, DoubleDBIDListMIter iter)Recursively build the tree by partial sorting.protected voidcountDistanceComputation()Count a distance computation.protected voidcountObjectAccess()Count a single object access.voidinitialize()Initialize the index.KNNSearcher<O>kNNByObject(DistanceQuery<O> distanceQuery, int maxk, int flags)Get a KNN query object for the given distance query and k.voidlogStatistics()Send statistics to the logger, if enabled.private intnext(int axis)Next axis.PrioritySearcher<O>priorityByObject(DistanceQuery<O> distanceQuery, double maxrange, int flags)Get a priority search object.RangeSearcher<O>rangeByObject(DistanceQuery<O> distanceQuery, double maxrange, int flags)Get a range query object for the given distance query and k.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface elki.index.DistancePriorityIndex
priorityByDBID
-
Methods inherited from interface elki.index.RangeIndex
rangeByDBID
-
-
-
-
Field Detail
-
LOG
private static final Logging LOG
Class logger
-
relation
protected final Relation<O extends NumberVector> relation
The representation we are bound to.
-
sorted
protected ModifiableDoubleDBIDList sorted
The actual "tree" as a sorted array.
-
dims
protected int dims
The number of dimensions.
-
leafsize
protected int leafsize
Maximum size of leaf nodes.
-
objaccess
protected final Counter objaccess
Counter for comparisons.
-
distcalc
protected final Counter distcalc
Counter for distance computations.
-
-
Method Detail
-
initialize
public void initialize()
Description copied from interface:IndexInitialize the index. For static indexes, this is the moment the index is bulk loaded.- Specified by:
initializein interfaceIndex
-
buildTree
private void buildTree(int left, int right, int axis, DoubleDBIDListMIter iter)Recursively build the tree by partial sorting. O(n log n) complexity. Apparently there exists a variant in only O(n log log n)? Please contribute!- Parameters:
left- Interval minimumright- Interval maximumaxis- Current splitting axisiter- Iterator
-
next
private int next(int axis)
Next axis.- Parameters:
axis- Current axis- Returns:
- Next axis
-
logStatistics
public void logStatistics()
Description copied from interface:IndexSend statistics to the logger, if enabled.Note: you must have set the logging level appropriately before initializing the index! Otherwise, the index might not have collected the desired statistics.
- Specified by:
logStatisticsin interfaceIndex
-
countObjectAccess
protected void countObjectAccess()
Count a single object access.
-
countDistanceComputation
protected void countDistanceComputation()
Count a distance computation.
-
kNNByObject
public KNNSearcher<O> kNNByObject(DistanceQuery<O> distanceQuery, int maxk, int flags)
Description copied from interface:KNNIndexGet a KNN query object for the given distance query and k.This function MAY return null, when the given distance is not supported!
- Specified by:
kNNByObjectin interfaceDistancePriorityIndex<O extends NumberVector>- Specified by:
kNNByObjectin interfaceKNNIndex<O extends NumberVector>- Parameters:
distanceQuery- Distance querymaxk- Maximum value of kflags- Hints for the optimizer- Returns:
- KNN Query object or
null
-
rangeByObject
public RangeSearcher<O> rangeByObject(DistanceQuery<O> distanceQuery, double maxrange, int flags)
Description copied from interface:RangeIndexGet a range query object for the given distance query and k.This function MAY return null, when the given distance is not supported!
- Specified by:
rangeByObjectin interfaceDistancePriorityIndex<O extends NumberVector>- Specified by:
rangeByObjectin interfaceRangeIndex<O extends NumberVector>- Parameters:
distanceQuery- Distance querymaxrange- Maximum rangeflags- Hints for the optimizer- Returns:
- KNN Query object or
null
-
priorityByObject
public PrioritySearcher<O> priorityByObject(DistanceQuery<O> distanceQuery, double maxrange, int flags)
Description copied from interface:DistancePriorityIndexGet a priority search object.- Specified by:
priorityByObjectin interfaceDistancePriorityIndex<O extends NumberVector>- Parameters:
distanceQuery- Distance querymaxrange- Maximum search range (may beDouble.POSITIVE_INFINITYflags- Optimizer hints- Returns:
- Priority searcher
-
-