Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Create exhaustive nearest neighbor searcher

`ExhaustiveSearcher`

model objects store the training data,
distance metric, and parameter values of the distance metric for an exhaustive nearest
neighbor search. The exhaustive search algorithm finds the distance from each query
observation to all *n* observations in the training data, which is an
*n*-by-*K* numeric matrix.

Once you create an `ExhaustiveSearcher`

model object, find
neighboring points in the training data to the query data by performing a nearest
neighbor search using `knnsearch`

or a radius search using
`rangesearch`

. The exhaustive search
algorithm is more efficient than the *K*d-tree algorithm when
*K* is large (that is, *K* > 10), and it is more
flexible than the *K*d-tree algorithm with respect to distance metric
choices. The `ExhaustiveSearcher`

model object also supports sparse
data.

Use either the `createns`

function or the
`ExhaustiveSearcher`

function (described here) to create an
`ExhaustiveSearcher`

object. Both functions use the same syntax
except that the `createns`

function has the `'NSMethod'`

name-value pair
argument, which you use to choose the nearest neighbor search method. The
`createns`

function also creates a `KDTreeSearcher`

object. Specify `'NSMethod','exhaustive'`

to create an `ExhaustiveSearcher`

object. The default is
`'exhaustive'`

if *K* > 10, the training data is
sparse, or the distance metric is not the Euclidean, city block, Chebychev, or
Minkowski.

`Mdl = ExhaustiveSearcher(X)`

`Mdl = ExhaustiveSearcher(X,Name,Value)`

creates an exhaustive nearest neighbor searcher object (`Mdl`

= ExhaustiveSearcher(`X`

)`Mdl`

)
using the *n*-by-*K* numeric matrix of
training data (`X`

).

specifies additional options using one or more name-value pair arguments. You
can specify the distance metric and set the distance metric parameter (`Mdl`

= ExhaustiveSearcher(`X`

,`Name,Value`

)`DistParameter`

)
property. For example,
`ExhaustiveSearcher(X,'Distance','chebychev')`

creates an
exhaustive nearest neighbor searcher object that uses the Chebychev distance. To
specify `DistParameter`

, use the `Cov`

,
`P`

, or `Scale`

name-value pair
argument.

`knnsearch` | Find k-nearest neighbors using searcher object |

`rangesearch` | Find all neighbors within specified distance using searcher object |