smile.neighbor
Class CoverTree<E>
- java.lang.Object
-
- smile.neighbor.CoverTree<E>
-
- Type Parameters:
E- the type of data objects in the tree.
- All Implemented Interfaces:
- KNNSearch<E,E>, NearestNeighborSearch<E,E>, RNNSearch<E,E>
public class CoverTree<E> extends java.lang.Object implements NearestNeighborSearch<E,E>, KNNSearch<E,E>, RNNSearch<E,E>
Cover tree is a data structure for generic nearest neighbor search, which is especially efficient in spaces with small intrinsic dimension. The cover tree has a theoretical bound that is based on the dataset's doubling constant. The bound on search time is O(c12 log node) where c is the expansion constant of the dataset.By default, the query object (reference equality) is excluded from the neighborhood. You may change this behavior with
setIdenticalExcluded. Note that you may observe weird behavior with String objects. JVM will pool the string literal objects. So the below variablesString a = "ABC"; String b = "ABC"; String c = "AB" + "C";are actually equal in reference testa == b == c. With toy data that you type explicitly in the code, this will cause problems. Fortunately, the data would be read from secondary storage in production.References
- Alina Beygelzimer, Sham Kakade, and John Langford. Cover Trees for Nearest Neighbor. ICML 2006.
-
-
Constructor Summary
Constructors Constructor and Description CoverTree(E[] dataset, Metric<E> distance)Constructor.CoverTree(E[] dataset, Metric<E> distance, double base)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanisIdenticalExcluded()Get whether if query object self be excluded from the neighborhood.Neighbor<E,E>[]knn(E q, int k)Search the k nearest neighbors to the query.Neighbor<E,E>nearest(E q)Search the nearest neighbor to the given sample.voidrange(E q, double radius, java.util.List<Neighbor<E,E>> neighbors)Search the neighbors in the given radius of query object, i.e.CoverTree<E>setIdenticalExcluded(boolean excluded)Set if exclude query object self from the neighborhood.java.lang.StringtoString()
-
-
-
Constructor Detail
-
CoverTree
public CoverTree(E[] dataset, Metric<E> distance)
Constructor.- Parameters:
dataset- the data set for nearest neighbor search.distance- a metric distance measure for nearest neighbor search.
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
setIdenticalExcluded
public CoverTree<E> setIdenticalExcluded(boolean excluded)
Set if exclude query object self from the neighborhood.
-
isIdenticalExcluded
public boolean isIdenticalExcluded()
Get whether if query object self be excluded from the neighborhood.
-
nearest
public Neighbor<E,E> nearest(E q)
Description copied from interface:NearestNeighborSearchSearch the nearest neighbor to the given sample.- Specified by:
nearestin interfaceNearestNeighborSearch<E,E>- Parameters:
q- the query key.- Returns:
- the nearest neighbor
-
knn
public Neighbor<E,E>[] knn(E q, int k)
Description copied from interface:KNNSearchSearch the k nearest neighbors to the query.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG