-
Notifications
You must be signed in to change notification settings - Fork 8
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
What does the radius parameter do? #5
Comments
Hello, Andrew Thank you for the feedback! Example of how it supposed to work: import numpy as np
import pynanoflann
X_index = np.array([[0, 0], [100., 0.], [0., 100.], [100., 100.]])
"""
2 3
|
|
|
|
|
0--------------1
"""
nn = pynanoflann.KDTree(n_neighbors=5, metric='L1', radius=100)
nn.fit(X_index)
query = X_index[:1] # point at (0, 0)
_, indices = nn.radius_neighbors(query, radius=0)
print(indices) # no matches
_, indices = nn.radius_neighbors(query, radius=50)
print(indices) # point at (0, 0)
_, indices = nn.radius_neighbors(query, radius=200-0.01)
print(indices) # points (0, 0), (100, 0), (0, 100); distance to (100, 100) == 200
_, indices = nn.radius_neighbors(query, radius=200+0.01)
print(indices) # all points Output:
that is, the results depends on the radius. |
Thanks! I guess my confusion is what the radius parameter in Edit: Edit2: |
For the radius query, there seems to be a minor bug. The python interface is returning square rooted distance, but the radius query takes in a squared query. |
@aluo-x that's expected behaviour then, for a L2 query, nanoflann takes in a squared radius and returns a list of squared distances, so the python interface squares the provided euclidean radius as input and then takes the square root of the squared distances to return regular distances. If you specify a radius from If that's confusing, I can submit a PR which squares the radius passed to |
I'm not sure that is the expected behavior. The python interface as of right now uses euclidean distance as function input, but returns squared euclidean distances. The KDTree construction also seems to ignore the radius argument. Edit: I mean to say, the function takes in squared euclidean distance, but returns euclidean distance. |
Yeah, I agree it is confusing that the constructor radius is the regular distance but the |
Sorry for the confusion, I've made a fix to this bug: You could try new version: pip install git+https://github.com/u1234x1234/pynanoflann.git@0.0.9 Thank you for the feedback |
First thanks for this great tool.
I'm a little confused by the radius parameter:
nn = pynanoflann.KDTree(n_neighbors=5, metric='L1', radius=100)
It seems like I can set this to a tiny value and still get correct results when I query.
The text was updated successfully, but these errors were encountered: