matlat之KDTreeSearcher()函数

Create Kd-tree nearest neighbor searcher(创建kd-树最近邻搜索器)。

Description

KDTreeSearcher model objects store the results of a nearest neighbor search that uses the Kd-tree algorithm. Results include the training data, distance metric and its parameters, and maximum number of data points in each leaf node (that is, the bucket size). The Kd-tree algorithm partitions an n-by-K data set by recursively splitting n points in K-dimensional space into a binary tree.

KDrelesearcher模型对象存储最近邻搜索的结果,该搜索使用kd-tree算法。结果包括训练数据、距离及其参数,以及每个叶子节点中的最大数据点数目(即BucketSize)。KD-树算法通过递归地将k维空间中的n个点分割为二叉树来分割n行k列数据集。

Once you create a KDTreeSearcher model object, you can search the stored tree to find all neighboring points to the query data by performing a nearest neighbor search using knnsearch or a radius search usingrangesearch. The Kd-tree algorithm is more efficient than the exhaustive search algorithm when K is small (that is, K ≤ 10), the training and query sets are not sparse, and the training and query sets have many observations.

创建KDrelesearcher模型对象后,可以通过使用knnsearch()函数或使用rangesearch()函数搜索执行最近的邻居搜索来搜索所存储的树,以查找查询数据的所有相邻点。当维数K比较小的时候(如k≤10),Kd-tree算法比穷举搜索算法更有效,训练和查询集并不稀疏,训练和查询集具有许多观察结果。

Syntax

Mdl = KDTreeSearcher(X)
Mdl = KDTreeSearcher(X,Name,Value)
 

Description

example

Mdl = KDTreeSearcher(X) grows a default Kd-tree (Mdl) using the n-by-K numeric matrix of training data (X).

KDTreeSearcher(X)使用训练数据(X)的n行k列数字矩阵生长默认的kd-树(Mdl)。

example

Mdl = KDTreeSearcher(X,Name,Value) specifies additional options using one or more name-value pair arguments. You can specify the maximum number of data points in each leaf node (that is, the bucket size) and the distance metric, and set the distance metric parameter (DistParameter) property. For example,KDTreeSearcher(X,'Distance','minkowski','BucketSize',10) specifies to use the Minkowski distance when searching for nearest neighbors and to use 10 for the bucket size. To specify DistParameter, use the P name-value pair argument.

mdl=kdtreesearcher(x,name,value)使用一个或多个名称-值对参数指定附加选项。您可以在每个叶子节点(即bucket size)和距离度量中指定数据点的最大数量,并设置距离度量参数属性。例如,KDTreeSearcher(x,‘Distance’,‘Minkowski’,‘BucketSize’,10)指定在搜索最近的邻居时使用Minkowski距离,bucket size指定为10。若要指定DistParameter参数,请使用p name-value对参数。

Object Functions  对象函数

knnsearch Find k-nearest neighbors using searcher object
rangesearch Find all neighbors within specified distance using searcher object

knnsearch:用搜索器对象Mdl寻找k个临近点。

rangesearch:使用搜索器对象Mdl以指定的距离范围寻找所有临近点。

举例:

load fisheriris;
X = meas;
[n,k] = size(X);
Mdl1 = KDTreeSearcher(X);

X has 150 observations and 4 predictors.  

n=150

k=4

 

X有150个观测值和4个预测器。(predictors翻译成预测器好像有些别扭!)

Grow a four-dimensional Kd-tree using the entire data set as training data.

使用整个数据集作为训练样本来生成四维KD-树。

总结:Mdl1 = KDTreeSearcher(X);这一句中的原始样本数据和利用原始样本数据建立的KDTreeSearcher(kd树搜索器)是完全一样的,只不过一个是离散的点,一个是对象。

原文地址:https://www.cnblogs.com/yibeimingyue/p/10876174.html