diff options
Diffstat (limited to 'docs/source/auto_examples')
-rw-r--r-- | docs/source/auto_examples/auto_examples_jupyter.zip | bin | 87492 -> 91095 bytes | |||
-rw-r--r-- | docs/source/auto_examples/auto_examples_python.zip | bin | 61260 -> 62950 bytes | |||
-rw-r--r-- | docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_003.png | bin | 18105 -> 16995 bytes | |||
-rw-r--r-- | docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_004.png | bin | 19189 -> 18588 bytes | |||
-rw-r--r-- | docs/source/auto_examples/plot_OT_1D.ipynb | 74 | ||||
-rw-r--r-- | docs/source/auto_examples/plot_OT_1D.py | 17 | ||||
-rw-r--r-- | docs/source/auto_examples/plot_OT_1D.rst | 143 | ||||
-rw-r--r-- | docs/source/auto_examples/plot_optim_OTreg.ipynb | 92 | ||||
-rw-r--r-- | docs/source/auto_examples/plot_optim_OTreg.py | 21 | ||||
-rw-r--r-- | docs/source/auto_examples/plot_optim_OTreg.rst | 233 |
10 files changed, 447 insertions, 133 deletions
diff --git a/docs/source/auto_examples/auto_examples_jupyter.zip b/docs/source/auto_examples/auto_examples_jupyter.zip Binary files differindex 3bb8ecf..92aa027 100644 --- a/docs/source/auto_examples/auto_examples_jupyter.zip +++ b/docs/source/auto_examples/auto_examples_jupyter.zip diff --git a/docs/source/auto_examples/auto_examples_python.zip b/docs/source/auto_examples/auto_examples_python.zip Binary files differindex 273c751..d9e26c4 100644 --- a/docs/source/auto_examples/auto_examples_python.zip +++ b/docs/source/auto_examples/auto_examples_python.zip diff --git a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_003.png b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_003.png Binary files differindex c9ed489..a75e649 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_003.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_003.png diff --git a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_004.png b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_004.png Binary files differindex 0af4542..7afdb53 100644 --- a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_004.png +++ b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_004.png diff --git a/docs/source/auto_examples/plot_OT_1D.ipynb b/docs/source/auto_examples/plot_OT_1D.ipynb index 7d3fdd1..97c593e 100644 --- a/docs/source/auto_examples/plot_OT_1D.ipynb +++ b/docs/source/auto_examples/plot_OT_1D.ipynb @@ -24,7 +24,79 @@ "execution_count": null, "cell_type": "code", "source": [ - "# Author: Remi Flamary <remi.flamary@unice.fr>\n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\nfrom ot.datasets import get_1D_gauss as gauss\n\n#%% parameters\n\nn = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na = gauss(n, m=20, s=5) # m= mean, s= std\nb = gauss(n, m=60, s=10)\n\n# loss matrix\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))\nM /= M.max()\n\n#%% plot the distributions\n\npl.figure(1, figsize=(6.4, 3))\npl.plot(x, a, 'b', label='Source distribution')\npl.plot(x, b, 'r', label='Target distribution')\npl.legend()\n\n#%% plot distributions and loss matrix\n\npl.figure(2, figsize=(5, 5))\not.plot.plot1D_mat(a, b, M, 'Cost matrix M')\n\n#%% EMD\n\nG0 = ot.emd(a, b, M)\n\npl.figure(3, figsize=(5, 5))\not.plot.plot1D_mat(a, b, G0, 'OT matrix G0')\n\n#%% Sinkhorn\n\nlambd = 1e-3\nGs = ot.sinkhorn(a, b, M, lambd, verbose=True)\n\npl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gs, 'OT matrix Sinkhorn')\n\npl.show()" + "# Author: Remi Flamary <remi.flamary@unice.fr>\n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\nfrom ot.datasets import get_1D_gauss as gauss" + ], + "outputs": [], + "metadata": { + "collapsed": false + } + }, + { + "source": [ + "Generate data\n#############################################################################\n\n" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "execution_count": null, + "cell_type": "code", + "source": [ + "#%% parameters\n\nn = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na = gauss(n, m=20, s=5) # m= mean, s= std\nb = gauss(n, m=60, s=10)\n\n# loss matrix\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))\nM /= M.max()" + ], + "outputs": [], + "metadata": { + "collapsed": false + } + }, + { + "source": [ + "Plot distributions and loss matrix\n#############################################################################\n\n" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "execution_count": null, + "cell_type": "code", + "source": [ + "#%% plot the distributions\n\npl.figure(1, figsize=(6.4, 3))\npl.plot(x, a, 'b', label='Source distribution')\npl.plot(x, b, 'r', label='Target distribution')\npl.legend()\n\n#%% plot distributions and loss matrix\n\npl.figure(2, figsize=(5, 5))\not.plot.plot1D_mat(a, b, M, 'Cost matrix M')" + ], + "outputs": [], + "metadata": { + "collapsed": false + } + }, + { + "source": [ + "Solve EMD \n#############################################################################\n\n" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "execution_count": null, + "cell_type": "code", + "source": [ + "#%% EMD\n\nG0 = ot.emd(a, b, M)\n\npl.figure(3, figsize=(5, 5))\not.plot.plot1D_mat(a, b, G0, 'OT matrix G0')" + ], + "outputs": [], + "metadata": { + "collapsed": false + } + }, + { + "source": [ + "Solve Sinkhorn\n#############################################################################\n\n" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "execution_count": null, + "cell_type": "code", + "source": [ + "#%% Sinkhorn\n\nlambd = 1e-3\nGs = ot.sinkhorn(a, b, M, lambd, verbose=True)\n\npl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gs, 'OT matrix Sinkhorn')\n\npl.show()" ], "outputs": [], "metadata": { diff --git a/docs/source/auto_examples/plot_OT_1D.py b/docs/source/auto_examples/plot_OT_1D.py index 0f3a26a..be6f5b3 100644 --- a/docs/source/auto_examples/plot_OT_1D.py +++ b/docs/source/auto_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/docs/source/auto_examples/plot_OT_1D.rst b/docs/source/auto_examples/plot_OT_1D.rst index a36e13c..252d387 100644 --- a/docs/source/auto_examples/plot_OT_1D.rst +++ b/docs/source/auto_examples/plot_OT_1D.rst @@ -10,68 +10,32 @@ - -.. rst-class:: sphx-glr-horizontal +.. code-block:: python - * + # Author: Remi Flamary <remi.flamary@unice.fr> + # + # License: MIT License - .. image:: /auto_examples/images/sphx_glr_plot_OT_1D_001.png - :scale: 47 + import numpy as np + import matplotlib.pylab as pl + import ot + from ot.datasets import get_1D_gauss as gauss - * - .. image:: /auto_examples/images/sphx_glr_plot_OT_1D_002.png - :scale: 47 - * - .. image:: /auto_examples/images/sphx_glr_plot_OT_1D_003.png - :scale: 47 - * - .. image:: /auto_examples/images/sphx_glr_plot_OT_1D_004.png - :scale: 47 +Generate data +############################################################################# -.. rst-class:: sphx-glr-script-out - - Out:: - - It. |Err - ------------------- - 0|8.187970e-02| - 10|3.460174e-02| - 20|6.633335e-03| - 30|9.797798e-04| - 40|1.389606e-04| - 50|1.959016e-05| - 60|2.759079e-06| - 70|3.885166e-07| - 80|5.470605e-08| - 90|7.702918e-09| - 100|1.084609e-09| - 110|1.527180e-10| - - - - -| .. code-block:: python - # Author: Remi Flamary <remi.flamary@unice.fr> - # - # License: MIT License - - import numpy as np - import matplotlib.pylab as pl - import ot - from ot.datasets import get_1D_gauss as gauss - #%% parameters n = 100 # nb bins @@ -87,6 +51,21 @@ M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1))) M /= M.max() + + + + + + + +Plot distributions and loss matrix +############################################################################# + + + +.. code-block:: python + + #%% plot the distributions pl.figure(1, figsize=(6.4, 3)) @@ -99,6 +78,33 @@ pl.figure(2, figsize=(5, 5)) ot.plot.plot1D_mat(a, b, M, 'Cost matrix M') + + + +.. rst-class:: sphx-glr-horizontal + + + * + + .. image:: /auto_examples/images/sphx_glr_plot_OT_1D_001.png + :scale: 47 + + * + + .. image:: /auto_examples/images/sphx_glr_plot_OT_1D_002.png + :scale: 47 + + + + +Solve EMD +############################################################################# + + + +.. code-block:: python + + #%% EMD G0 = ot.emd(a, b, M) @@ -106,6 +112,23 @@ pl.figure(3, figsize=(5, 5)) ot.plot.plot1D_mat(a, b, G0, 'OT matrix G0') + + + +.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_005.png + :align: center + + + + +Solve Sinkhorn +############################################################################# + + + +.. code-block:: python + + #%% Sinkhorn lambd = 1e-3 @@ -116,7 +139,33 @@ pl.show() -**Total running time of the script:** ( 0 minutes 1.050 seconds) + + +.. image:: /auto_examples/images/sphx_glr_plot_OT_1D_007.png + :align: center + + +.. rst-class:: sphx-glr-script-out + + Out:: + + It. |Err + ------------------- + 0|8.187970e-02| + 10|3.460174e-02| + 20|6.633335e-03| + 30|9.797798e-04| + 40|1.389606e-04| + 50|1.959016e-05| + 60|2.759079e-06| + 70|3.885166e-07| + 80|5.470605e-08| + 90|7.702918e-09| + 100|1.084609e-09| + 110|1.527180e-10| + + +**Total running time of the script:** ( 0 minutes 1.065 seconds) diff --git a/docs/source/auto_examples/plot_optim_OTreg.ipynb b/docs/source/auto_examples/plot_optim_OTreg.ipynb index 0cb6ef2..9d26e4d 100644 --- a/docs/source/auto_examples/plot_optim_OTreg.ipynb +++ b/docs/source/auto_examples/plot_optim_OTreg.ipynb @@ -24,7 +24,97 @@ "execution_count": null, "cell_type": "code", "source": [ - "import numpy as np\nimport matplotlib.pylab as pl\nimport ot\n\n\n#%% parameters\n\nn = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na = ot.datasets.get_1D_gauss(n, m=20, s=5) # m= mean, s= std\nb = ot.datasets.get_1D_gauss(n, m=60, s=10)\n\n# loss matrix\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))\nM /= M.max()\n\n#%% EMD\n\nG0 = ot.emd(a, b, M)\n\npl.figure(3, figsize=(5, 5))\not.plot.plot1D_mat(a, b, G0, 'OT matrix G0')\n\n#%% Example with Frobenius norm regularization\n\n\ndef f(G):\n return 0.5 * np.sum(G**2)\n\n\ndef df(G):\n return G\n\n\nreg = 1e-1\n\nGl2 = ot.optim.cg(a, b, M, reg, f, df, verbose=True)\n\npl.figure(3)\not.plot.plot1D_mat(a, b, Gl2, 'OT matrix Frob. reg')\n\n#%% Example with entropic regularization\n\n\ndef f(G):\n return np.sum(G * np.log(G))\n\n\ndef df(G):\n return np.log(G) + 1.\n\n\nreg = 1e-3\n\nGe = ot.optim.cg(a, b, M, reg, f, df, verbose=True)\n\npl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Ge, 'OT matrix Entrop. reg')\n\n#%% Example with Frobenius norm + entropic regularization with gcg\n\n\ndef f(G):\n return 0.5 * np.sum(G**2)\n\n\ndef df(G):\n return G\n\n\nreg1 = 1e-3\nreg2 = 1e-1\n\nGel2 = ot.optim.gcg(a, b, M, reg1, reg2, f, df, verbose=True)\n\npl.figure(5, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gel2, 'OT entropic + matrix Frob. reg')\npl.show()" + "import numpy as np\nimport matplotlib.pylab as pl\nimport ot" + ], + "outputs": [], + "metadata": { + "collapsed": false + } + }, + { + "source": [ + "Generate data \n#############################################################################\n\n" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "execution_count": null, + "cell_type": "code", + "source": [ + "#%% parameters\n\nn = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na = ot.datasets.get_1D_gauss(n, m=20, s=5) # m= mean, s= std\nb = ot.datasets.get_1D_gauss(n, m=60, s=10)\n\n# loss matrix\nM = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))\nM /= M.max()" + ], + "outputs": [], + "metadata": { + "collapsed": false + } + }, + { + "source": [ + "Solve EMD \n#############################################################################\n\n" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "execution_count": null, + "cell_type": "code", + "source": [ + "#%% EMD\n\nG0 = ot.emd(a, b, M)\n\npl.figure(3, figsize=(5, 5))\not.plot.plot1D_mat(a, b, G0, 'OT matrix G0')" + ], + "outputs": [], + "metadata": { + "collapsed": false + } + }, + { + "source": [ + "Solve EMD with Frobenius norm regularization\n#############################################################################\n\n" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "execution_count": null, + "cell_type": "code", + "source": [ + "#%% Example with Frobenius norm regularization\n\n\ndef f(G):\n return 0.5 * np.sum(G**2)\n\n\ndef df(G):\n return G\n\n\nreg = 1e-1\n\nGl2 = ot.optim.cg(a, b, M, reg, f, df, verbose=True)\n\npl.figure(3)\not.plot.plot1D_mat(a, b, Gl2, 'OT matrix Frob. reg')" + ], + "outputs": [], + "metadata": { + "collapsed": false + } + }, + { + "source": [ + "Solve EMD with entropic regularization\n#############################################################################\n\n" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "execution_count": null, + "cell_type": "code", + "source": [ + "#%% Example with entropic regularization\n\n\ndef f(G):\n return np.sum(G * np.log(G))\n\n\ndef df(G):\n return np.log(G) + 1.\n\n\nreg = 1e-3\n\nGe = ot.optim.cg(a, b, M, reg, f, df, verbose=True)\n\npl.figure(4, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Ge, 'OT matrix Entrop. reg')" + ], + "outputs": [], + "metadata": { + "collapsed": false + } + }, + { + "source": [ + "Solve EMD with Frobenius norm + entropic regularization\n#############################################################################\n\n" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "execution_count": null, + "cell_type": "code", + "source": [ + "#%% Example with Frobenius norm + entropic regularization with gcg\n\ndef f(G):\n return 0.5 * np.sum(G**2)\n\n\ndef df(G):\n return G\n\n\nreg1 = 1e-3\nreg2 = 1e-1\n\nGel2 = ot.optim.gcg(a, b, M, reg1, reg2, f, df, verbose=True)\n\npl.figure(5, figsize=(5, 5))\not.plot.plot1D_mat(a, b, Gel2, 'OT entropic + matrix Frob. reg')\npl.show()" ], "outputs": [], "metadata": { diff --git a/docs/source/auto_examples/plot_optim_OTreg.py b/docs/source/auto_examples/plot_optim_OTreg.py index 276b250..d36b269 100644 --- a/docs/source/auto_examples/plot_optim_OTreg.py +++ b/docs/source/auto_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) diff --git a/docs/source/auto_examples/plot_optim_OTreg.rst b/docs/source/auto_examples/plot_optim_OTreg.rst index f417158..532d4ca 100644 --- a/docs/source/auto_examples/plot_optim_OTreg.rst +++ b/docs/source/auto_examples/plot_optim_OTreg.rst @@ -11,24 +11,104 @@ Regularized OT with generic solver +.. code-block:: python + + + import numpy as np + import matplotlib.pylab as pl + import ot + + + + + + + -.. rst-class:: sphx-glr-horizontal +Generate data +############################################################################# - * - .. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_003.png - :scale: 47 +.. 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_004.png - :scale: 47 +.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_003.png + :align: center - * - .. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_005.png - :scale: 47 + + +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_004.png + :align: center .. rst-class:: sphx-glr-script-out @@ -258,6 +338,45 @@ 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 @@ -481,52 +600,17 @@ Regularized OT with generic solver 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 - +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 - - G0 = ot.emd(a, b, M) - - pl.figure(3, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, G0, 'OT matrix G0') - - #%% Example with Frobenius norm regularization - + #%% Example with Frobenius norm + entropic regularization with gcg def f(G): return 0.5 * np.sum(G**2) @@ -536,52 +620,35 @@ Regularized OT with generic solver 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') - - #%% 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) + reg1 = 1e-3 + reg2 = 1e-1 - pl.figure(4, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, Ge, 'OT matrix Entrop. reg') + Gel2 = ot.optim.gcg(a, b, M, reg1, reg2, f, df, verbose=True) - #%% Example with Frobenius norm + entropic regularization with gcg + pl.figure(5, figsize=(5, 5)) + ot.plot.plot1D_mat(a, b, Gel2, 'OT entropic + matrix Frob. reg') + pl.show() - def f(G): - return 0.5 * np.sum(G**2) +.. image:: /auto_examples/images/sphx_glr_plot_optim_OTreg_008.png + :align: center - def df(G): - return G +.. rst-class:: sphx-glr-script-out - reg1 = 1e-3 - reg2 = 1e-1 + Out:: - Gel2 = ot.optim.gcg(a, b, M, reg1, reg2, f, df, verbose=True) + 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 - pl.figure(5, figsize=(5, 5)) - ot.plot.plot1D_mat(a, b, Gel2, 'OT entropic + matrix Frob. reg') - pl.show() -**Total running time of the script:** ( 0 minutes 2.720 seconds) +**Total running time of the script:** ( 0 minutes 2.719 seconds) |