Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fabriziomusacchio/wasserstein_distance_demo
This repository contains the code for some blog posts on the Wasserstein metric. For further details, please refer to the corresponding posts.
https://github.com/fabriziomusacchio/wasserstein_distance_demo
optimal-transport python wasserstein-distance
Last synced: 1 day ago
JSON representation
This repository contains the code for some blog posts on the Wasserstein metric. For further details, please refer to the corresponding posts.
- Host: GitHub
- URL: https://github.com/fabriziomusacchio/wasserstein_distance_demo
- Owner: FabrizioMusacchio
- Created: 2023-07-24T08:21:12.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-28T10:36:43.000Z (over 1 year ago)
- Last Synced: 2023-07-28T11:37:29.298Z (over 1 year ago)
- Topics: optimal-transport, python, wasserstein-distance
- Language: Python
- Homepage: https://www.fabriziomusacchio.com/blog/2023-07-22-wasserstein_distance
- Size: 22.8 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Wasserstein metric
This repository contains the code for the following blog posts:
* [Wasserstein distance and optimal transport](https://www.fabriziomusacchio.com/blog/2023-07-22-wasserstein_distance)
* [Wasserstein distance via entropy regularization (Sinkhorn algorithm)](https://www.fabriziomusacchio.com/blog/2023-07-23-wasserstein_distance_skinhorn)
* [Approximating the Wasserstein distance with cumulative distribution functions ](https://www.fabriziomusacchio.com/blog/2023-07-24-wasserstein_distance_cdf_approximation/)
* [Comparing Wasserstein distance, sliced Wasserstein distance, and L2 norm ](https://www.fabriziomusacchio.com/blog/2023-07-26-wasserstein_vs_l2_norm/)
* [Probability distance metrics in machine learning](https://www.fabriziomusacchio.com/blog/2023-07-28-probability_density_metrics/)For further details, please refer to these posts.
For reproducibility:
```powershell
conda create -n wasserstein -y python=3.9
conda activate wasserstein
conda install mamba -y
mamba install -y numpy matplotlib scikit-learn scipy pot ipykernel
pip install POT
```## Examples
Two example distributions (source and target):![img](images/wasserstein_distributions.png)
The according distance (cost) matrix:
![img](images/wasserstein_cost_matrix.png)
And the resulting optimal transport plan:
![img](images/wasserstein_optimal_transport_linear_programming.png)
The corresponding Wasserstein distance is $W_1 = \sim0.1658$.
Comparing Wasserstein distance, sliced Wasserstein distance (SWD), and L2 norm:
![img](images/wasserstein_l2_animation_m2.gif)
![img](images/wasserstein_l2_animation_s2.gif)Comparing various probability distance metrics:
![img](images/distance_evolution_discrete_mean2.gif)
![img](images/distance_evolution_discrete_std2.gif)