K-Nearest Neigbors and Radius (Range) Search
Filed under: Algorithms, Computational Geometry, Mathematics
2 Comments
BruteSearchMex
When the dataset is small, when you have to run only a few number of search, or when the dimensions of points is large, the brute search method is still faster than kd-trees data structure. Computing the distances one by one take a minor time than building the tree.
Some of this problems have became less gravous since the introduction of GLTree (file id 22190) which allows for a very fast tree construction.
Despite this, very small dataset are still terrain for brute search algorithms.
I saw many k-neighbours utilities on FEX, but all them were m-coded. I think such a brute calculation is not an m-code job. So I developed my own Nearest Neighbour finder. It is nothing special it just computes all the distances and take the ones required from the input parameters, but of course the mex implementation make it even faster than vectorized m-code.
The following utilities are provided:
- Nearest neighbor
- K-Nearest neighbors
- Radius Search
They al supports N-dimensions and work on double, it is possible to choose if return the distances.
Here is a time comparison with a vectrized m-code:
Output:
Elapsed time is 0.962640 seconds.
Elapsed time is 18.813100 seconds.
For info, questions, suggestions, bugs: giaccariluigi@msn.com
Download Now
Popularity: 7% [?]
Related Posts
Comments
2 Comments on K-Nearest Neigbors and Radius (Range) Search
-
Arne Bøckmann on
Mon, 12th Oct 2009 18:29
Could you provide an example on how to find the sparse connectivity matrix with a specified cut-off radius ? Could this radius also differ from point to point?
[Reply]
Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!
Include MATLAB code in your comment by doing the following:
<pre lang="MATLAB">
%insert code here
</pre>



















































Luigi Giaccari Reply:
October 12th, 2009 at 19:53
Try this:
Consider that sparse matrix in Maltab is class defined for doubles. So if you want a logical amtrix you need to use:
It depends on what are your requirements.
Second, yes radius can be different. Radisu search supports only one query time so you have to call the rourtine each loop.
Good luck
Luigi
[Reply]