diff options
author | RĂ©mi Flamary <remi.flamary@gmail.com> | 2017-09-15 14:54:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-15 14:54:21 +0200 |
commit | 81b2796226f3abde29fc024752728444da77509a (patch) | |
tree | c52cec3c38552f9f8c15361758aa9a80c30c3ef3 /examples/plot_OT_2D_samples.py | |
parent | e70d5420204db78691af2d0fbe04cc3d4416a8f4 (diff) | |
parent | 7fea2cd3e8ad29bf3fa442d7642bae124ee2bab0 (diff) |
Merge pull request #27 from rflamary/autonb
auto notebooks + release update (fixes #16)
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) |