Class CoverTree<T>
- java.lang.Object
-
- org.tinspin.index.covertree.CoverTree<T>
-
public class CoverTree<T> extends Object implements PointMap<T>
A 'faster' CoverTree implementation based on the paper:"Faster Cover Trees", Mike Izbicki, Christian R. Shelton, Proceedings of the 32nd International Conference on Machine Learning, Lille, France, 2015.
Changes over original algorithms: - findNearestNeighbour compares if (d(y, x) greater (d(_x_, q.point()) - q.maxdist(this))) instead of if (d(y, x) greater (d(_y_, q.point()) - q.maxdist(this))) - maxDist: - lazily calculated. - calculated while excluding subbranches that don't need to be calculated - Invalidated on modifications (should speed up remove/insert) - Algorithm 2 (insert) uses BASE=1.3: BASE*covdist(p) instead of 2*covdist(p)) - Rebalancing: - The paper proposes to sort the children on their distance to 'x' and then insert into the first one that has enough covdist. The sorting appears unnecessary because we anyway have to check all children, and finding the closest one is trivially possible without sorting. - Some optimizations for kNN which are not discussed in the paper
Other: - We also implemented the kNN algorithm by Hjaltason and Samet, but it about 2x as long as our own algorithm in all scenarios we tested. TODO - Rebalancing (nearest-ancestor) - Merge Node/Point classes
- Author:
- Tilmann Zäschke
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCoverTree.CTStats-
Nested classes/interfaces inherited from interface org.tinspin.index.Index
Index.BEComparator, Index.BoxEntry<T>, Index.BoxEntryKnn<T>, Index.BoxFilterKnn<T>, Index.BoxIterator<T>, Index.BoxIteratorKnn<T>, Index.PEComparator, Index.PointEntry<T>, Index.PointEntryKnn<T>, Index.PointFilterKnn<T>, Index.PointIterator<T>, Index.PointIteratorKnn<T>, Index.QueryIterator<T>, Index.QueryIteratorKnn<T>
-
Nested classes/interfaces inherited from interface org.tinspin.index.PointMap
PointMap.Factory
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheck()voidclear()Clear all entries.booleancontains(double[] key)Lookup an entry, using exact match.static <T> Index.PointEntry<T>create(double[] point, T value)static <T> CoverTree<T>create(int nDims)static <T> CoverTree<T>create(int nDims, double base, PointDistance dist)static <T> CoverTree<T>create(Index.PointEntry<T>[] data, double base, PointDistance distFn)intgetDepth()intgetDims()intgetNodeCount()CoverTree.CTStatsgetStats()voidinsert(double[] key, T value)Insert a point.Index.PointIterator<T>iterator()Index.PointIterator<T>query(double[] min, double[] max)Index.PointEntryKnn<T>query1nn(double[] center)Finds the nearest neighbor.TqueryExact(double[] point)Lookup an entry, using exact match.Index.PointIteratorKnn<T>queryKnn(double[] center, int k)Finds the nearest neighbor.Tremove(double[] point)Remove a point entry.intsize()StringtoString()StringtoStringTree()Tupdate(double[] oldPoint, double[] newPoint)Update the position of an entry.
-
-
-
Method Detail
-
create
public static <T> Index.PointEntry<T> create(double[] point, T value)
-
create
public static <T> CoverTree<T> create(int nDims)
-
create
public static <T> CoverTree<T> create(int nDims, double base, PointDistance dist)
-
create
public static <T> CoverTree<T> create(Index.PointEntry<T>[] data, double base, PointDistance distFn)
-
getDims
public int getDims()
-
clear
public void clear()
Description copied from interface:IndexClear all entries.
-
getStats
public CoverTree.CTStats getStats()
-
getNodeCount
public int getNodeCount()
- Specified by:
getNodeCountin interfaceIndex
-
toStringTree
public String toStringTree()
- Specified by:
toStringTreein interfaceIndex- Returns:
- a full string output of the tree structure with all entries
-
insert
public void insert(double[] key, T value)Description copied from interface:PointMapInsert a point.
-
remove
public T remove(double[] point)
Description copied from interface:PointMapRemove a point entry.
-
update
public T update(double[] oldPoint, double[] newPoint)
Description copied from interface:PointMapUpdate the position of an entry.
-
queryExact
public T queryExact(double[] point)
Description copied from interface:PointMapLookup an entry, using exact match.- Specified by:
queryExactin interfacePointMap<T>- Parameters:
point- the point- Returns:
- the value of the entry or null if the entry was not found
-
iterator
public Index.PointIterator<T> iterator()
-
query
public Index.PointIterator<T> query(double[] min, double[] max)
-
query1nn
public Index.PointEntryKnn<T> query1nn(double[] center)
Description copied from interface:PointMapFinds the nearest neighbor. This uses Euclidean distance. Other distance types can only be specified directly on the index implementations.
-
queryKnn
public Index.PointIteratorKnn<T> queryKnn(double[] center, int k)
Description copied from interface:PointMapFinds the nearest neighbor. This uses Euclidean distance. Other distance types can only be specified directly on the index implementations.
-
contains
public boolean contains(double[] key)
Description copied from interface:PointMapLookup an entry, using exact match.
-
check
public void check()
-
-