NearestNeighbors.jl icon indicating copy to clipboard operation
NearestNeighbors.jl copied to clipboard

periodic kdtree or balltree

Open moradza opened this issue 3 years ago • 6 comments

I am trying to use this package to build neighbor lists. I am new to Julia. Can you help me in the implementation of periodic elucidation distance or add it as a functionality?

moradza avatar Jan 13 '22 03:01 moradza

You can find the PeriodicEuclidean distance over at Distances.jl. And then you can pass it as the metric argument to the tree constructor here. You'll need to use a BallTree, though, because PeriodicEuclidean is not a Minkowski-type metric.

dkarrasch avatar Jan 13 '22 10:01 dkarrasch

In what sense is PeriodicEucledean not a Minkowski Metric? As it is very similar to the Eucledean would it not be quite easy to also implement it for KDTree?

oameye avatar Jan 16 '22 13:01 oameye

In what sense is PeriodicEucledean not a Minkowski Metric? As it is similar to the Eucledean would it not be quite easy to also implement it for KDTree?

Did a quick google search. It seems that for periodic euclidean metric the canonical KD tree structure is not applicable. Nevertheless, as this review indicates there are modified KD Tree structures which can handle periodic boundaries.

oameye avatar Jan 16 '22 13:01 oameye

I guess it should be possible https://namdanalyzer.readthedocs.io/en/latest/kdTree/periodic_kdtree.html. I am still learning Julia, do you have an example of using distance.jl with ballTree.

moradza avatar Jan 16 '22 20:01 moradza

I guess it should be possible https://namdanalyzer.readthedocs.io/en/latest/kdTree/periodic_kdtree.html. I am still learning Julia, do you have an example of using distance.jl with ballTree.

using NearestNeighbors
using Distances
data = rand(1, 10^4)
r = 0.05
point = rand(1)

balltree = BallTree(data, PeriodicEuclidean([1]))
idxs = inrange(balltree, point, r)

oameye avatar Jan 17 '22 07:01 oameye