Skip to content

Taking the square root of distances is now optional#10

Open
hochshi wants to merge 3 commits intou1234x1234:masterfrom
hochshi:master
Open

Taking the square root of distances is now optional#10
hochshi wants to merge 3 commits intou1234x1234:masterfrom
hochshi:master

Conversation

@hochshi
Copy link
Copy Markdown

@hochshi hochshi commented Feb 20, 2023

I've added a root_dist flag that allow the distances returned from nanoflann to stay squared even when using a L2 norm.
I've also added 2 tests to verify the addition of the flag the results remain consistent with sklearn.

Also bumped the version in setup.py to 0.0.9.

@u1234x1234
Copy link
Copy Markdown
Owner

Hi,

Thank you for the contribution!

What do you think about making it as a different metric name not as an additional root_dist argument?
I mean that root_dist does not affect L1 distance and it's not clear what to expect in cases (metric='L1', root_dist=True) or (metric='L1', root_dist=False).

My suggestion is to add a new metric L2_squared in addition to L1 and L2. And when the metric is L2_squared keep the distances squared by not taking root. So it will be something similar to:

if metric == "l2":
  dists = np.sqrt(dists)    # will be skipped with metric="l2_squared"

or

    if metric == "l2":
        g_d = [np.sqrt(x) for x in g_d]

@hochshi
Copy link
Copy Markdown
Author

hochshi commented Feb 22, 2023

Sure. I'll make the changes soon.
I was surprised at first that the distances were square rooted, as nanoflann's behaviour is to return squared distances.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants