summaryrefslogtreecommitdiff
path: root/docs/source/auto_examples/plot_optim_OTreg.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/source/auto_examples/plot_optim_OTreg.rst')
-rw-r--r--docs/source/auto_examples/plot_optim_OTreg.rst615
1 files changed, 344 insertions, 271 deletions
diff --git a/docs/source/auto_examples/plot_optim_OTreg.rst b/docs/source/auto_examples/plot_optim_OTreg.rst
index 70cd26c..480149a 100644
--- a/docs/source/auto_examples/plot_optim_OTreg.rst
+++ b/docs/source/auto_examples/plot_optim_OTreg.rst
@@ -7,28 +7,126 @@
Regularized OT with generic solver
==================================
+Illustrates the use of the generic solver for regularized OT with
+user-designed regularization term. It uses Conditional gradient as in [6] and
+generalized Conditional Gradient as proposed in [5][7].
+[5] N. Courty; R. Flamary; D. Tuia; A. Rakotomamonjy, Optimal Transport for
+Domain Adaptation, in IEEE Transactions on Pattern Analysis and Machine
+Intelligence , vol.PP, no.99, pp.1-1.
+[6] Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014).
+Regularized discrete optimal transport. SIAM Journal on Imaging Sciences,
+7(3), 1853-1882.
+[7] Rakotomamonjy, A., Flamary, R., & Courty, N. (2015). Generalized
+conditional gradient: analysis of convergence and applications.
+arXiv preprint arXiv:1510.06567.
-.. rst-class:: sphx-glr-horizontal
- *
- .. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_003.png
- :scale: 47
- *
- .. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_004.png
- :scale: 47
+.. code-block:: python
+
+
+ import numpy as np
+ import matplotlib.pylab as pl
+ import ot
+
+
+
+
+
+
+
+
+Generate data
+-------------
+
+
+
+.. code-block:: python
+
+
+ #%% parameters
+
+ n = 100 # nb bins
+
+ # bin positions
+ x = np.arange(n, dtype=np.float64)
+
+ # Gaussian distributions
+ a = ot.datasets.get_1D_gauss(n, m=20, s=5) # m= mean, s= std
+ b = ot.datasets.get_1D_gauss(n, m=60, s=10)
+
+ # loss matrix
+ M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))
+ M /= M.max()
+
+
+
+
+
+
+
+Solve EMD
+---------
+
+
+
+.. code-block:: python
+
+
+ #%% EMD
+
+ G0 = ot.emd(a, b, M)
+
+ pl.figure(3, figsize=(5, 5))
+ ot.plot.plot1D_mat(a, b, G0, 'OT matrix G0')
+
+
+
+
+.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_003.png
+ :align: center
+
+
+
+
+Solve EMD with Frobenius norm regularization
+--------------------------------------------
+
+
+
+.. code-block:: python
+
+
+ #%% Example with Frobenius norm regularization
+
+
+ def f(G):
+ return 0.5 * np.sum(G**2)
+
+
+ def df(G):
+ return G
+
+
+ reg = 1e-1
+
+ 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')
+
+
- *
- .. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_005.png
- :scale: 47
+.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_004.png
+ :align: center
.. rst-class:: sphx-glr-script-out
@@ -258,312 +356,287 @@ Regularized OT with generic solver
It. |Loss |Delta loss
--------------------------------
200|1.663543e-01|-8.737134e-08
+
+
+Solve EMD with entropic regularization
+--------------------------------------
+
+
+
+.. code-block:: python
+
+
+ #%% Example with entropic regularization
+
+
+ def f(G):
+ return np.sum(G * np.log(G))
+
+
+ def df(G):
+ return np.log(G) + 1.
+
+
+ reg = 1e-3
+
+ 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')
+
+
+
+
+.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_006.png
+ :align: center
+
+
+.. rst-class:: sphx-glr-script-out
+
+ Out::
+
It. |Loss |Delta loss
--------------------------------
0|1.692289e-01|0.000000e+00
1|1.617643e-01|-4.614437e-02
- 2|1.612546e-01|-3.161037e-03
- 3|1.611040e-01|-9.349544e-04
- 4|1.610346e-01|-4.310179e-04
- 5|1.610072e-01|-1.701719e-04
- 6|1.609947e-01|-7.759814e-05
- 7|1.609934e-01|-7.941439e-06
- 8|1.609841e-01|-5.797180e-05
- 9|1.609838e-01|-1.559407e-06
- 10|1.609685e-01|-9.530282e-05
- 11|1.609666e-01|-1.142129e-05
- 12|1.609541e-01|-7.799970e-05
- 13|1.609496e-01|-2.780416e-05
- 14|1.609385e-01|-6.887105e-05
- 15|1.609334e-01|-3.174241e-05
- 16|1.609231e-01|-6.420777e-05
- 17|1.609115e-01|-7.189949e-05
- 18|1.608815e-01|-1.865331e-04
- 19|1.608799e-01|-1.013039e-05
+ 2|1.612639e-01|-3.102965e-03
+ 3|1.611291e-01|-8.371098e-04
+ 4|1.610468e-01|-5.110558e-04
+ 5|1.610198e-01|-1.672927e-04
+ 6|1.610130e-01|-4.232417e-05
+ 7|1.610090e-01|-2.513455e-05
+ 8|1.610002e-01|-5.443507e-05
+ 9|1.609996e-01|-3.657071e-06
+ 10|1.609948e-01|-2.998735e-05
+ 11|1.609695e-01|-1.569217e-04
+ 12|1.609533e-01|-1.010779e-04
+ 13|1.609520e-01|-8.043897e-06
+ 14|1.609465e-01|-3.415246e-05
+ 15|1.609386e-01|-4.898605e-05
+ 16|1.609324e-01|-3.837052e-05
+ 17|1.609298e-01|-1.617826e-05
+ 18|1.609184e-01|-7.080015e-05
+ 19|1.609083e-01|-6.273206e-05
It. |Loss |Delta loss
--------------------------------
- 20|1.608695e-01|-6.468606e-05
- 21|1.608686e-01|-5.738419e-06
- 22|1.608661e-01|-1.495923e-05
- 23|1.608657e-01|-2.784611e-06
- 24|1.608633e-01|-1.512408e-05
- 25|1.608624e-01|-5.397916e-06
- 26|1.608617e-01|-4.115218e-06
- 27|1.608561e-01|-3.503396e-05
- 28|1.608479e-01|-5.098773e-05
- 29|1.608452e-01|-1.659203e-05
- 30|1.608399e-01|-3.298319e-05
- 31|1.608330e-01|-4.302183e-05
- 32|1.608310e-01|-1.273465e-05
- 33|1.608280e-01|-1.827713e-05
- 34|1.608231e-01|-3.039842e-05
- 35|1.608212e-01|-1.229256e-05
- 36|1.608200e-01|-6.900556e-06
- 37|1.608159e-01|-2.554039e-05
- 38|1.608103e-01|-3.521137e-05
- 39|1.608058e-01|-2.795180e-05
+ 20|1.608988e-01|-5.940805e-05
+ 21|1.608853e-01|-8.380030e-05
+ 22|1.608844e-01|-5.185045e-06
+ 23|1.608824e-01|-1.279113e-05
+ 24|1.608819e-01|-3.156821e-06
+ 25|1.608783e-01|-2.205746e-05
+ 26|1.608764e-01|-1.189894e-05
+ 27|1.608755e-01|-5.474607e-06
+ 28|1.608737e-01|-1.144227e-05
+ 29|1.608676e-01|-3.775335e-05
+ 30|1.608638e-01|-2.348020e-05
+ 31|1.608627e-01|-6.863136e-06
+ 32|1.608529e-01|-6.110230e-05
+ 33|1.608487e-01|-2.641106e-05
+ 34|1.608409e-01|-4.823638e-05
+ 35|1.608373e-01|-2.256641e-05
+ 36|1.608338e-01|-2.132444e-05
+ 37|1.608310e-01|-1.786649e-05
+ 38|1.608260e-01|-3.103848e-05
+ 39|1.608206e-01|-3.321265e-05
It. |Loss |Delta loss
--------------------------------
- 40|1.608040e-01|-1.119118e-05
- 41|1.608027e-01|-8.193369e-06
- 42|1.607994e-01|-2.026719e-05
- 43|1.607985e-01|-5.819902e-06
- 44|1.607978e-01|-4.048170e-06
- 45|1.607978e-01|-3.007470e-07
- 46|1.607950e-01|-1.705375e-05
- 47|1.607927e-01|-1.430186e-05
- 48|1.607925e-01|-1.166526e-06
- 49|1.607911e-01|-9.069406e-06
- 50|1.607910e-01|-3.804209e-07
- 51|1.607910e-01|-5.942399e-08
- 52|1.607910e-01|-2.321380e-07
- 53|1.607907e-01|-1.877655e-06
- 54|1.607906e-01|-2.940224e-07
- 55|1.607877e-01|-1.814208e-05
- 56|1.607841e-01|-2.236496e-05
- 57|1.607810e-01|-1.951355e-05
- 58|1.607804e-01|-3.578228e-06
- 59|1.607789e-01|-9.442277e-06
+ 40|1.608201e-01|-3.054747e-06
+ 41|1.608195e-01|-4.198335e-06
+ 42|1.608193e-01|-8.458736e-07
+ 43|1.608159e-01|-2.153759e-05
+ 44|1.608115e-01|-2.738314e-05
+ 45|1.608108e-01|-3.960032e-06
+ 46|1.608081e-01|-1.675447e-05
+ 47|1.608072e-01|-5.976340e-06
+ 48|1.608046e-01|-1.604130e-05
+ 49|1.608020e-01|-1.617036e-05
+ 50|1.608014e-01|-3.957795e-06
+ 51|1.608011e-01|-1.292411e-06
+ 52|1.607998e-01|-8.431795e-06
+ 53|1.607964e-01|-2.127054e-05
+ 54|1.607947e-01|-1.021878e-05
+ 55|1.607947e-01|-3.560621e-07
+ 56|1.607900e-01|-2.929781e-05
+ 57|1.607890e-01|-5.740229e-06
+ 58|1.607858e-01|-2.039550e-05
+ 59|1.607836e-01|-1.319545e-05
It. |Loss |Delta loss
--------------------------------
- 60|1.607779e-01|-5.997371e-06
- 61|1.607754e-01|-1.564408e-05
- 62|1.607742e-01|-7.693285e-06
- 63|1.607727e-01|-9.030547e-06
- 64|1.607719e-01|-5.103894e-06
- 65|1.607693e-01|-1.605420e-05
- 66|1.607676e-01|-1.047837e-05
- 67|1.607675e-01|-6.026848e-07
- 68|1.607655e-01|-1.240216e-05
- 69|1.607632e-01|-1.434674e-05
- 70|1.607618e-01|-8.829808e-06
- 71|1.607606e-01|-7.581824e-06
- 72|1.607590e-01|-1.009457e-05
- 73|1.607586e-01|-2.222963e-06
- 74|1.607577e-01|-5.564775e-06
- 75|1.607574e-01|-1.932763e-06
- 76|1.607573e-01|-8.148685e-07
- 77|1.607554e-01|-1.187660e-05
- 78|1.607546e-01|-4.557651e-06
- 79|1.607537e-01|-5.911902e-06
+ 60|1.607826e-01|-6.378947e-06
+ 61|1.607808e-01|-1.145102e-05
+ 62|1.607776e-01|-1.941743e-05
+ 63|1.607743e-01|-2.087422e-05
+ 64|1.607741e-01|-1.310249e-06
+ 65|1.607738e-01|-1.682752e-06
+ 66|1.607691e-01|-2.913936e-05
+ 67|1.607671e-01|-1.288855e-05
+ 68|1.607654e-01|-1.002448e-05
+ 69|1.607641e-01|-8.209492e-06
+ 70|1.607632e-01|-5.588467e-06
+ 71|1.607619e-01|-8.050388e-06
+ 72|1.607618e-01|-9.417493e-07
+ 73|1.607598e-01|-1.210509e-05
+ 74|1.607591e-01|-4.392914e-06
+ 75|1.607579e-01|-7.759587e-06
+ 76|1.607574e-01|-2.760280e-06
+ 77|1.607556e-01|-1.146469e-05
+ 78|1.607550e-01|-3.689456e-06
+ 79|1.607550e-01|-4.065631e-08
It. |Loss |Delta loss
--------------------------------
- 80|1.607529e-01|-4.710187e-06
- 81|1.607528e-01|-8.866080e-07
- 82|1.607522e-01|-3.620627e-06
- 83|1.607514e-01|-5.091281e-06
- 84|1.607498e-01|-9.932095e-06
- 85|1.607487e-01|-6.852804e-06
- 86|1.607478e-01|-5.373596e-06
- 87|1.607473e-01|-3.287295e-06
- 88|1.607470e-01|-1.666655e-06
- 89|1.607469e-01|-5.293790e-07
- 90|1.607466e-01|-2.051914e-06
- 91|1.607456e-01|-6.422797e-06
- 92|1.607456e-01|-1.110433e-07
- 93|1.607451e-01|-2.803849e-06
- 94|1.607451e-01|-2.608066e-07
- 95|1.607441e-01|-6.290352e-06
- 96|1.607429e-01|-7.298455e-06
- 97|1.607429e-01|-8.969905e-09
- 98|1.607427e-01|-7.923968e-07
- 99|1.607427e-01|-3.519286e-07
+ 80|1.607539e-01|-6.555681e-06
+ 81|1.607528e-01|-7.177470e-06
+ 82|1.607527e-01|-5.306068e-07
+ 83|1.607514e-01|-7.816045e-06
+ 84|1.607511e-01|-2.301970e-06
+ 85|1.607504e-01|-4.281072e-06
+ 86|1.607503e-01|-7.821886e-07
+ 87|1.607480e-01|-1.403013e-05
+ 88|1.607480e-01|-1.169298e-08
+ 89|1.607473e-01|-4.235982e-06
+ 90|1.607470e-01|-1.717105e-06
+ 91|1.607470e-01|-6.148402e-09
+ 92|1.607462e-01|-5.396481e-06
+ 93|1.607461e-01|-5.194954e-07
+ 94|1.607450e-01|-6.525707e-06
+ 95|1.607442e-01|-5.332060e-06
+ 96|1.607439e-01|-1.682093e-06
+ 97|1.607437e-01|-1.594796e-06
+ 98|1.607435e-01|-7.923812e-07
+ 99|1.607420e-01|-9.738552e-06
It. |Loss |Delta loss
--------------------------------
- 100|1.607426e-01|-3.563804e-07
- 101|1.607410e-01|-1.004042e-05
- 102|1.607410e-01|-2.124801e-07
- 103|1.607398e-01|-7.556935e-06
- 104|1.607398e-01|-7.606853e-08
- 105|1.607385e-01|-8.058684e-06
- 106|1.607383e-01|-7.393061e-07
- 107|1.607381e-01|-1.504958e-06
- 108|1.607377e-01|-2.508807e-06
- 109|1.607371e-01|-4.004631e-06
- 110|1.607365e-01|-3.580156e-06
- 111|1.607364e-01|-2.563573e-07
- 112|1.607354e-01|-6.390137e-06
- 113|1.607348e-01|-4.119553e-06
- 114|1.607339e-01|-5.299475e-06
- 115|1.607335e-01|-2.316767e-06
- 116|1.607330e-01|-3.444737e-06
- 117|1.607324e-01|-3.467980e-06
- 118|1.607320e-01|-2.374632e-06
- 119|1.607319e-01|-7.978255e-07
+ 100|1.607419e-01|-1.022448e-07
+ 101|1.607419e-01|-4.865999e-07
+ 102|1.607418e-01|-7.092012e-07
+ 103|1.607408e-01|-5.861815e-06
+ 104|1.607402e-01|-3.953266e-06
+ 105|1.607395e-01|-3.969572e-06
+ 106|1.607390e-01|-3.612075e-06
+ 107|1.607377e-01|-7.683735e-06
+ 108|1.607365e-01|-7.777599e-06
+ 109|1.607364e-01|-2.335096e-07
+ 110|1.607364e-01|-4.562036e-07
+ 111|1.607360e-01|-2.089538e-06
+ 112|1.607356e-01|-2.755355e-06
+ 113|1.607349e-01|-4.501960e-06
+ 114|1.607347e-01|-1.160544e-06
+ 115|1.607346e-01|-6.289450e-07
+ 116|1.607345e-01|-2.092146e-07
+ 117|1.607336e-01|-5.990866e-06
+ 118|1.607330e-01|-3.348498e-06
+ 119|1.607328e-01|-1.256222e-06
It. |Loss |Delta loss
--------------------------------
- 120|1.607312e-01|-4.221434e-06
- 121|1.607310e-01|-1.324597e-06
- 122|1.607304e-01|-3.650359e-06
- 123|1.607298e-01|-3.732712e-06
- 124|1.607295e-01|-1.994082e-06
- 125|1.607289e-01|-3.954139e-06
- 126|1.607286e-01|-1.532372e-06
- 127|1.607286e-01|-1.167223e-07
- 128|1.607283e-01|-2.157376e-06
- 129|1.607279e-01|-2.253077e-06
- 130|1.607274e-01|-3.301532e-06
- 131|1.607269e-01|-2.650754e-06
- 132|1.607264e-01|-3.595551e-06
- 133|1.607262e-01|-1.159425e-06
- 134|1.607258e-01|-2.512411e-06
- 135|1.607255e-01|-1.998792e-06
- 136|1.607251e-01|-2.486536e-06
- 137|1.607246e-01|-2.782996e-06
- 138|1.607246e-01|-2.922470e-07
- 139|1.607242e-01|-2.071131e-06
+ 120|1.607320e-01|-5.418353e-06
+ 121|1.607318e-01|-8.296189e-07
+ 122|1.607311e-01|-4.381608e-06
+ 123|1.607310e-01|-8.913901e-07
+ 124|1.607309e-01|-3.808821e-07
+ 125|1.607302e-01|-4.608994e-06
+ 126|1.607294e-01|-5.063777e-06
+ 127|1.607290e-01|-2.532835e-06
+ 128|1.607285e-01|-2.870049e-06
+ 129|1.607284e-01|-4.892812e-07
+ 130|1.607281e-01|-1.760452e-06
+ 131|1.607279e-01|-1.727139e-06
+ 132|1.607275e-01|-2.220706e-06
+ 133|1.607271e-01|-2.516930e-06
+ 134|1.607269e-01|-1.201434e-06
+ 135|1.607269e-01|-2.183459e-09
+ 136|1.607262e-01|-4.223011e-06
+ 137|1.607258e-01|-2.530202e-06
+ 138|1.607258e-01|-1.857260e-07
+ 139|1.607256e-01|-1.401957e-06
It. |Loss |Delta loss
--------------------------------
- 140|1.607237e-01|-3.154193e-06
- 141|1.607235e-01|-1.194962e-06
- 142|1.607232e-01|-2.035251e-06
- 143|1.607232e-01|-6.027855e-08
- 144|1.607229e-01|-1.555696e-06
- 145|1.607228e-01|-1.081740e-06
- 146|1.607225e-01|-1.881070e-06
- 147|1.607224e-01|-4.100096e-07
- 148|1.607223e-01|-7.785200e-07
- 149|1.607222e-01|-2.094072e-07
- 150|1.607220e-01|-1.440814e-06
- 151|1.607217e-01|-1.997794e-06
- 152|1.607214e-01|-2.011022e-06
- 153|1.607212e-01|-8.808854e-07
- 154|1.607211e-01|-7.245877e-07
- 155|1.607207e-01|-2.217159e-06
- 156|1.607201e-01|-3.817891e-06
- 157|1.607200e-01|-7.409600e-07
- 158|1.607198e-01|-1.497698e-06
- 159|1.607195e-01|-1.729666e-06
+ 140|1.607250e-01|-3.242751e-06
+ 141|1.607247e-01|-2.308071e-06
+ 142|1.607247e-01|-4.730700e-08
+ 143|1.607246e-01|-4.240229e-07
+ 144|1.607242e-01|-2.484810e-06
+ 145|1.607238e-01|-2.539206e-06
+ 146|1.607234e-01|-2.535574e-06
+ 147|1.607231e-01|-1.954802e-06
+ 148|1.607228e-01|-1.765447e-06
+ 149|1.607228e-01|-1.620007e-08
+ 150|1.607222e-01|-3.615783e-06
+ 151|1.607222e-01|-8.668516e-08
+ 152|1.607215e-01|-4.000673e-06
+ 153|1.607213e-01|-1.774103e-06
+ 154|1.607213e-01|-6.328834e-09
+ 155|1.607209e-01|-2.418783e-06
+ 156|1.607208e-01|-2.848492e-07
+ 157|1.607207e-01|-8.836043e-07
+ 158|1.607205e-01|-1.192836e-06
+ 159|1.607202e-01|-1.638022e-06
It. |Loss |Delta loss
--------------------------------
- 160|1.607195e-01|-2.115187e-07
- 161|1.607192e-01|-1.643727e-06
- 162|1.607192e-01|-1.712969e-07
- 163|1.607189e-01|-1.805877e-06
- 164|1.607189e-01|-1.209827e-07
- 165|1.607185e-01|-2.060002e-06
- 166|1.607182e-01|-1.961341e-06
- 167|1.607181e-01|-1.020366e-06
- 168|1.607179e-01|-9.760982e-07
- 169|1.607178e-01|-7.219236e-07
- 170|1.607175e-01|-1.837718e-06
- 171|1.607174e-01|-3.337578e-07
- 172|1.607173e-01|-5.298564e-07
- 173|1.607173e-01|-6.864278e-08
- 174|1.607173e-01|-2.008419e-07
- 175|1.607171e-01|-1.375630e-06
- 176|1.607168e-01|-1.911257e-06
- 177|1.607167e-01|-2.709815e-07
- 178|1.607167e-01|-1.390953e-07
- 179|1.607165e-01|-1.199675e-06
- It. |Loss |Delta loss
- --------------------------------
- 180|1.607165e-01|-1.457259e-07
- 181|1.607163e-01|-1.049154e-06
- 182|1.607163e-01|-2.753577e-09
- 183|1.607163e-01|-6.972814e-09
- 184|1.607161e-01|-1.552100e-06
- 185|1.607159e-01|-1.068596e-06
- 186|1.607157e-01|-1.247724e-06
- 187|1.607155e-01|-1.158164e-06
- 188|1.607155e-01|-2.616199e-07
- 189|1.607154e-01|-3.595874e-07
- 190|1.607154e-01|-5.334527e-08
- 191|1.607153e-01|-3.452744e-07
- 192|1.607153e-01|-1.239593e-07
- 193|1.607152e-01|-8.184984e-07
- 194|1.607150e-01|-1.316308e-06
- 195|1.607150e-01|-7.100882e-09
- 196|1.607148e-01|-1.393958e-06
- 197|1.607146e-01|-1.242735e-06
- 198|1.607144e-01|-1.123993e-06
- 199|1.607143e-01|-3.512071e-07
- It. |Loss |Delta loss
- --------------------------------
- 200|1.607143e-01|-2.151971e-10
- It. |Loss |Delta loss
- --------------------------------
- 0|1.693084e-01|0.000000e+00
- 1|1.610121e-01|-5.152589e-02
- 2|1.609378e-01|-4.622297e-04
- 3|1.609284e-01|-5.830043e-05
- 4|1.609284e-01|-1.111580e-12
-
+ 160|1.607202e-01|-3.670914e-08
+ 161|1.607197e-01|-3.153709e-06
+ 162|1.607197e-01|-2.419565e-09
+ 163|1.607194e-01|-2.136882e-06
+ 164|1.607194e-01|-1.173754e-09
+ 165|1.607192e-01|-8.169238e-07
+ 166|1.607191e-01|-9.218755e-07
+ 167|1.607189e-01|-9.459255e-07
+ 168|1.607187e-01|-1.294835e-06
+ 169|1.607186e-01|-5.797668e-07
+ 170|1.607186e-01|-4.706272e-08
+ 171|1.607183e-01|-1.753383e-06
+ 172|1.607183e-01|-1.681573e-07
+ 173|1.607183e-01|-2.563971e-10
+Solve EMD with Frobenius norm + entropic regularization
+-------------------------------------------------------
-|
.. code-block:: python
- import numpy as np
- import matplotlib.pylab as pl
- import ot
-
-
-
- #%% parameters
-
- n=100 # nb bins
-
- # bin positions
- x=np.arange(n,dtype=np.float64)
-
- # Gaussian distributions
- a=ot.datasets.get_1D_gauss(n,m=20,s=5) # m= mean, s= std
- b=ot.datasets.get_1D_gauss(n,m=60,s=10)
-
- # loss matrix
- M=ot.dist(x.reshape((n,1)),x.reshape((n,1)))
- M/=M.max()
-
- #%% EMD
+ #%% Example with Frobenius norm + entropic regularization with gcg
- G0=ot.emd(a,b,M)
- pl.figure(3)
- ot.plot.plot1D_mat(a,b,G0,'OT matrix G0')
+ def f(G):
+ return 0.5 * np.sum(G**2)
- #%% Example with Frobenius norm regularization
- def f(G): return 0.5*np.sum(G**2)
- def df(G): return G
+ def df(G):
+ return G
- reg=1e-1
- Gl2=ot.optim.cg(a,b,M,reg,f,df,verbose=True)
+ reg1 = 1e-3
+ reg2 = 1e-1
- pl.figure(3)
- ot.plot.plot1D_mat(a,b,Gl2,'OT matrix Frob. reg')
+ Gel2 = ot.optim.gcg(a, b, M, reg1, reg2, f, df, verbose=True)
- #%% Example with entropic regularization
+ pl.figure(5, figsize=(5, 5))
+ ot.plot.plot1D_mat(a, b, Gel2, 'OT entropic + matrix Frob. reg')
+ pl.show()
- def f(G): return np.sum(G*np.log(G))
- def df(G): return np.log(G)+1
- reg=1e-3
- Ge=ot.optim.cg(a,b,M,reg,f,df,verbose=True)
+.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_008.png
+ :align: center
- pl.figure(4)
- ot.plot.plot1D_mat(a,b,Ge,'OT matrix Entrop. reg')
- #%% Example with Frobenius norm + entropic regularization with gcg
+.. rst-class:: sphx-glr-script-out
- def f(G): return 0.5*np.sum(G**2)
- def df(G): return G
+ Out::
- reg1=1e-3
- reg2=1e-1
+ It. |Loss |Delta loss
+ --------------------------------
+ 0|1.693084e-01|0.000000e+00
+ 1|1.610121e-01|-5.152589e-02
+ 2|1.609378e-01|-4.622297e-04
+ 3|1.609284e-01|-5.830043e-05
+ 4|1.609284e-01|-1.111407e-12
- Gel2=ot.optim.gcg(a,b,M,reg1,reg2,f,df,verbose=True)
- pl.figure(5)
- ot.plot.plot1D_mat(a,b,Gel2,'OT entropic + matrix Frob. reg')
- pl.show()
-**Total running time of the script:** ( 0 minutes 2.319 seconds)
+**Total running time of the script:** ( 0 minutes 2.800 seconds)