TEST_NEAREST
Test Functions for the Nearest Neighbor Calculation
TEST_NEAREST,
a MATLAB program which
tests several functions that carry out the nearest neighbor calculation.
In a nearest neighbor calculation, we are given:
R, a set of NR points in M dimensions.
S, a set of NS points in M dimensions.
D(x,y), a norm for measuring distances between points in M dimensions.
and we are asked to compute, for each point S(JS),

JR = NEAREST(JS), the index of the point in R for which
the distance D(S(JS),R(JR)) is minimized.
Obviously, one method to determine the values in NEAREST is simply to
compute every distance and take the index of the minimum. But even
this simple idea can be implemented in many ways in MATLAB, and
implementations will vary in their cost in memory and time.
Also, note that if the dimension M is small, and if the size of the
R set is small relative to that of S, it may be much cheaper to
compute the Delaunay triangulation of R (or its higherdimensional
generalization). Computing the triangulation is somewhat expensive,
but makes the search procedure extremely quick.
Lloyd's version of the Centroidal Voronoi Tessellation (CVT) algorithm
estimates the area or volume of the cells using sampling. This computation
is a nearest neighbor calculation.
Licensing:
The computer code and data files described and made available on this web page
are distributed under
the GNU LGPL license.
Languages:
TEST_NEAREST is available in
a C version and
a C++ version and
a FORTRAN90 version and
a MATLAB version.
Related Programs:
CVT,
a MATLAB library which
computes elements of a Centroidal Voronoi Tessellation (CVT).
NEAREST_INTERP_1D,
a MATLAB library which
interpolates a set of data using a piecewise constant interpolant
defined by the nearest neighbor criterion.
NEAREST_NEIGHBOR,
a MATLAB library which
works in a given Mdimensional space, seeking, for each point
in a set S, the nearest point in a set R,
by Richard Brown.
test_nearest_test
References:

Sunil Arya, David Mount, Nathan Netanyahu, Ruth Silverman,
Angela Wu,
An Optimal Algorithm for Approximate Nearest Neighbor Searching
in Fixed Dimensions,
Journal of the ACM,
Volume 45, Number 6, November 1998, pages 891923.

Jon Bentley, Bruce Weide, Andrew Yao,
Optimal Expected Time Algorithms for Closest Point Problems,
ACM Transactions on Mathematical Software,
Volume 6, Number 4, December 1980, pages 563580.

Marc deBerg, Marc Krevald, Mark Overmars,
Otfried Schwarzkopf,
Computational Geometry,
Springer, 2000,
ISBN: 3540656200,
LC: QA448.D38.C65.
Source Code:

find_closest1.m,
a straightforward calculation which, for each sample point,
computes the distance to each data point, and remembers the index
of the closest one;

find_closest2.m,
a calculation which, for each sample point,
uses the MATLAB commands repmat() and min(), hoping for faster execution.

find_closest3.m,
a calculation which, for each sample point,
computes the distance vector using matrix algebra.

nearest_neighbor.m,
a function by Richard Brown for the nearest neighbor calculation.

timestamp.m,
prints the current YMDHMS date as a timestamp;
Last revised on 30 March 2019.