Giter VIP home page Giter VIP logo

Comments (11)

KristofferC avatar KristofferC commented on August 23, 2024

If it satisfies the requirements for being a metric then the ball tree should be able to handle it.

from nearestneighbors.jl.

cortner avatar cortner commented on August 23, 2024

ok, then I will give it a try. Can we leave this open so I can ask questions if needed.

from nearestneighbors.jl.

KristofferC avatar KristofferC commented on August 23, 2024

Sure

from nearestneighbors.jl.

cortner avatar cortner commented on August 23, 2024

I get the following error message; the data I am passing in is a Array{FixedSizeArrays.Vec{3,Float64},1}; I am guessing this fails because FixedSizeArrays.Vec is not a subtype of AbstractArray? Can you confirm?

LoadError: MethodError: no method matching NearestNeighbors.BallTree{V<:AbstractArray{T,1},N,T,M<:Distances.Metric}(::Array{FixedSizeArrays.Vec{3,Float64},1}, ::PerMet.PeriodicEuclidean)
Closest candidates are:
  NearestNeighbors.BallTree{V<:AbstractArray{T,1},N,T,M<:Distances.Metric}{V<:AbstractArray{T,N},M<:Distances.Metric}(!Matched::Array{V<:AbstractArray,1}, ::M<:Distances.Metric; leafsize, reorder, storedata, indicesfor, reorderbuffer) at /Users/ortner/.julia/v0.5/NearestNeighbors/src/ball_tree.jl:39
  NearestNeighbors.BallTree{V<:AbstractArray{T,1},N,T,M<:Distances.Metric}{T<:AbstractFloat,M<:Distances.Metric}(!Matched::Array{T<:AbstractFloat,2}, ::M<:Distances.Metric; leafsize, storedata, reorder, indicesfor, reorderbuffer) at /Users/ortner/.julia/v0.5/NearestNeighbors/src/ball_tree.jl:83
  NearestNeighbors.BallTree{V<:AbstractArray{T,1},N,T,M<:Distances.Metric}{T}(::Any) at sysimg.jl:53
while loading In[12], in expression starting on line 2

from nearestneighbors.jl.

KristofferC avatar KristofferC commented on August 23, 2024

Yes, that is the reason. There are two solutions to this. Either, I relax the constraint of AbstractVector or alternatively you convert / reinterpret your vector to something like https://github.com/andyferris/StaticArrays.jl (which I think has a cleaner interface).

julia> using FixedSizeArrays

julia> using StaticArrays

julia> a = [Vec{3}(1.0,2.0,3.0), Vec{3}(1.0,2.0,3.0)]
2-element Array{FixedSizeArrays.Vec{3,Float64},1}:
 Vec(1.0,2.0,3.0)
 Vec(1.0,2.0,3.0)

julia> reinterpret(SVector{3, Float64}, a, (2,))
2-element Array{StaticArrays.SVector{3,Float64},1}:
 [1.0,2.0,3.0]
 [1.0,2.0,3.0]

from nearestneighbors.jl.

cortner avatar cortner commented on August 23, 2024

Yes I just checked that staticarrays works. I've been thinking of switching for a while. Anyhow now I get a stack overflow and need to do some debugging. Thank you.

from nearestneighbors.jl.

cortner avatar cortner commented on August 23, 2024

Finally found time to look at it. My problem is a generic Julia problem - I hope you don't mind that I post this here, but feel free to ask me to move this to Julia users.

So I am trying to define PeriodicEuclidean <: Metric not in the Distances module, but in my own module. I was hoping that your function Distances.evaluate(d::Distances.PreMetric, ...) would correctly call my implementation of evaluate, but it turns out it doesn't and instead calls itself 80_000 times causing a stack overflow. I think there is still something I don't fully understand about dispatch. Probably there are multiple versions of the Distances module?

using Distances, NearestNeighbors, StaticArrays
module PerMet
using StaticArrays, Distances
type PeriodicEuclidean <: Metric end   # at the moment just do Euclidean
function Distances.evaluate(dist::PeriodicEuclidean, a::SVector{3, Float64}, b::SVector{3, Float64}) 
    print("*")
    norm(a-b)
end 
end 
dist = PerMet.PeriodicEuclidean()
X =  reinterpret(SVector{3, Float64}, rand(3, 10), (10,))
# Distances.evaluate(dist, X[1], X[2])   # this calls the correct `evaluate`
pertree = BallTree(X, dist)    # this never calls the "*" implementation but instead creates a stack overflow

from nearestneighbors.jl.

KristofferC avatar KristofferC commented on August 23, 2024

Your evaluate function is too strongly typed. Change the types of a and b to AbstractVector and it will at least work to create the tree. The problem is that evaluate is not only called with SVectors during the creation of the ball tree.

from nearestneighbors.jl.

cortner avatar cortner commented on August 23, 2024

that seems to have done it - thanks. I'll now go back to trying periodicity.

from nearestneighbors.jl.

KristofferC avatar KristofferC commented on August 23, 2024

Any updated. Should this be closed?

from nearestneighbors.jl.

cortner avatar cortner commented on August 23, 2024

I didn't find time to work on it - sorry. Best close it and I'll either reopen it or find you on Gitter if I ever get back to it. Thank yu

from nearestneighbors.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.