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

Add p-Wasserstein distance #158

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

Conversation

Sh4pe
Copy link

@Sh4pe Sh4pe commented Feb 16, 2020

This PR adds the p-Wasserstein distance (a.k.a. Earth Mover Distance). Calculating the p-Wasserstein entails solving a linear program. This is done using JuMP.jl with the Cbc.jl optimizer.

Fixes #37

@johnnychen94
Copy link
Contributor

johnnychen94 commented Feb 16, 2020

I would say the main issue of introducing this PR is its huge dependency. You know, at present this package is quite small

julia> @time using Distances
  0.078969 seconds (52.74 k allocations: 3.509 MiB)

Probably this package isn't the best place to put the codes to

@Sh4pe
Copy link
Author

Sh4pe commented Feb 17, 2020

I would say the main issue of introducing this PR is its huge dependency. You know, at present this package is quite small

julia> @time using Distances
  0.078969 seconds (52.74 k allocations: 3.509 MiB)

Probably this package isn't the best place to put the codes to

Yes, this PR introduces a lot of dependencies. But since you need to solve a (possibly large) linear program in order to calculate the Wasserstein distance, you need to introduce at least some dependencies (granted that you don't want to re-implement a linear program solver on your own)...

So what do you think would be a better place for the code?

And what do others think?

@Sh4pe
Copy link
Author

Sh4pe commented Feb 23, 2020

Another implementation (though solved quite differently) is in #159. Don't really know about the implementation there though.

@devmotion
Copy link
Member

FYI: https://github.com/JuliaOptimalTransport/OptimalTransport.jl contains specialized implementations for the 1D solution, both for discrete and continuous distributions, but also a pure Julia implementation for solving the optimal transport problem with discrete measures in arbitrary dimensions (and soon there will be also a specialized implementation for multivariate normal distributions). We just added wasserstein as an interface for computing the p-Wasserstein distance.

@nalimilan
Copy link
Member

Adding JuMP as a dependency to Distances.jl would certainly be a problem. As noted at #159 (comment), the 1D Wasserstein distance has a closed form solution, and Distances.jl only includes 1D distances, so we should use that.

@devmotion
Copy link
Member

We started splitting OptimalTransport.jl into smaller subpackages, the Wasserstein distances, based on MOI in the general case and including special cases as 1D and e.g. Gaussian distributions, are moved to https://github.com/JuliaOptimalTransport/ExactOptimalTransport.jl.

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.

Add Earth Mover's Distance/Wasserstein metric
4 participants