New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to return at most N nearest neighbors? #1
Comments
There's no built-in function for this, but it is possible by customizing matching done in the library. There's Lines 96 to 102 in c273038
and if you create your own implementation of that visitor: Lines 111 to 130 in c273038
you can collect N elements instead of picking one. |
If I always keep N nearest visited nodes in my implementation of the BestCandidate trait, would it be guaranteed that after the find_nearest_custom function return, the N remaining nodes are the the nearest N's among all the nodes? The reason why I'm curious about this question is that tree-like structure can trim unnecessary searching branches to speedup the search. What if the trimmed branches contain nodes that is among the N nearest ones? |
You're right! There's one more trick you have to do: best_candidate.distance() has to return distance of the Nth farthest node, which will force it to search everything in that radius. |
I found myself needing the same thing as described in this issue, I made a pull request adding examples on how to achieve this! See #3. |
According to the API doc, there is a find_nearest function. However, by default, it can only return the nearest neighbor node. How can I find out at most N nearest neighbors? This is import for interpolation.
The text was updated successfully, but these errors were encountered: