knnsearch or rangesearch with annulus

6 visualizzazioni (ultimi 30 giorni)
Matthew
Matthew il 27 Nov 2018
Commentato: Matthew il 6 Dic 2018
For those of you familiar with Matlab's knnsearch routine (via creating a KDTree from the KDTreeSearcher routine (accessible from the Statistics and Machine Learning Toolbox)), is there a way to use to use the rangesearch and/or knnsearch comands to find the nearest neighbors of a given focal point, , say, that belong to an annulus around that focal point?
More specifically, I am trying to implement a nearest neighbor search about , and I would like to avoid being returned in the subsequent list of neighbors. After I create the KDTree (via the KDTreeSearcher command), I then use the same tree in a for-loop for many focal points. Thus, I would like to avoid creating a new KDTree for each focal point. Here are two ways to find nearest neighbors:
% construct a KDTree from some N-dimensional data
xData = randn(100,5);
xKDTree = KDTreeSearcher(xData);
% focal point
x0 = xData(1,:);
% returns the 5 nearest neighbors in the previously-constructed KDTree of the focal point x0
[IDX, D] = knnsearch(xKDTree, x0, 'K', 5);
% (note: IDX(1) = 1 and D(1) = 0)
% returns the neighbors that are located a maximum distance of 1.5 units away from the focal point x0
[IDX, D] = rangesearch(xKDTree, x0, 1.5);
% (note: IDX{1}(1) = 1 and D{1}(1) = 0)
By default, rangesearch returns the nearest neighbors that are located within some r-ball or disk of . That is, x is a nearest neighbor of if . Naturally, the focal point is a member of this set. Visually,
Yes, I am aware that I could run rangesearch (or knnsearch) once to return -many neighbors and then remove the focal point from this list. However, rangesearch and knnsearch accommodate so many search and distance/metric options that I'm curious if there is an option to use an annulus rather than an r-ball. That is, after creating xKDTree, is there a way to execute knnsearch either to find K-many nearest neighbors located a positive distance from a focal point (rather than simply a non-negative distance), or to find neighbors located in an annulus about the given focal point, ? (I am using the Euclidean norm).
Thank you for your time.
  3 Commenti
Matthew
Matthew il 27 Nov 2018
Modificato: Matthew il 27 Nov 2018
(basic diagrams posted)

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by