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

knn: skipped items output when there is a skip function has always the last index and not 0 index #145

Closed
lukeanto opened this issue Jun 12, 2022 · 3 comments · Fixed by #146
Labels

Comments

@lukeanto
Copy link

lukeanto commented Jun 12, 2022

Hello, I had old code written for Julia 1.0

using NearestNeighbors
data = [[0.13380863416387367, 0.7845254987714512],[0.1563342025559629, 0.7956456895676077],[0.23320094627474594, 0.9055515160266435]]
tree = KDTree(hcat(map(p -> [p[1], p[2]], data)...))
nearest, distance = knn(tree, [0.15, 0.8], 3, true, x -> x == 2)

In Julia 1.0, nearest is returned as [1, 3, 0], because 2 is skipped; in Julia 1.7.3, nearest is returned as [1, 3, 3], which seems not correct.

Packages status in Julia 1.0

  [15f4f7f2] AutoHashEquals v0.2.0
  [864edb3b] DataStructures v0.18.13
  [c27321d9] Glob v1.3.0
  [cd3eb016] HTTP v0.9.17
  [7073ff75] IJulia v1.23.3
  [6218d12a] ImageMagick v0.7.9
  [02fcd773] ImageTransformations v0.8.13
  [916415d5] Images v0.23.3
  [b8a86587] NearestNeighbors v0.4.10

Packages statuses in Julia 1.7.3:

  [15f4f7f2] AutoHashEquals v0.2.0
  [864edb3b] DataStructures v0.18.13
  [c27321d9] Glob v1.3.0
  [cd3eb016] HTTP v0.9.17
  [6218d12a] ImageMagick v1.2.1
  [02fcd773] ImageTransformations v0.9.4
  [916415d5] Images v0.25.2
  [b8a86587] NearestNeighbors v0.4.10

So they are the same, except for IJulia, which should not be significant anyway

@KristofferC
Copy link
Owner

KristofferC commented Jun 13, 2022

It's a bit strange that the Julia version would change this... I'll try to figure out what changed.

Edit: Ah, it is a bounds error...

@KristofferC
Copy link
Owner

Can you try with #146?

@lukeanto
Copy link
Author

Tried just now, this is the final output,

...
julia> nearest, distance = knn(tree, [0.15, 0.8], 3, true, x -> x == 2)
([1, 3], [0.02239688629947563, 0.13440059522389006])

It is different from the original [1, 3, 0], but seems anyway correct to me (probably better, I have not to check for index 0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants