KristofferC / NearestNeighbors.jl

High performance nearest neighbor data structures (KDTree and BallTree) and algorithms for Julia.
Other
413 stars 65 forks source link

periodic kdtree or balltree #133

Open moradza opened 2 years ago

moradza commented 2 years ago

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?

dkarrasch commented 2 years ago

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.

oameye commented 2 years ago

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 commented 2 years ago

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.

moradza commented 2 years ago

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.

oameye commented 2 years ago

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)

KristofferC commented 2 months ago

Searches with periodic boundaries are implemented by mapping all initial data points to one canonical periodic image, building an ordinary kd-tree with these points, then querying this kd-tree multiple times, if necessary, with all the relevant periodic images of the query point.

We could do this.