E - the type of data objects in the tree.public class KDTree<E> extends java.lang.Object implements NearestNeighborSearch<double[],E>, KNNSearch<double[],E>, RNNSearch<double[],E>
KD-trees are not suitable for efficiently finding the nearest neighbor in high dimensional spaces. As a general rule, if the dimensionality is D, then number of points in the dataset, N, should be N >> 2D. Otherwise, when kd-trees are used with high-dimensional dataset, most of the points in the tree will be evaluated and the efficiency is no better than exhaustive search, and approximate nearest-neighbor methods should be used instead.
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 |
|---|
KDTree(double[][] key,
E[] data)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
isIdenticalExcluded()
Get whether if query object self be excluded from the neighborhood.
|
Neighbor<double[],E>[] |
knn(double[] q,
int k)
Search the k nearest neighbors to the query.
|
Neighbor<double[],E> |
nearest(double[] q)
Search the nearest neighbor to the given sample.
|
void |
range(double[] q,
double radius,
java.util.List<Neighbor<double[],E>> neighbors)
Search the neighbors in the given radius of query object, i.e.
|
KDTree |
setIdenticalExcluded(boolean excluded)
Set if exclude query object self from the neighborhood.
|
java.lang.String |
toString() |
public KDTree(double[][] key,
E[] data)
key - the keys of data objects.data - the data objects.public java.lang.String toString()
toString in class java.lang.Objectpublic KDTree setIdenticalExcluded(boolean excluded)
public boolean isIdenticalExcluded()
public Neighbor<double[],E> nearest(double[] q)
NearestNeighborSearchnearest in interface NearestNeighborSearch<double[],E>q - the query key.public Neighbor<double[],E>[] knn(double[] q, int k)
KNNSearch