diff options
author | Rémi Flamary <remi.flamary@gmail.com> | 2017-08-30 17:10:38 +0200 |
---|---|---|
committer | Rémi Flamary <remi.flamary@gmail.com> | 2017-08-30 17:10:38 +0200 |
commit | 3547344740ec16157fd65c7f27d4acd6add986a4 (patch) | |
tree | b8062a227c507aae055aa70c907115fab2ab1918 /examples | |
parent | 164dc24d7cdf61acd045f6b879ae2955b7dfcd18 (diff) |
exples +rst
Diffstat (limited to 'examples')
-rw-r--r-- | examples/plot_OT_1D.py | 17 | ||||
-rw-r--r-- | examples/plot_optim_OTreg.py | 21 |
2 files changed, 37 insertions, 1 deletions
diff --git a/examples/plot_OT_1D.py b/examples/plot_OT_1D.py index 0f3a26a..be6f5b3 100644 --- a/examples/plot_OT_1D.py +++ b/examples/plot_OT_1D.py @@ -15,6 +15,10 @@ import matplotlib.pylab as pl import ot from ot.datasets import get_1D_gauss as gauss +############################################################################## +# Generate data +############################################################################## + #%% parameters n = 100 # nb bins @@ -30,6 +34,11 @@ b = gauss(n, m=60, s=10) M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1))) M /= M.max() + +############################################################################## +# Plot distributions and loss matrix +############################################################################## + #%% plot the distributions pl.figure(1, figsize=(6.4, 3)) @@ -42,6 +51,10 @@ pl.legend() pl.figure(2, figsize=(5, 5)) ot.plot.plot1D_mat(a, b, M, 'Cost matrix M') +############################################################################## +# Solve EMD +############################################################################## + #%% EMD G0 = ot.emd(a, b, M) @@ -49,6 +62,10 @@ G0 = ot.emd(a, b, M) pl.figure(3, figsize=(5, 5)) ot.plot.plot1D_mat(a, b, G0, 'OT matrix G0') +############################################################################## +# Solve Sinkhorn +############################################################################## + #%% Sinkhorn lambd = 1e-3 diff --git a/examples/plot_optim_OTreg.py b/examples/plot_optim_OTreg.py index 276b250..d36b269 100644 --- a/examples/plot_optim_OTreg.py +++ b/examples/plot_optim_OTreg.py @@ -12,6 +12,10 @@ import matplotlib.pylab as pl import ot +############################################################################## +# Generate data +############################################################################## + #%% parameters n = 100 # nb bins @@ -27,6 +31,10 @@ b = ot.datasets.get_1D_gauss(n, m=60, s=10) M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1))) M /= M.max() +############################################################################## +# Solve EMD +############################################################################## + #%% EMD G0 = ot.emd(a, b, M) @@ -34,6 +42,10 @@ G0 = ot.emd(a, b, M) pl.figure(3, figsize=(5, 5)) ot.plot.plot1D_mat(a, b, G0, 'OT matrix G0') +############################################################################## +# Solve EMD with Frobenius norm regularization +############################################################################## + #%% Example with Frobenius norm regularization @@ -52,6 +64,10 @@ Gl2 = ot.optim.cg(a, b, M, reg, f, df, verbose=True) pl.figure(3) ot.plot.plot1D_mat(a, b, Gl2, 'OT matrix Frob. reg') +############################################################################## +# Solve EMD with entropic regularization +############################################################################## + #%% Example with entropic regularization @@ -70,8 +86,11 @@ Ge = ot.optim.cg(a, b, M, reg, f, df, verbose=True) pl.figure(4, figsize=(5, 5)) ot.plot.plot1D_mat(a, b, Ge, 'OT matrix Entrop. reg') -#%% Example with Frobenius norm + entropic regularization with gcg +############################################################################## +# Solve EMD with Frobenius norm + entropic regularization +############################################################################## +#%% Example with Frobenius norm + entropic regularization with gcg def f(G): return 0.5 * np.sum(G**2) |