Nearest neighbors searching

Back to Geometric algorithms

Let be a finite point-set, and a metric. Let and be the (total) relation

.

If then is said to be nearer to q than . If is ordered with , then the k:th nearest neighbor of in is the k:th smallest element of , denoted . The exact nearest neighbor problem asks for the points nearest to , i.e., . The approximate nearest neighbor problem asks for points such that

,

i.e., the found points have no more than amount of relative error when comparing the distances of the found neighbors to the distances of the exact neighbors.

Practice

Pastel implements nearest-neighbor searching and counting in both approximate and exact forms. There are several algorithms that might be appropriate in different situations. The brute-force algorithm is a naive try-all algorithm, which scales in performance as . A more elegant algorithm is made possible by a branch-and-bound algorithm using a kd-tree. The advantage of the brute-force algorithm is that it has minimal dependence to dimension. Due to curse of dimensionality, in dimensions high enough (e.g. dimension > 32), it is the case that the kd-tree has to inspect almost all of the points, giving the same asymptotic performance as the brute-force search. In these cases, it can make sense to use the brute-force algorithm instead for better practical performance. However, in all other cases you should use the kd-tree.

Learn more

Files

An aggregate file nearest neighbors searching.