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

[WIP] A generalized PeriodicEuclidean (allows specifying the periods as a parallelogon) #237

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

GiggleLiu
Copy link

@GiggleLiu GiggleLiu commented Dec 20, 2021

In physics, we often use lattices, the periodic boundary condition is non-rectangular in most cases. It can be an arbitrary parallelogon.
It would be nice if the periods can be a matrix, it will make NearestNeighbors.jl more useful to condensed matter physicists.

I am not very familiar with the design pattern of this package, if someone feel the added code is not qualified according to your standard, please feel free to modify this PR. Thanks!

Example

julia> using Distances

julia> p = PeriodicEuclidean([10 0.0; 10.0 10.0])
PeriodicEuclidean{Matrix{Float64}}([10.0 0.0; 10.0 10.0])

julia> evaluate(p, [0.1, 0.2], [10.1, 10.3])
0.1000000000000012

UPDATE: somehow, the NearestNeighbors.jl does not work properly with this update. Still checking why it is so.
UPDATE 2: they redefined some functions in their own package... this is so wield.
https://github.com/KristofferC/NearestNeighbors.jl/blob/1de39f57fcf5e51ce51592e382f530e514a59952/src/evaluation.jl#L9
https://github.com/KristofferC/NearestNeighbors.jl/blob/1de39f57fcf5e51ce51592e382f530e514a59952/src/ball_tree.jl#L64
@KristofferC
UPDATE3: This issue can be fixed by this monkey patch (KristofferC/NearestNeighbors.jl#130). I tested it in my lattice package, it is a correct fix.

@GiggleLiu GiggleLiu changed the title non rectangular periodic non rectangular PeriodicEuclidean Dec 20, 2021
@GiggleLiu GiggleLiu changed the title non rectangular PeriodicEuclidean A generalized PeriodicEuclidean (allows specifying the periods as a parallelogon) Dec 20, 2021
src/metrics.jl Outdated Show resolved Hide resolved
Co-authored-by: Daniel Karrasch <[email protected]>
@GiggleLiu
Copy link
Author

GiggleLiu commented Jan 26, 2022

I notice that the distance computed in this way (shifting the parallelogon for 2^ndim times towards all directions) does not cover all cases (actually I found a counter-example). I need to do more research and will comment back later.

Note: So far, I haven't found any information useful. Maybe finding the shortest distance in non-rectangular periodic space is an open problem?

https://math.stackexchange.com/questions/1364594/distance-in-a-periodic-system

@GiggleLiu GiggleLiu changed the title A generalized PeriodicEuclidean (allows specifying the periods as a parallelogon) [WIP] A generalized PeriodicEuclidean (allows specifying the periods as a parallelogon) Jan 26, 2022
@GiggleLiu
Copy link
Author

Note:
The problem of finding the distance with periodic boundary condition is called the closest vector problem, it is known as NP-hard. However, for low-dimensional system, solving it regorously might be possible, check this paper:

https://arxiv.org/abs/1504.01995

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

Successfully merging this pull request may close these issues.

2 participants