⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testbrutesearch.m

📁 K-nearest neighbors 搜索 聚类时经常使用的一种方法 国外网站转载
💻 M
字号:

%Warning workspace will be cleared
clc
clear all
close all


mex BruteSearchMex.cpp
fprintf('Mex successifully completed!!!!\n');



N=1000000;%number of reference points
Nq=100;%number of query points
dim=3;%dimension of points
k=3;%number of neighbor
r=.1;%Search radius

p=rand(N,dim);%Note that functions in this new version requires the transpose of these matrix
qp=rand(Nq,dim);


%% Nearest Neighbor
fprintf('\n\n\nNearest Neighbor Search of %4.0f query points and %4.0f reference points\n',N,Nq)
tic
[idc]=BruteSearchMex(p',qp');%find the nearest neighbour for each query points                    
fprintf('\t-Not returning the distances took: %4.4f s\n',toc)
tic
[idc,dist]=BruteSearchMex(p',qp');%same but returns also the distance of
fprintf('\t-Returning the distances took: %4.4f s\n',toc)



%% K-Nearest neighbor
fprintf('\n\n\n %1.0f Nearest Neighbors Search of %4.0f query points and %4.0f reference points\n',k,N,Nq)
tic
kidc=BruteSearchMex(p',qp','k',k);%find the K nearest neighbour for each query points
fprintf('\t-Not returning the distances took: %4.4f s\n',toc)                        

tic
[kidc,kdist]=BruteSearchMex(p',qp','k',k);%same but also returns  the distance
fprintf('\t-Returning the distances took: %4.4f s\n',toc)                                   


%% Radius Search

% NOTE: Differently from the others the radius search only supports one
% input query point

fprintf('\n\n\nRadius Search of %4.0f query points and %4.0f reference points within radius=%4.4f\n',N,Nq,r)
tic

for i=1:Nq
    ridc=BruteSearchMex(p',qp(i,:)','r',r);%finds the points within the serach radius
end
fprintf('\t-Not returning the distances took: %4.4f s\n',toc)
for i=1:Nq
    [ridc,rdist]=BruteSearchMex(p',qp(i,:)','r',r);%same but also returns  the distances                                                   %     distance of pints
end
fprintf('\t-Returning the distances took: %4.4f s\n',toc) 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -