Comments (11)
If it satisfies the requirements for being a metric then the ball tree should be able to handle it.
from nearestneighbors.jl.
ok, then I will give it a try. Can we leave this open so I can ask questions if needed.
from nearestneighbors.jl.
Sure
from nearestneighbors.jl.
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.
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.
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.
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.
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 SVector
s during the creation of the ball tree.
from nearestneighbors.jl.
that seems to have done it - thanks. I'll now go back to trying periodicity.
from nearestneighbors.jl.
Any updated. Should this be closed?
from nearestneighbors.jl.
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)
- Is there a reason sqeuclidean distance is not supported? HOT 4
- README.md Misleading Custom Metric Documentation
- Document that `inrangecount` also counts the point itself HOT 2
- [Question] Can you insert new data into an existing KDTree object? HOT 2
- Compilation time issues with very high dimensions HOT 3
- Reverse Cuthill-McKee ordering option HOT 1
- Querying number of distance evaluations HOT 3
- Make datatypes of the KNN results selectable for potentially lower memory overhead
- Does ball tree work with any metric? HOT 2
- Add example with `skip` option to documentation HOT 1
- Julia 1.10 is waiting on IO to finish during compilation HOT 3
- It should be possible to make `KDNode` smaller
- KDTree: Wrong results for non-Euclidean metrics
- Cannot build KDTree with Subarrays since v0.4.14 HOT 3
- KDTree with Matrix{ComplexF64} HOT 1
- Can't do `knn` on `AbstractVector{SVector}` HOT 2
- Test benchmarks and have them run on CI
- 1.0 road map HOT 5
- `get_min_distance_sq` seems weird
- Interface for tree traversal / walking of BallTree/KDTree HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nearestneighbors.jl.