diff options
Diffstat (limited to 'examples/plot_OT_2D_samples.py')
-rw-r--r-- | examples/plot_OT_2D_samples.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/examples/plot_OT_2D_samples.py b/examples/plot_OT_2D_samples.py index 023e645..9818ec5 100644 --- a/examples/plot_OT_2D_samples.py +++ b/examples/plot_OT_2D_samples.py @@ -4,6 +4,9 @@ 2D Optimal transport between empirical distributions ==================================================== +Illustration of 2D optimal transport between discributions that are weighted +sum of diracs. The OT matrix is plotted with the samples. + """ # Author: Remi Flamary <remi.flamary@unice.fr> @@ -14,6 +17,10 @@ import numpy as np import matplotlib.pylab as pl import ot +############################################################################## +# Generate data +# ------------- + #%% parameters and data generation n = 50 # nb samples @@ -33,6 +40,10 @@ a, b = np.ones((n,)) / n, np.ones((n,)) / n # uniform distribution on samples M = ot.dist(xs, xt) M /= M.max() +############################################################################## +# Plot data +# --------- + #%% plot samples pl.figure(1) @@ -45,6 +56,9 @@ pl.figure(2) pl.imshow(M, interpolation='nearest') pl.title('Cost matrix M') +############################################################################## +# Compute EMD +# ----------- #%% EMD @@ -62,10 +76,14 @@ pl.legend(loc=0) pl.title('OT matrix with samples') +############################################################################## +# Compute Sinkhorn +# ---------------- + #%% sinkhorn # reg term -lambd = 5e-4 +lambd = 1e-3 Gs = ot.sinkhorn(a, b, M, lambd) |