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.

Home Page:https://www.fabriziomusacchio.com/blog/2023-07-22-wasserstein_distance

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wasserstein metric

This repository contains the code for the following blog posts:

For further details, please refer to these posts.

For reproducibility:

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

The according distance (cost) matrix:

img

And the resulting optimal transport plan:

img

The corresponding Wasserstein distance is $W_1 = \sim0.1658$.

Comparing Wasserstein distance, sliced Wasserstein distance (SWD), and L2 norm:

img img

Comparing various probability distance metrics:

img img

About

This repository contains the code for some blog posts on the Wasserstein metric. For further details, please refer to the corresponding posts.

https://www.fabriziomusacchio.com/blog/2023-07-22-wasserstein_distance


Languages

Language:Python 100.0%