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>, java.io.Serializable
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.
Constructor and Description |
---|
KDTree(double[][] key,
E[] data)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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.Object
public Neighbor<double[],E> nearest(double[] q)
NearestNeighborSearch
nearest
in interface NearestNeighborSearch<double[],E>
q
- the query key.public Neighbor<double[],E>[] knn(double[] q, int k)
KNNSearch