# doc-cache created by Octave 11.2.0
# name: cache
# type: cell
# rows: 3
# columns: 30
# name: <cell-element>
# type: sq_string
# elements: 1
# length: 18
ExhaustiveSearcher


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 715
statistics: ExhaustiveSearcher

Exhaustive nearest neighbor searcher

The ExhaustiveSearcher class implements an exhaustive search
algorithm for nearest neighbor queries. It stores training data and
supports various distance metrics along with their parameter values for
performing an exhaustive search. The exhaustive search algorithm computes
the distance from each query point to all the points in the training data
and facilitates a nearest neighbor search using knnsearch or a
radius search using rangesearch .

You can either use the ExhaustiveSearcher class constructor or the
createns function to create an ExhaustiveSearcher object.

See also:
createns,
KDTreeSearcher,
hnswSearcher,
knnsearch,
rangesearch


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 36
Exhaustive nearest neighbor searcher



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 32
ExhaustiveSearcher.DistParameter


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 531
ExhaustiveSearcher: property DistParameter

Distance parameter

The type and value of the distance parameter depends on the selected
Distance metric and can be any of the following:

For 'minkowski' , a positive scalar exponent (default 2).
For 'seuclidean' , a nonnegative vector of scaling factors
matching the number of columns in X (default is standard
deviation of X ).
For 'mahalanobis' , a positive definite covariance matrix
matching the dimensions of X (default is cov ( X ) ).
Empty for other metrics or custom functions.


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 18
Distance parameter



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 27
ExhaustiveSearcher.Distance


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 281
ExhaustiveSearcher: property Distance

Distance metric

Distance metric used for searches, specified as a character vector (e.g.,
'euclidean' , 'minkowski' ) or a function handle to a
custom distance function. Default is 'euclidean' . Supported
metrics align with those in pdist2 .


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 15
Distance metric



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 37
ExhaustiveSearcher.ExhaustiveSearcher


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 1506
ExhaustiveSearcher: obj = ExhaustiveSearcher ( X )
ExhaustiveSearcher: obj = ExhaustiveSearcher ( X , name , value )

Create an ExhaustiveSearcher object for nearest neighbor
searches.

obj = ExhaustiveSearcher ( X ) constructs an
ExhaustiveSearcher object with training data X using the
default 'euclidean' distance metric. X must be an
N&times;P numeric matrix, where rows represent observations and columns
represent features.

obj = ExhaustiveSearcher ( X , name , value )
allows customization through name-value pairs:

Name Value
'Distance' Distance metric, specified as a
character vector (e.g., 'euclidean' , 'minkowski' ) or a
function handle. Default is 'euclidean' . See pdist2 for
supported metrics.
'P' a positive scalar specifying the exponent for
the Minkowski distance. Valid only when 'Distance' is
'minkowski' . Default is 2.
'Scale' a nonnegative vector with the same number
of elements as the columns in X specifying the scale parameter for
the standardized Euclidean distance. Valid only when
'Distance' is 'seuclidean' . Default is std (X) .
'Cov' a positive definite matrix matching the
number of columns in X specifying the covariance matrix for the
Mahalanobis distance. Valid only when 'Distance' is
'mahalanobis' . Default is cov (X) .

'Distance' , 'P' , 'Cov' and 'Scale' override
the searcher&rsquo;s own metric for that call only; the Distance and
DistParameter properties keep their values, as they do in MATLAB.

See also:
ExhaustiveSearcher,
knnsearch,
rangesearch,
pdist2


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 66
Create an ExhaustiveSearcher object for nearest neighbor searches.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 20
ExhaustiveSearcher.X


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 345
ExhaustiveSearcher: property X

Point data

Point data, specified as an N&times;P numeric matrix where each row
is an observation and each column is a feature. This property is private
and cannot be modified after object creation.

Data of class single is stored and searched in single
precision, any other numeric class is converted to double .


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 10
Point data



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 28
ExhaustiveSearcher.knnsearch


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 1363
ExhaustiveSearcher: [ idx , D ] = knnsearch ( obj , Y )
ExhaustiveSearcher: [ idx , D ] = knnsearch ( obj , Y , name , value )

Find the K nearest neighbors in the training data to query points.

[ idx , D ] = knnsearch ( obj , Y ) returns the
indices idx and distances D of the nearest neighbor in
obj.X to each point in Y , using the distance metric specified
in obj.Distance .

obj is an ExhaustiveSearcher object.
Y is an M&times;P numeric matrix of query points, where
P must match the number of columns in obj.X .

idx is always of class double . D is of class
single when either obj.X or Y is single ,
in which case the distances are computed in single precision, and of
class double otherwise.

[ idx , D ] = knnsearch ( obj , Y , name ,
value )
allows additional options via name-value pairs:

Name Value
'K' A positive integer specifying the number of
nearest neighbors to find. Default is 1. A value larger than the
number of observations in the training data is answered with all of
them, since there are no more neighbors to return.
'IncludeTies' Logical flag indicating whether to
include all neighbors tied with the K th smallest distance. Default
is false . If true , idx and D are cell arrays.

idx contains the indices of the nearest neighbors in obj.X .
D contains the corresponding distances.

See also:
ExhaustiveSearcher,
rangesearch,
pdist2


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 66
Find the K nearest neighbors in the training data to query points.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 30
ExhaustiveSearcher.rangesearch


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 1140
ExhaustiveSearcher: [ idx , D ] = rangesearch ( obj , Y , r )
ExhaustiveSearcher: [ idx , D ] = rangesearch ( obj , Y , r , name , value )

Find all neighbors within a specified radius of query points.

[ idx , D ] = rangesearch ( obj , Y , r )
returns the indices idx and distances D of all points in
obj.X within radius r of each point in Y , using the
distance metric specified in obj.Distance .

obj is an ExhaustiveSearcher object.
Y is an M&times;P numeric matrix of query points, where
P must match the number of columns in obj.X .
r is a nonnegative scalar specifying the search radius.

idx is always of class double . D is of class
single when either obj.X or Y is single ,
in which case the distances are computed in single precision, and of
class double otherwise.

[ idx , D ] = rangesearch (&hellip;, name ,
value ) allows additional options via name-value pairs:

Name Value
'SortIndices' Logical flag indicating whether to
sort the indices by distance. Default is true .

idx and D are cell arrays where each cell contains the
indices and distances for one query point in Y .

See also:
ExhaustiveSearcher,
knnsearch,
pdist2


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 61
Find all neighbors within a specified radius of query points.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 14
KDTreeSearcher


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 762
statistics: KDTreeSearcher

KD-tree nearest neighbor searcher

The KDTreeSearcher class implements a KD-tree search algorithm for
nearest neighbor queries. It stores training data and supports various
distance metrics along with their parameter values for performing a KD-tree
search. The KD-tree algorithm partitions the training data into a
hierarchical tree structure and performs search operations by traversing
the tree to reduce the number of distance computations. It facilitates
nearest neighbor queries using knnsearch and radius queries using
rangesearch .

You can either use the KDTreeSearcher class constructor or the
createns function to create an KDTreeSearcher object.

See also:
createns,
ExhaustiveSearcher,
hnswSearcher,
knnsearch,
rangesearch


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 33
KD-tree nearest neighbor searcher



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 25
KDTreeSearcher.BucketSize


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 244
KDTreeSearcher: property BucketSize

Maximum number of data points in each leaf node

The maximum number of data points in the leaf node of the KD-tree.
Default value is 50. This property is private and cannot be modified
after object creation.


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 47
Maximum number of data points in each leaf node



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 28
KDTreeSearcher.DistParameter


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 384
KDTreeSearcher: property DistParameter

Distance parameter

The type and value of the distance parameter depends on the selected
Distance metric and can be any of the following:

For 'minkowski' , a positive scalar exponent (default 2).
Empty for other metrics ( 'euclidean' , 'cityblock' ,
'chebychev' ). Attempting to set a non-empty value for these
metrics will result in an error.


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 18
Distance parameter



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 23
KDTreeSearcher.Distance


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 232
KDTreeSearcher: property Distance

Distance metric

Distance metric used for searches, specified as a character vector.
Supported metrics are 'euclidean' , 'cityblock' ,
'minkowski' , and 'chebychev' . Default value is
'euclidean' .


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 15
Distance metric



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 29
KDTreeSearcher.KDTreeSearcher


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 1315
KDTreeSearcher: obj = KDTreeSearcher ( X )
KDTreeSearcher: obj = KDTreeSearcher ( X , name , value )

Create a KDTreeSearcher object for nearest neighbor searches.

obj = KDTreeSearcher ( X ) constructs a
KDTreeSearcher object with training data X using the
default 'euclidean' distance metric. X must be an
N&times;P numeric matrix, where rows represent observations and columns
represent features.

obj = KDTreeSearcher ( X , name , value )
allows customization through name-value pairs:

Name Value
'Distance' Distance metric, specified as a
character vector ( 'euclidean' , 'cityblock' ,
'minkowski' , 'chebychev' ). Default is
'euclidean' .
'P' Minkowski distance exponent, a positive
scalar. Valid only when 'Distance' is 'minkowski' .
Default is 2.
'BucketSize' Maximum number of data points in the
leaf node of the KD-tree, a positive integer. Default is 50.

You can also create a KDTreeSearcher object using the
createns function.

'Distance' and 'P' override the searcher&rsquo;s own metric for
that call only; the Distance and DistParameter
properties keep their values. The tree is built from the data alone, so
changing the metric does not rebuild it. 'Cov' and
'Scale' are not accepted, since they belong to metrics a kd-tree
cannot search.

See also:
KDTreeSearcher,
knnsearch,
rangesearch,
createns


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 61
Create a KDTreeSearcher object for nearest neighbor searches.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 16
KDTreeSearcher.X


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 341
KDTreeSearcher: property X

Point data

Point data, specified as an N&times;P numeric matrix where each row is
an observation and each column is a feature. This property is private
and cannot be modified after object creation.

Data of class single is stored and searched in single
precision, any other numeric class is converted to double .


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 10
Point data



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 24
KDTreeSearcher.knnsearch


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 1441
KDTreeSearcher: [ idx , D ] = knnsearch ( obj , Y )
KDTreeSearcher: [ idx , D ] = knnsearch ( obj , Y , name , value )

Find the K nearest neighbors in the training data to query points.

[ idx , D ] = knnsearch ( obj , Y , K )
returns the indices idx and distances D of the K
nearest neighbors in obj.X to each point in Y , using the
distance metric specified in obj.Distance .

obj is a KDTreeSearcher object.
Y is an M&times;P numeric matrix of query points, where
P must match the number of columns in obj.X .
idx contains the indices of the nearest neighbors in
obj.X .
D contains the corresponding distances.

idx is always of class double . D is of class
single when either obj.X or Y is single ,
in which case the distances are computed in single precision, and of
class double otherwise.

[ idx , D ] = knnsearch ( obj , Y , name ,
value ) allows additional options via name-value pairs:

Name Value
'K' A positive integer specifying the number of
nearest neighbors to find. Default is 1. A value larger than the
number of observations in the training data is answered with all of
them, since there are no more neighbors to return.
'IncludeTies' Logical flag indicating whether to
include all neighbors tied with the K th smallest distance. Default
is false . If true , idx and D are cell arrays.
'SortIndices' Logical flag indicating whether to
sort the indices by distance. Default is true .

See also:
KDTreeSearcher,
rangesearch


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 66
Find the K nearest neighbors in the training data to query points.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 26
KDTreeSearcher.rangesearch


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 1120
KDTreeSearcher: [ idx , D ] = rangesearch ( obj , Y , r )
KDTreeSearcher: [ idx , D ] = rangesearch ( obj , Y , r , name , value )

Find all neighbors within a specified radius of query points.

[ idx , D ] = rangesearch ( obj , Y , r )
returns the indices idx and distances D of all points in
obj.X within radius r of each point in Y , using the
distance metric specified in obj.Distance .

obj is a KDTreeSearcher object.
Y is an M&times;P numeric matrix of query points, where
P must match the number of columns in obj.X .
r is a nonnegative scalar specifying the search radius.

idx is always of class double . D is of class
single when either obj.X or Y is single ,
in which case the distances are computed in single precision, and of
class double otherwise.

[ idx , D ] = rangesearch ( obj , Y , r ,
name ,
value )
allows additional options via name-value pairs:

Name Value
'SortIndices' Logical flag indicating whether to
sort the indices by distance. Default is true .

idx and D are cell arrays where each cell contains the
indices and distances for one query point in Y .

See also:
KDTreeSearcher,
knnsearch


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 61
Find all neighbors within a specified radius of query points.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 8
createns


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 2102
statistics: obj = createns ( X )
statistics: obj = createns ( X , name , value , &hellip;)

Create a nearest neighbor searcher object.

obj = createns ( X ) creates a nearest neighbor searcher
object using the training data X . By default, it constructs an
ExhaustiveSearcher object with the Euclidean distance metric.

obj = createns ( X , name , value , &hellip;)
allows customization of the searcher type and its properties through
name-value pairs. The following name-value pair is supported to specify
the searcher type:

Name Value
'NSMethod' Specifies the nearest neighbor search
method. Possible values are:

'exhaustive' : Creates an ExhaustiveSearcher object.
'kdtree' : Creates a KDTreeSearcher object.
'hnsw' : Creates an hnswSearcher object.

Default is 'exhaustive' .

Additional name-value pairs depend on the selected 'NSMethod' and
are passed directly to the constructor of the corresponding class:

For 'exhaustive' , see ExhaustiveSearcher documentation
for parameters like 'Distance' , 'P' , 'Scale' , and
'Cov' .
For 'kdtree' , see KDTreeSearcher documentation for
parameters like 'Distance' , 'P' , and 'BucketSize' .
For 'hnsw' , see hnswSearcher documentation for
parameters
like 'Distance' , 'P' , 'Scale' , 'Cov' ,
'MaxNumLinksPerNode' , and 'TrainSetSize' .

Input Arguments:

X - Training data, specified as an N&times;P numeric matrix
where rows represent observations and columns represent features. Must be
finite and numeric.

Output:

obj - A nearest neighbor searcher object of type
ExhaustiveSearcher , KDTreeSearcher , or hnswSearcher ,
depending on the specified 'NSMethod' .

Examples:

## Create an ExhaustiveSearcher with default parameters
X = [1, 2; 3, 4; 5, 6];
obj = createns (X);

## Create a KDTreeSearcher with Euclidean distance
obj = createns (X, "NSMethod", "kdtree", "Distance", "euclidean");

## Create an hnswSearcher with Minkowski distance and custom parameters
obj = createns (X, "NSMethod", "hnsw", "Distance", "minkowski", "P", 3, ...
"MaxNumLinksPerNode", 2);

See also:
ExhaustiveSearcher,
KDTreeSearcher,
hnswSearcher,
knnsearch,
rangesearch


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 42
Create a nearest neighbor searcher object.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 12
hnswSearcher


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 671
statistics: hnswSearcher

Hierarchical Navigable Small World (HNSW) nearest neighbor searcher class.

The hnswSearcher class implements the HNSW algorithm for efficient
nearest neighbor queries. It stores training data and supports various
distance metrics for performing searches. The HNSW algorithm builds a
multilayer graph structure that enables fast approximate nearest neighbor
searches by navigating through the graph. It facilitates nearest neighbor
queries search using knnsearch .

You can either use the hnswSearcher class constructor or the
createns function to create an hnswSearcher object.

See also:
createns,
ExhaustiveSearcher,
KDTreeSearcher,
knnsearch


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 74
Hierarchical Navigable Small World (HNSW) nearest neighbor searcher class.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 26
hnswSearcher.DistParameter


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 577
hnswSearcher: property DistParameter

Distance parameter

The type and value of the distance parameter depends on the selected
Distance metric and can be any of the following:

For 'minkowski' , a positive scalar exponent (default 2).
For 'seuclidean' , a nonnegative vector of scaling factors
matching the number of columns in X (default is standard
deviation of X ).
For 'mahalanobis' , a positive definite covariance matrix
matching the dimensions of X (default is cov ( X ) ).
Empty for other metrics.

This property is private and cannot be modified after object creation.


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 18
Distance parameter



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 21
hnswSearcher.Distance


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 309
hnswSearcher: property Distance

Distance metric

Distance metric used for searches, specified as a character vector (e.g.,
'euclidean' , 'minkowski' , 'cityblock' ). Default
is 'euclidean' . Supported metrics align with those in
pdist2 . This property is private and cannot be modified after
object creation.


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 15
Distance metric



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 31
hnswSearcher.MaxNumLinksPerNode


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 283
hnswSearcher: property MaxNumLinksPerNode

Number of connections created for each node

Maximum number of neighbors per node in the HNSW graph. Affects graph
connectivity and search accuracy. Default value is 16. This property is
private and cannot be modified after object creation.


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 43
Number of connections created for each node



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 25
hnswSearcher.TrainSetSize


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 295
hnswSearcher: property TrainSetSize

Number of potential nearest neighbors

Size of the dynamic candidate list during graph construction. Higher
values improve accuracy at the cost of construction time. Default value
is 200. This property is private and cannot be modified after object
creation.


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 37
Number of potential nearest neighbors



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 14
hnswSearcher.X


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 339
hnswSearcher: property X

Point data

Point data, specified as an N&times;P numeric matrix where each row is
an observation and each column is a feature. This property is private
and cannot be modified after object creation.

Data of class single is stored and searched in single
precision, any other numeric class is converted to double .


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 10
Point data



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 25
hnswSearcher.hnswSearcher


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 1353
hnswSearcher: obj = hnswSearcher ( X )
hnswSearcher: obj = hnswSearcher ( X , name , value )

Create an hnswSearcher object for approximate nearest neighbor
searches.

obj = hnswSearcher ( X ) constructs an
hnswSearcher object with training data X using the
default 'euclidean' distance metric. X must be an
N&times;P numeric matrix, where rows represent observations and columns
represent features.

obj = hnswSearcher ( X , name , value )
allows customization through name-value pairs:

Name Value
'Distance' Distance metric, specified as a
character vector (e.g., 'euclidean' , 'minkowski' ,
'cityblock' ). Default is 'euclidean' . See pdist2
for supported metrics.
'P' Minkowski distance exponent, a positive
scalar. Valid only when 'Distance' is 'minkowski' .
Default is 2.
'Scale' Nonnegative vector of scaling factors
matching the number of columns in X . Valid only when
'Distance' is 'seuclidean' . Default is std (X) .
'Cov' Positive definite covariance matrix
matching the number of columns in X . Valid only when
'Distance' is 'mahalanobis' . Default is cov (X) .
'MaxNumLinksPerNode' Maximum number of neighbors
per node in the HNSW graph, a positive integer. Default is 16.
'TrainSetSize' Size of the dynamic candidate
list during graph construction, a positive integer. Default is 200.

See also:
hnswSearcher,
knnsearch,
createns,
pdist2


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 72
Create an hnswSearcher object for approximate nearest neighbor searches.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 22
hnswSearcher.knnsearch


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 1474
hnswSearcher: [ idx , D ] = knnsearch ( obj , Y )
hnswSearcher: [ idx , D ] = knnsearch ( obj , Y , name , value )

Find the nearest neighbors in the training data to query points.

[ idx , D ] = knnsearch ( obj , Y ) returns the
indices idx and distances D of the nearest neighbor in
obj.X to each point in Y , using the distance metric specified
in obj.Distance .

obj is an hnswSearcher object.
Y is an M&times;P numeric matrix of query points, where
P must match the number of columns in obj.X .
idx contains the indices of the nearest neighbors in
obj.X .
D contains the corresponding distances.

idx is always of class double . D is of class
single when either obj.X or Y is single ,
in which case the distances are computed in single precision, and of
class double otherwise.

[ idx , D ] = knnsearch ( obj , Y , name ,
value )
allows additional options via name-value pairs:

Name Value
'K' A positive integer specifying the number of
nearest neighbors to find. Default is 1. A value larger than the
number of observations in the training data is answered with all of
them, since there are no more neighbors to return.
'SearchSetSize' A positive integer specifying the
size of the candidate list of nearest neighbors for a single query point
during the search process. Default is max (10, C ) , where
C is the number of columns in obj.X . 'SearchSetSize'
must be at least C and no more than the number of rows in training
data obj.X .

See also:
hnswSearcher,
pdist2


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 64
Find the nearest neighbors in the training data to query points.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 9
knnsearch


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 5130
statistics: idx = knnsearch ( X , Y )
statistics: [ idx , D ] = knnsearch ( X , Y )
statistics: [&hellip;] = knnsearch (&hellip;, name , value )

Find k-nearest neighbors from input data.

idx = knnsearch ( X , Y ) finds K nearest
neighbors in X for Y . It returns idx which contains indices
of K nearest neighbors of each row of Y , If not specified,
K = 1 . X must be an N&times;P numeric matrix of input
data, where rows correspond to observations and columns correspond to
features or variables. Y is an M&times;P numeric matrix with query
points, which must have the same numbers of column as X .

[ idx , D ] = knnsearch ( X , Y ) also returns the
the distances, D , which correspond to the K nearest neighbour in
X for each Y

Additional parameters can be specified by Name-Value pair arguments.

Name Value
'K' is the number of nearest neighbors to be found
in the kNN search. It must be a positive integer value and by default it is
1.
'P' is the Minkowski distance exponent and it must be
a positive scalar. This argument is only valid when the selected distance
metric is 'minkowski' . By default it is 2.
'Scale' is the scale parameter for the standardized
Euclidean distance and it must be a nonnegative numeric vector of equal
length to the number of columns in X . This argument is only valid when
the selected distance metric is 'seuclidean' , in which case each
coordinate of X is scaled by the corresponding element of
'scale' , as is each query point in Y . By default, the scale
parameter is the standard deviation of each coordinate in X .
'Cov' is the covariance matrix for computing the
mahalanobis distance and it must be a positive definite matrix matching the
the number of columns in X . This argument is only valid when the
selected distance metric is 'mahalanobis' .
'BucketSize' is the maximum number of data points in
the leaf node of the Kd-tree and it must be a positive integer. This
argument is only valid when the selected search method is 'kdtree' .
'SortIndices' is a boolean flag to sort the returned
indices in ascending order by distance and it is true by default.
When the selected search method is 'exhaustive' or the
'IncludeTies' flag is true, knnsearch always sorts the
returned indices.
'Distance' is the distance metric used by
knnsearch as specified below:

'euclidean' Euclidean distance.
'seuclidean' standardized Euclidean distance. Each
coordinate difference between the rows in X and the query matrix
Y is scaled by dividing by the corresponding element of the standard
deviation computed from X . To specify a different scaling, use the
'Scale' name-value argument.
'cityblock' City block distance.
'chebychev' Chebychev distance (maximum coordinate
difference).
'minkowski' Minkowski distance. The default exponent
is 2. To specify a different exponent, use the 'P' name-value
argument.
'mahalanobis' Mahalanobis distance, computed using a
positive definite covariance matrix. To change the value of the covariance
matrix, use the 'Cov' name-value argument.
'cosine' Cosine distance.
'correlation' One minus the sample linear correlation
between observations (treated as sequences of values).
'spearman' One minus the sample Spearman&rsquo;s rank
correlation between observations (treated as sequences of values).
'hamming' Hamming distance, which is the percentage
of coordinates that differ.
'jaccard' One minus the Jaccard coefficient, which is
the percentage of nonzero coordinates that differ.
@distfun Custom distance function handle. A distance
function of the form function D2 = distfun ( XI , YI ) ,
where XI is a 1&times;P vector containing a single observation in
P -dimensional space, YI is an N&times;P matrix containing an
arbitrary number of observations in the same P -dimensional space, and
D2 is an N&times;P vector of distances, where ( D2 k) is
the distance between observations XI and ( YI k,:) .

'NSMethod' is the nearest neighbor search method used
by knnsearch as specified below.

'kdtree' Creates and uses a Kd-tree to find nearest
neighbors. 'kdtree' is the default value when the number of columns
in X is less than or equal to 10, X is not sparse, and the
distance metric is 'euclidean' , 'cityblock' ,
'manhattan' , 'chebychev' , or 'minkowski' . Otherwise,
the default value is 'exhaustive' . This argument is only valid when
the distance metric is one of the four aforementioned metrics.
'exhaustive' Uses the exhaustive search algorithm by
computing the distance values from all the points in X to each point in
Y .

'IncludeTies' is a boolean flag to indicate if the
returned values should contain the indices that have same distance as the
K^th neighbor. When false , knnsearch chooses the
observation with the smallest index among the observations that have the same
distance from a query point. When true , knnsearch includes
all nearest neighbors whose distances are equal to the K^th smallest
distance in the output arguments. To specify K , use the 'K'
name-value pair argument. In that case idx and D are
M -by- 1 cell arrays and each cell holds a row vector,
whichever search method is used.

See also:
rangesearch,
pdist2,
fitcknn


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 41
Find k-nearest neighbors from input data.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 5
mahal


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 468
statistics: d = mahal ( y , x )

Mahalanobis&rsquo; D-square distance.

Return the Mahalanobis&rsquo; D-square distance of the points in
y from the distribution implied by points x .

Specifically, it uses a Cholesky decomposition to set

answer(i) = ( y (i,:) - mean ( x )) * inv (A) *
( y (i,:)-mean ( x ))'

where A is the covariance of x .

The data x and y must have the same number of components
(columns), but may have a different number of observations (rows).


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 31
Mahalanobis' D-square distance.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 5
pdist


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 3050
statistics: D = pdist ( X )
statistics: D = pdist ( X , Distance )
statistics: D = pdist ( X , Distance , DistParameter )

Return the distance between any two rows in X .

D = pdist ( X calculates the euclidean distance between
pairs of observations in X . X must be an M&times;P numeric
matrix representing M points in P -dimensional space. This
function computes the pairwise distances returned in D as an
M&times;(M-1)/P row vector. Use Z = squareform ( D ) to
convert the row vector D into a an M&times;M symmetric matrix Z ,
where Z (i,j) corresponds to the pairwise distance between
points i and j .

D = pdist ( X , Y , Distance ) returns the
distance between pairs of observations in X using the metric specified
by Distance , which can be any of the following options.

'euclidean' Euclidean distance.
'fasteuclidean' Euclidean distance computed with an
alternative algorithm which may be faster but might reduce accuracy.
'squaredeuclidean' Squared Euclidean distance.
'fastsquaredeuclidean' Euclidean distance computed
with an alternative algorithm which may be faster but might reduce accuracy.
'seuclidean' standardized Euclidean distance. Each
coordinate difference between the rows in X and the query matrix
Y is scaled by dividing by the corresponding element of the standard
deviation computed from X . A different scaling vector can be specified
with the subsequent DistParameter input argument.
'mahalanobis' Mahalanobis distance, computed using a
positive definite covariance matrix. A different covariance matrix can be
specified with the subsequent DistParameter input argument.
'cityblock' City block distance.
'minkowski' Minkowski distance. The default exponent
is 2. A different exponent can be specified with the subsequent
DistParameter input argument.
'chebychev' Chebychev distance (maximum coordinate
difference).
'cosine' One minus the cosine of the included angle
between points (treated as vectors).
'correlation' One minus the sample linear correlation
between observations (treated as sequences of values).
'hamming' Hamming distance, which is the percentage
of coordinates that differ.
'jaccard' One minus the Jaccard coefficient, which is
the percentage of nonzero coordinates that differ.
'spearman' One minus the sample Spearman&rsquo;s rank
correlation between observations (treated as sequences of values).
@distfun Custom distance function handle. A distance
function of the form function D2 = distfun ( XI , YI ) ,
where XI is a 1&times;P vector containing a single observation in
P -dimensional space, YI is an N&times;P matrix containing an
arbitrary number of observations in the same P -dimensional space, and
D2 is an N&times;P vector of distances, where ( D2 k) is
the distance between observations XI and ( YI k,:) .

D = pdist ( X , Y , Distance ,
DistParameter )
returns the distance using the metric specified by Distance and
DistParameter . The latter one can only be specified when the selected
Distance is 'seuclidean' , 'minkowski' , and
'mahalanobis' .

See also:
pdist2,
squareform,
linkage


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 46
Return the distance between any two rows in X.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 6
pdist2


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 3984
statistics: D = pdist2 ( X , Y )
statistics: D = pdist2 ( X , Y , Distance )
statistics: D = pdist2 ( X , Y , Distance , DistParameter )
statistics: D = pdist2 (&hellip;, Name , Value )
statistics: [ D , I ] = pdist2 (&hellip;, Name , Value )

Compute pairwise distance between two sets of vectors.

D = pdist2 ( X , Y ) calculates the euclidean distance
between each pair of observations in X and Y . Let X be an
M&times;P matrix representing M points in P -dimensional space
and Y be an N&times;P matrix representing another set of points in the
same space. This function computes the M&times;N distance matrix D ,
where D (i,j) is the distance between X (i,:) and
Y (j,:) .

D = pdist2 ( X , Y , Distance ) returns the
distance between each pair of observations in X and Y using the
metric specified by Distance , which can be any of the following
options.

'euclidean' Euclidean distance.
'fasteuclidean' Euclidean distance computed with an
alternative algorithm which may be faster but might reduce accuracy.
'squaredeuclidean' Squared Euclidean distance.
'fastsquaredeuclidean' Euclidean distance computed
with an alternative algorithm which may be faster but might reduce accuracy.
'seuclidean' standardized Euclidean distance. Each
coordinate difference between the rows in X and the query matrix
Y is scaled by dividing by the corresponding element of the standard
deviation computed from X . A different scaling vector can be specified
with the subsequent DistParameter input argument.
'mahalanobis' Mahalanobis distance, computed using a
positive definite covariance matrix. A different covariance matrix can be
specified with the subsequent DistParameter input argument.
'cityblock' City block distance.
'minkowski' Minkowski distance. The default exponent
is 2. A different exponent can be specified with the subsequent
DistParameter input argument.
'chebychev' Chebychev distance (maximum coordinate
difference).
'cosine' One minus the cosine of the included angle
between points (treated as vectors).
'correlation' One minus the sample linear correlation
between observations (treated as sequences of values).
'hamming' Hamming distance, which is the percentage
of coordinates that differ.
'jaccard' One minus the Jaccard coefficient, which is
the percentage of nonzero coordinates that differ.
'spearman' One minus the sample Spearman&rsquo;s rank
correlation between observations (treated as sequences of values).
@distfun Custom distance function handle. A distance
function of the form function D2 = distfun ( XI , YI ) ,
where XI is a 1&times;P vector containing a single observation in
P -dimensional space, YI is an N&times;P matrix containing an
arbitrary number of observations in the same P -dimensional space, and
D2 is an N&times;P vector of distances, where ( D2 k) is
the distance between observations XI and ( YI k,:) .

D = pdist2 ( X , Y , Distance ,
DistParameter )
returns the distance using the metric specified by Distance and
DistParameter . The latter one can only be specified when the selected
Distance is 'seuclidean' , 'minkowski' , and
'mahalanobis' .

D = pdist2 (&hellip;, Name , Value ) for any previous
arguments, modifies the computation using Name - Value parameters.

D = pdist2 ( X , Y , Distance , 'Smallest' ,
K ) computes the distance using the metric specified by
Distance and returns the K smallest pairwise distances to
observations in X for each observation in Y in ascending order.

D = pdist2 ( X , Y , Distance ,
DistParameter ,
'Largest' , K ) computes the distance using the metric specified
by Distance and DistParameter and returns the K largest
pairwise distances in descending order.

[ D , I ] = pdist2 (&hellip;, Name , Value ) also
returns the matrix I , which contains the indices of the observations in
X corresponding to the distances in D . You must specify either
'Smallest' or 'Largest' as an optional Name - Value
pair argument to compute the second output argument.

See also:
pdist,
knnsearch,
rangesearch


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 54
Compute pairwise distance between two sets of vectors.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 11
rangesearch


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 4841
statistics: idx = rangesearch ( X , Y , r )
statistics: [ idx , D ] = rangesearch ( X , Y , r )
statistics: [&hellip;] = rangesearch (&hellip;, name , value )

Find all neighbors within specified distance from input data.

idx = rangesearch ( X , Y , r ) returns all the
points in X that are within distance r from the points in
Y .
X must be an N&times;P numeric matrix of input data, where rows
correspond to observations and columns correspond to features or variables.
Y is an M&times;P numeric matrix with query points, which must have
the same numbers of column as X . r must be a nonnegative scalar
value. idx is an M&times;1 cell array, where M is the number
of observations in Y . The vector Idx {j} contains the
indices of observations (rows) in X whose distances to
Y (j,:) are not greater than r .

[ idx , D ] = rangesearch ( X , Y , r ) also
returns the distances, D , which correspond to the points in X
that are within distance r from the points in Y . D is an
M&times;1 cell array, where M is the number of observations in
Y . The vector D {j} contains the distances of
observations (rows) in X whose distances to Y (j,:) are
not greater than r .

Additional parameters can be specified by Name-Value pair arguments.

Name Value
'P' is the Minkowski distance exponent and it must be
a positive scalar. This argument is only valid when the selected distance
metric is 'minkowski' . By default it is 2.
'Scale' is the scale parameter for the standardized
Euclidean distance and it must be a nonnegative numeric vector of equal
length to the number of columns in X . This argument is only valid when
the selected distance metric is 'seuclidean' , in which case each
coordinate of X is scaled by the corresponding element of
'scale' , as is each query point in Y . By default, the scale
parameter is the standard deviation of each coordinate in X .
'Cov' is the covariance matrix for computing the
mahalanobis distance and it must be a positive definite matrix matching the
the number of columns in X . This argument is only valid when the
selected distance metric is 'mahalanobis' .
'BucketSize' is the maximum number of data points in
the leaf node of the Kd-tree and it must be a positive integer. This
argument is only valid when the selected search method is 'kdtree' .
'SortIndices' is a boolean flag to sort the returned
indices in ascending order by distance and it is true by default.
When the selected search method is 'exhaustive' or the
'IncludeTies' flag is true, rangesearch always sorts the
returned indices.
'Distance' is the distance metric used by
rangesearch as specified below:

'euclidean' Euclidean distance.
'seuclidean' standardized Euclidean distance. Each
coordinate difference between the rows in X and the query matrix
Y is scaled by dividing by the corresponding element of the standard
deviation computed from X . To specify a different scaling, use the
'Scale' name-value argument.
'cityblock' City block distance.
'chebychev' Chebychev distance (maximum coordinate
difference).
'minkowski' Minkowski distance. The default exponent
is 2. To specify a different exponent, use the 'P' name-value
argument.
'mahalanobis' Mahalanobis distance, computed using a
positive definite covariance matrix. To change the value of the covariance
matrix, use the 'Cov' name-value argument.
'cosine' Cosine distance.
'correlation' One minus the sample linear correlation
between observations (treated as sequences of values).
'spearman' One minus the sample Spearman&rsquo;s rank
correlation between observations (treated as sequences of values).
'hamming' Hamming distance, which is the percentage
of coordinates that differ.
'jaccard' One minus the Jaccard coefficient, which is
the percentage of nonzero coordinates that differ.
@distfun Custom distance function handle. A distance
function of the form function D2 = distfun ( XI , YI ) ,
where XI is a 1&times;P vector containing a single observation in
P -dimensional space, YI is an N&times;P matrix containing an
arbitrary number of observations in the same P -dimensional space, and
D2 is an N&times;P vector of distances, where ( D2 k) is
the distance between observations XI and ( YI k,:) .

'NSMethod' is the nearest neighbor search method used
by rangesearch as specified below.

'kdtree' Creates and uses a Kd-tree to find nearest
neighbors. 'kdtree' is the default value when the number of columns
in X is less than or equal to 10, X is not sparse, and the
distance metric is 'euclidean' , 'cityblock' ,
'manhattan' , 'chebychev' , or 'minkowski' . Otherwise,
the default value is 'exhaustive' . This argument is only valid when
the distance metric is one of the four aforementioned metrics.
'exhaustive' Uses the exhaustive search algorithm by
computing the distance values from all the points in X to each point in
Y .

See also:
knnsearch,
pdist2


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 61
Find all neighbors within specified distance from input data.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 10
squareform


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 1182
statistics: zOut = squareform ( yIn )
statistics: yOut = squareform ( zIn )
statistics: zOut = squareform ( yIn , 'tovector' )
statistics: yOut = squareform ( zIn , 'tomatrix' )

Interchange between distance matrix and distance vector formats.

Converts between a hollow (diagonal filled with zeros), square, and
symmetric matrix and a vector of the lower triangular part.

Its target application is the conversion of the vector returned by
pdist into a distance matrix. It performs the opposite operation
if input is a matrix.

If x is a numeric or logical vector, its number of elements must fit
into the triangular part of a matrix (main diagonal excluded). In other
words, numel ( x ) = n * ( n - 1) / 2 for some integer
n . The resulting matrix will be n by n .

If x is a numeric or logical distance matrix, it must be square and the
diagonal entries of x must all be zeros. If x is not symmetric,
only the lower triangular part is used.

The second argument is used to specify the output type in case the distance
input is a scalar. Accepted values are 'tomatrix' (or 'tom' )
and 'tovector' (or 'tov' ). If not specified, it defaults to
'tomatrix' otherwise.

See also:
pdist


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 64
Interchange between distance matrix and distance vector formats.





