E
- the type of data objects in the tree.public class CoverTree<E> extends java.lang.Object implements NearestNeighborSearch<E,E>, KNNSearch<E,E>, RNNSearch<E,E>
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 variables
String a = "ABC";
String b = "ABC";
String c = "AB" + "C";
are actually equal in reference test a == 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.
Constructor and Description |
---|
CoverTree(E[] dataset,
smile.math.distance.Metric<E> distance)
Constructor.
|
CoverTree(E[] dataset,
smile.math.distance.Metric<E> distance,
double base)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
isIdenticalExcluded()
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.
|
void |
range(E q,
double radius,
java.util.List<Neighbor<E,E>> neighbors)
Search the neighbors in the given radius of query object, i.e.
|
CoverTree |
setIdenticalExcluded(boolean excluded)
Set if exclude query object self from the neighborhood.
|
java.lang.String |
toString() |
public CoverTree(E[] dataset, smile.math.distance.Metric<E> distance)
dataset
- the data set for nearest neighbor search.distance
- a metric distance measure for nearest neighbor search.public java.lang.String toString()
toString
in class java.lang.Object
public CoverTree setIdenticalExcluded(boolean excluded)
public boolean isIdenticalExcluded()
public Neighbor<E,E> nearest(E q)
NearestNeighborSearch
nearest
in interface NearestNeighborSearch<E,E>
q
- the query key.public Neighbor<E,E>[] knn(E q, int k)
KNNSearch