Skip to content
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

Distances #1299

Merged
merged 2 commits into from
Aug 5, 2024
Merged

Distances #1299

merged 2 commits into from
Aug 5, 2024

Conversation

kremnik
Copy link
Contributor

@kremnik kremnik commented Aug 4, 2024

What has been done

With this PR, some little optimizations of distance calculations have been done:

  1. Using np.linalg.norm for norm and Euclidean distance calculations
  2. Adding zero denominator checks in the l2_normalize function

How to test

make lint && make test

@serengil
Copy link
Owner

serengil commented Aug 4, 2024

old find_euclidean_distance function returns 0.9086272014052611 for dataset/img1.jpg and dataset/img2.jpg whereas new function returns 0.908627201405261

thresholds are tuned for the old function. i am not confident to merge this to cause any trouble.

@kremnik
Copy link
Contributor Author

kremnik commented Aug 4, 2024

@serengil The values are extremely close, with the difference appearing in the 15th decimal digit. Since the thresholds precision is set to 2 decimal digits, so small difference should not affect the overall results.

@serengil
Copy link
Owner

serengil commented Aug 5, 2024

yeah you are totally right, it is my bad.

@serengil serengil merged commit 285c6b7 into serengil:master Aug 5, 2024
2 checks passed
@serengil
Copy link
Owner

serengil commented Aug 5, 2024

TLDR: np.linalg.norm(a - b) is equivalent to np.sqrt(np.sum(np.multiply(a - b, a - b))). Both methods compute the Euclidean distance between two vectors a and b.

@serengil
Copy link
Owner

serengil commented Aug 5, 2024

@kremnik LGTM and merged. Thank you for your contribution.

@kremnik kremnik deleted the distances branch August 5, 2024 23:38
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