Nearest Neighbor Matching without Replacement
古いコメントを表示
Hello there,
I am looking to match data in two vectors, x and y, based on shortest Euclidean distance. Each match should be unique; that is, numbers in vectors x and y cannot be matched twice. I have looked into knnsearch, but have not found anything that suggests the function works without replacement. Thank you!
3 件のコメント
KSSV
2016 年 12 月 8 日
Well, it means for each point you want only one nearest neighbor and this neighbor should not be neighbor to any other point. Is it? If so you have to violate shortest Eucldean distance if neighbor repeats.
Phillip
2018 年 3 月 30 日
It does not violate the shortest distance if it is removed from the set once matched (what Al is referring too when he says " without Replacement").
Peng Li
2020 年 3 月 31 日
any update here? also was wondering if there is a way to do knn search without replacement.
回答 (2 件)
neuroDuck
2022 年 2 月 25 日
A late response, but for anyone that might come across this in future, I think a brute force approach should work, with the following code, assuming you don't have too many comparisons to go through:
[cIdx] = unique(knnsearch(x,y));
% brute force knnsearch to do without replacements
startingK = 2;
while length(cIdx)<length(y)
[cIdx] = unique(knnsearch(x,y,'k',startingK));
startingK = startingK + 1;
end
If you have R2019a release
x=rand(1,10)
y=rand(1,10)
C=abs(x(:)-y(:).');
M = matchpairs(C,max(C(:)));
px = M(:,1);
xm = x(px)
d = abs(xm-y)
カテゴリ
ヘルプ センター および File Exchange で Nearest Neighbors についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!