NEAREST_NEIGHBOR
Nearest Neighbor from a Set of Points


NEAREST_NEIGHBOR is a MATLAB function which works in a given M-dimensional space, seeking, for each point in a set S, the nearest point in a set R, by Richard Brown.

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),

    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 higher-dimensional generalization). Computing the triangulation is somewhat expensive, but makes the search procedure extremely quick.

    Richard Brown's function tries to use MATLAB's Delaunay search algorithm when it seems preferable, and otherwise computes the nearest neighbor by the straightforward approach.

    Licensing:

    Copyright (c) 2009, Richard Brown
    All rights reserved.
    
    Redistribution and use in source and binary forms, with or without 
    modification, are permitted provided that the following conditions are 
    met:
    
        * Redistributions of source code must retain the above copyright 
          notice, this list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above copyright 
          notice, this list of conditions and the following disclaimer in 
          the documentation and/or other materials provided with the distribution
          
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
    POSSIBILITY OF SUCH DAMAGE.
        

    Languages:

    NEAREST_NEIGHBOR is available in 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.

    TEST_NEAREST, a MATLAB program which tests the time complexity of various procedures for solving the nearest neighbor problem.

    References:

    1. 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 891-923.
    2. 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 563-580.
    3. Marc deBerg, Marc Krevald, Mark Overmars, Otfried Schwarzkopf,
      Computational Geometry,
      Springer, 2000,
      ISBN: 3-540-65620-0,
      LC: QA448.D38.C65.

    Source Code:

    Examples and Tests:

    You can go up one level to the MATLAB source codes.


    Last revised on 23 December 2012.