From 05da582675c89ab20998e1a9505bf3c220e296b8 Mon Sep 17 00:00:00 2001 From: RĂ©mi Flamary Date: Fri, 9 Jun 2017 13:57:07 +0200 Subject: update doc --- .../source/auto_examples/auto_examples_jupyter.zip | Bin 36979 -> 39268 bytes docs/source/auto_examples/auto_examples_python.zip | Bin 25361 -> 26670 bytes .../images/sphx_glr_plot_OT_2D_samples_001.png | Bin 23230 -> 15481 bytes .../images/sphx_glr_plot_OT_2D_samples_002.png | Bin 12700 -> 15264 bytes .../images/sphx_glr_plot_OT_2D_samples_003.png | Bin 10279 -> 15188 bytes .../images/sphx_glr_plot_OT_2D_samples_004.png | Bin 72646 -> 21310 bytes .../images/sphx_glr_plot_OT_2D_samples_005.png | Bin 12408 -> 15604 bytes .../images/sphx_glr_plot_OT_2D_samples_006.png | Bin 126486 -> 26377 bytes .../auto_examples/images/sphx_glr_plot_WDA_001.png | Bin 0 -> 41268 bytes .../images/sphx_glr_plot_optim_OTreg_003.png | Bin 26191 -> 20684 bytes .../images/sphx_glr_plot_optim_OTreg_004.png | Bin 27315 -> 21750 bytes .../images/sphx_glr_plot_optim_OTreg_005.png | Bin 29807 -> 22971 bytes .../thumb/sphx_glr_plot_OT_2D_samples_thumb.png | Bin 16536 -> 11693 bytes .../images/thumb/sphx_glr_plot_WDA_thumb.png | Bin 0 -> 71650 bytes .../thumb/sphx_glr_plot_optim_OTreg_thumb.png | Bin 3101 -> 2894 bytes docs/source/auto_examples/index.rst | 20 ++++ docs/source/auto_examples/plot_OT_2D_samples.ipynb | 2 +- docs/source/auto_examples/plot_OT_2D_samples.py | 2 +- docs/source/auto_examples/plot_OT_2D_samples.rst | 4 +- docs/source/auto_examples/plot_WDA.ipynb | 54 +++++++++ docs/source/auto_examples/plot_WDA.py | 63 ++++++++++ docs/source/auto_examples/plot_WDA.rst | 127 +++++++++++++++++++++ docs/source/auto_examples/plot_optim_OTreg.ipynb | 2 +- docs/source/auto_examples/plot_optim_OTreg.py | 2 +- docs/source/auto_examples/plot_optim_OTreg.rst | 13 ++- 25 files changed, 277 insertions(+), 12 deletions(-) create mode 100644 docs/source/auto_examples/images/sphx_glr_plot_WDA_001.png create mode 100644 docs/source/auto_examples/images/thumb/sphx_glr_plot_WDA_thumb.png create mode 100644 docs/source/auto_examples/plot_WDA.ipynb create mode 100644 docs/source/auto_examples/plot_WDA.py create mode 100644 docs/source/auto_examples/plot_WDA.rst (limited to 'docs/source/auto_examples') diff --git a/docs/source/auto_examples/auto_examples_jupyter.zip b/docs/source/auto_examples/auto_examples_jupyter.zip index 4840aa7..2b892cf 100644 Binary files a/docs/source/auto_examples/auto_examples_jupyter.zip and b/docs/source/auto_examples/auto_examples_jupyter.zip differ diff --git a/docs/source/auto_examples/auto_examples_python.zip b/docs/source/auto_examples/auto_examples_python.zip index 6e73f21..9799061 100644 Binary files a/docs/source/auto_examples/auto_examples_python.zip and b/docs/source/auto_examples/auto_examples_python.zip differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_001.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_001.png index 43b50e8..c31761d 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_001.png and b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_001.png differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_002.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_002.png index 5651ebd..f6c5d0e 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_002.png and b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_002.png differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_003.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_003.png index b6ca0f4..8f5dfb9 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_003.png and b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_003.png differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_004.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_004.png index ab54a41..309565f 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_004.png and b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_004.png differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_005.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_005.png index 24453e1..6ba8a56 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_005.png and b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_005.png differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_006.png b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_006.png index d1b00e7..7fa0f98 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_006.png and b/docs/source/auto_examples/images/sphx_glr_plot_OT_2D_samples_006.png differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_WDA_001.png b/docs/source/auto_examples/images/sphx_glr_plot_WDA_001.png new file mode 100644 index 0000000..c577317 Binary files /dev/null and b/docs/source/auto_examples/images/sphx_glr_plot_WDA_001.png differ 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 index e12ebc6..7ffcc14 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_003.png and b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_003.png differ 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 index 1d57b8d..2a72060 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_004.png and b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_004.png differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_005.png b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_005.png index 4f5f2d4..e70a6de 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_005.png and b/docs/source/auto_examples/images/sphx_glr_plot_optim_OTreg_005.png differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_2D_samples_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_2D_samples_thumb.png index 0ff6768..d64d50b 100644 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_2D_samples_thumb.png and b/docs/source/auto_examples/images/thumb/sphx_glr_plot_OT_2D_samples_thumb.png differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_WDA_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_WDA_thumb.png new file mode 100644 index 0000000..2597600 Binary files /dev/null and b/docs/source/auto_examples/images/thumb/sphx_glr_plot_WDA_thumb.png differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_optim_OTreg_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_optim_OTreg_thumb.png index cbc8e0f..3015582 100644 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_optim_OTreg_thumb.png and b/docs/source/auto_examples/images/thumb/sphx_glr_plot_optim_OTreg_thumb.png differ diff --git a/docs/source/auto_examples/index.rst b/docs/source/auto_examples/index.rst index 6fac8c0..868ca76 100644 --- a/docs/source/auto_examples/index.rst +++ b/docs/source/auto_examples/index.rst @@ -21,6 +21,26 @@ POT Examples /auto_examples/plot_OT_1D +.. raw:: html + +
+ +.. only:: html + + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_WDA_thumb.png + + :ref:`sphx_glr_auto_examples_plot_WDA.py` + +.. raw:: html + +
+ + +.. toctree:: + :hidden: + + /auto_examples/plot_WDA + .. raw:: html
diff --git a/docs/source/auto_examples/plot_OT_2D_samples.ipynb b/docs/source/auto_examples/plot_OT_2D_samples.ipynb index e8ec1d1..7d42ba7 100644 --- a/docs/source/auto_examples/plot_OT_2D_samples.ipynb +++ b/docs/source/auto_examples/plot_OT_2D_samples.ipynb @@ -24,7 +24,7 @@ "execution_count": null, "cell_type": "code", "source": [ - "import numpy as np\nimport matplotlib.pylab as pl\nimport ot\n\n#%% parameters and data generation\n\nn=20 # nb samples\n\nmu_s=np.array([0,0])\ncov_s=np.array([[1,0],[0,1]])\n\nmu_t=np.array([4,4])\ncov_t=np.array([[1,-.8],[-.8,1]])\n\nxs=ot.datasets.get_2D_samples_gauss(n,mu_s,cov_s)\nxt=ot.datasets.get_2D_samples_gauss(n,mu_t,cov_t)\n\na,b = ot.unif(n),ot.unif(n) # uniform distribution on samples\n\n# loss matrix\nM=ot.dist(xs,xt)\nM/=M.max()\n\n#%% plot samples\n\npl.figure(1)\npl.plot(xs[:,0],xs[:,1],'+b',label='Source samples')\npl.plot(xt[:,0],xt[:,1],'xr',label='Target samples')\npl.legend(loc=0)\npl.title('Source and traget distributions')\n\npl.figure(2)\npl.imshow(M,interpolation='nearest')\npl.title('Cost matrix M')\n\n\n#%% EMD\n\nG0=ot.emd(a,b,M)\n\npl.figure(3)\npl.imshow(G0,interpolation='nearest')\npl.title('OT matrix G0')\n\npl.figure(4)\not.plot.plot2D_samples_mat(xs,xt,G0,c=[.5,.5,1])\npl.plot(xs[:,0],xs[:,1],'+b',label='Source samples')\npl.plot(xt[:,0],xt[:,1],'xr',label='Target samples')\npl.legend(loc=0)\npl.title('OT matrix with samples')\n\n\n#%% sinkhorn\n\n# reg term\nlambd=5e-3\n\nGs=ot.sinkhorn(a,b,M,lambd)\n\npl.figure(5)\npl.imshow(Gs,interpolation='nearest')\npl.title('OT matrix sinkhorn')\n\npl.figure(6)\not.plot.plot2D_samples_mat(xs,xt,Gs,color=[.5,.5,1])\npl.plot(xs[:,0],xs[:,1],'+b',label='Source samples')\npl.plot(xt[:,0],xt[:,1],'xr',label='Target samples')\npl.legend(loc=0)\npl.title('OT matrix Sinkhorn with samples')" + "import numpy as np\nimport matplotlib.pylab as pl\nimport ot\n\n#%% parameters and data generation\n\nn=2 # nb samples\n\nmu_s=np.array([0,0])\ncov_s=np.array([[1,0],[0,1]])\n\nmu_t=np.array([4,4])\ncov_t=np.array([[1,-.8],[-.8,1]])\n\nxs=ot.datasets.get_2D_samples_gauss(n,mu_s,cov_s)\nxt=ot.datasets.get_2D_samples_gauss(n,mu_t,cov_t)\n\na,b = ot.unif(n),ot.unif(n) # uniform distribution on samples\n\n# loss matrix\nM=ot.dist(xs,xt)\nM/=M.max()\n\n#%% plot samples\n\npl.figure(1)\npl.plot(xs[:,0],xs[:,1],'+b',label='Source samples')\npl.plot(xt[:,0],xt[:,1],'xr',label='Target samples')\npl.legend(loc=0)\npl.title('Source and traget distributions')\n\npl.figure(2)\npl.imshow(M,interpolation='nearest')\npl.title('Cost matrix M')\n\n\n#%% EMD\n\nG0=ot.emd(a,b,M)\n\npl.figure(3)\npl.imshow(G0,interpolation='nearest')\npl.title('OT matrix G0')\n\npl.figure(4)\not.plot.plot2D_samples_mat(xs,xt,G0,c=[.5,.5,1])\npl.plot(xs[:,0],xs[:,1],'+b',label='Source samples')\npl.plot(xt[:,0],xt[:,1],'xr',label='Target samples')\npl.legend(loc=0)\npl.title('OT matrix with samples')\n\n\n#%% sinkhorn\n\n# reg term\nlambd=5e-3\n\nGs=ot.sinkhorn(a,b,M,lambd)\n\npl.figure(5)\npl.imshow(Gs,interpolation='nearest')\npl.title('OT matrix sinkhorn')\n\npl.figure(6)\not.plot.plot2D_samples_mat(xs,xt,Gs,color=[.5,.5,1])\npl.plot(xs[:,0],xs[:,1],'+b',label='Source samples')\npl.plot(xt[:,0],xt[:,1],'xr',label='Target samples')\npl.legend(loc=0)\npl.title('OT matrix Sinkhorn with samples')" ], "outputs": [], "metadata": { diff --git a/docs/source/auto_examples/plot_OT_2D_samples.py b/docs/source/auto_examples/plot_OT_2D_samples.py index 6c39ad4..3b95083 100644 --- a/docs/source/auto_examples/plot_OT_2D_samples.py +++ b/docs/source/auto_examples/plot_OT_2D_samples.py @@ -13,7 +13,7 @@ import ot #%% parameters and data generation -n=20 # nb samples +n=2 # nb samples mu_s=np.array([0,0]) cov_s=np.array([[1,0],[0,1]]) diff --git a/docs/source/auto_examples/plot_OT_2D_samples.rst b/docs/source/auto_examples/plot_OT_2D_samples.rst index bc86cb8..01e5f31 100644 --- a/docs/source/auto_examples/plot_OT_2D_samples.rst +++ b/docs/source/auto_examples/plot_OT_2D_samples.rst @@ -58,7 +58,7 @@ #%% parameters and data generation - n=20 # nb samples + n=2 # nb samples mu_s=np.array([0,0]) cov_s=np.array([[1,0],[0,1]]) @@ -122,7 +122,7 @@ pl.legend(loc=0) pl.title('OT matrix Sinkhorn with samples') -**Total running time of the script:** ( 0 minutes 1.051 seconds) +**Total running time of the script:** ( 0 minutes 0.406 seconds) diff --git a/docs/source/auto_examples/plot_WDA.ipynb b/docs/source/auto_examples/plot_WDA.ipynb new file mode 100644 index 0000000..6d641a7 --- /dev/null +++ b/docs/source/auto_examples/plot_WDA.ipynb @@ -0,0 +1,54 @@ +{ + "nbformat_minor": 0, + "nbformat": 4, + "cells": [ + { + "execution_count": null, + "cell_type": "code", + "source": [ + "%matplotlib inline" + ], + "outputs": [], + "metadata": { + "collapsed": false + } + }, + { + "source": [ + "\n# WAsserstein Discriminant Analysis\n\n\n@author: rflamary\n\n" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "execution_count": null, + "cell_type": "code", + "source": [ + "import numpy as np\nimport matplotlib.pylab as pl\nimport ot\nfrom ot.datasets import get_1D_gauss as gauss\nfrom ot.dr import wda\n\n\n#%% parameters\n\nn=1000 # nb samples in source and target datasets\nnz=0.2\nxs,ys=ot.datasets.get_data_classif('3gauss',n,nz)\nxt,yt=ot.datasets.get_data_classif('3gauss',n,nz)\n\nnbnoise=8\n\nxs=np.hstack((xs,np.random.randn(n,nbnoise)))\nxt=np.hstack((xt,np.random.randn(n,nbnoise)))\n\n#%% plot samples\n\npl.figure(1)\n\n\npl.scatter(xt[:,0],xt[:,1],c=ys,marker='+',label='Source samples')\npl.legend(loc=0)\npl.title('Discriminant dimensions')\n\n\n#%% plot distributions and loss matrix\np=2\nreg=1\nk=10\nmaxiter=100\n\nP,proj = wda(xs,ys,p,reg,k,maxiter=maxiter)\n\n#%% plot samples\n\nxsp=proj(xs)\nxtp=proj(xt)\n\npl.figure(1,(10,5))\n\npl.subplot(1,2,1)\npl.scatter(xsp[:,0],xsp[:,1],c=ys,marker='+',label='Projected samples')\npl.legend(loc=0)\npl.title('Projected training samples')\n\n\npl.subplot(1,2,2)\npl.scatter(xtp[:,0],xtp[:,1],c=ys,marker='+',label='Projected samples')\npl.legend(loc=0)\npl.title('Projected test samples')" + ], + "outputs": [], + "metadata": { + "collapsed": false + } + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "name": "python2", + "language": "python" + }, + "language_info": { + "mimetype": "text/x-python", + "nbconvert_exporter": "python", + "name": "python", + "file_extension": ".py", + "version": "2.7.12", + "pygments_lexer": "ipython2", + "codemirror_mode": { + "version": 2, + "name": "ipython" + } + } + } +} \ No newline at end of file diff --git a/docs/source/auto_examples/plot_WDA.py b/docs/source/auto_examples/plot_WDA.py new file mode 100644 index 0000000..94b7ef4 --- /dev/null +++ b/docs/source/auto_examples/plot_WDA.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +""" +================================= +WAsserstein Discriminant Analysis +================================= + +@author: rflamary +""" + +import numpy as np +import matplotlib.pylab as pl +import ot +from ot.datasets import get_1D_gauss as gauss +from ot.dr import wda + + +#%% parameters + +n=1000 # nb samples in source and target datasets +nz=0.2 +xs,ys=ot.datasets.get_data_classif('3gauss',n,nz) +xt,yt=ot.datasets.get_data_classif('3gauss',n,nz) + +nbnoise=8 + +xs=np.hstack((xs,np.random.randn(n,nbnoise))) +xt=np.hstack((xt,np.random.randn(n,nbnoise))) + +#%% plot samples + +pl.figure(1) + + +pl.scatter(xt[:,0],xt[:,1],c=ys,marker='+',label='Source samples') +pl.legend(loc=0) +pl.title('Discriminant dimensions') + + +#%% plot distributions and loss matrix +p=2 +reg=1 +k=10 +maxiter=100 + +P,proj = wda(xs,ys,p,reg,k,maxiter=maxiter) + +#%% plot samples + +xsp=proj(xs) +xtp=proj(xt) + +pl.figure(1,(10,5)) + +pl.subplot(1,2,1) +pl.scatter(xsp[:,0],xsp[:,1],c=ys,marker='+',label='Projected samples') +pl.legend(loc=0) +pl.title('Projected training samples') + + +pl.subplot(1,2,2) +pl.scatter(xtp[:,0],xtp[:,1],c=ys,marker='+',label='Projected samples') +pl.legend(loc=0) +pl.title('Projected test samples') diff --git a/docs/source/auto_examples/plot_WDA.rst b/docs/source/auto_examples/plot_WDA.rst new file mode 100644 index 0000000..379a133 --- /dev/null +++ b/docs/source/auto_examples/plot_WDA.rst @@ -0,0 +1,127 @@ + + +.. _sphx_glr_auto_examples_plot_WDA.py: + + +================================= +WAsserstein Discriminant Analysis +================================= + +@author: rflamary + + + + +.. image:: /auto_examples/images/sphx_glr_plot_WDA_001.png + :align: center + + +.. rst-class:: sphx-glr-script-out + + Out:: + + Compiling cost function... + Computing gradient of cost function... + iter cost val grad. norm + 1 +7.5272200933021116e-01 8.85804426e-01 + 2 +2.5764223980223788e-01 3.04501586e-01 + 3 +1.6018169776696620e-01 1.78298483e-01 + 4 +1.4560944642106255e-01 1.42133298e-01 + 5 +1.0243843483991794e-01 1.23342675e-01 + 6 +7.8856617504010643e-02 1.05379766e-01 + 7 +7.7620851864404483e-02 1.04044062e-01 + 8 +7.3160520861018416e-02 8.33770034e-02 + 9 +6.6999294576662857e-02 2.87368977e-02 + 10 +6.6250206928793964e-02 1.72155066e-03 + 11 +6.6247631521353170e-02 2.43806911e-04 + 12 +6.6247596955965438e-02 1.40066459e-04 + 13 +6.6247580176638649e-02 4.77471577e-06 + 14 +6.6247580163923028e-02 3.00484279e-06 + 15 +6.6247580159235792e-02 1.91039983e-06 + 16 +6.6247580156889613e-02 9.56038747e-07 + Terminated - min grad norm reached after 16 iterations, 7.78 seconds. + + + + +| + + +.. code-block:: python + + + import numpy as np + import matplotlib.pylab as pl + import ot + from ot.datasets import get_1D_gauss as gauss + from ot.dr import wda + + + #%% parameters + + n=1000 # nb samples in source and target datasets + nz=0.2 + xs,ys=ot.datasets.get_data_classif('3gauss',n,nz) + xt,yt=ot.datasets.get_data_classif('3gauss',n,nz) + + nbnoise=8 + + xs=np.hstack((xs,np.random.randn(n,nbnoise))) + xt=np.hstack((xt,np.random.randn(n,nbnoise))) + + #%% plot samples + + pl.figure(1) + + + pl.scatter(xt[:,0],xt[:,1],c=ys,marker='+',label='Source samples') + pl.legend(loc=0) + pl.title('Discriminant dimensions') + + + #%% plot distributions and loss matrix + p=2 + reg=1 + k=10 + maxiter=100 + + P,proj = wda(xs,ys,p,reg,k,maxiter=maxiter) + + #%% plot samples + + xsp=proj(xs) + xtp=proj(xt) + + pl.figure(1,(10,5)) + + pl.subplot(1,2,1) + pl.scatter(xsp[:,0],xsp[:,1],c=ys,marker='+',label='Projected samples') + pl.legend(loc=0) + pl.title('Projected training samples') + + + pl.subplot(1,2,2) + pl.scatter(xtp[:,0],xtp[:,1],c=ys,marker='+',label='Projected samples') + pl.legend(loc=0) + pl.title('Projected test samples') + +**Total running time of the script:** ( 0 minutes 14.134 seconds) + + + +.. container:: sphx-glr-footer + + + .. container:: sphx-glr-download + + :download:`Download Python source code: plot_WDA.py ` + + + + .. container:: sphx-glr-download + + :download:`Download Jupyter notebook: plot_WDA.ipynb ` + +.. rst-class:: sphx-glr-signature + + `Generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_optim_OTreg.ipynb b/docs/source/auto_examples/plot_optim_OTreg.ipynb index 250ea72..00d4702 100644 --- a/docs/source/auto_examples/plot_optim_OTreg.ipynb +++ b/docs/source/auto_examples/plot_optim_OTreg.ipynb @@ -24,7 +24,7 @@ "execution_count": null, "cell_type": "code", "source": [ - "import numpy as np\nimport matplotlib.pylab as pl\nimport ot\n\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)\not.plot.plot1D_mat(a,b,G0,'OT matrix G0')\n\n#%% Example with Frobenius norm regularization\n\ndef f(G): return 0.5*np.sum(G**2)\ndef df(G): return G\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\ndef f(G): return np.sum(G*np.log(G))\ndef df(G): return np.log(G)+1\n\nreg=1e-3\n\nGe=ot.optim.cg(a,b,M,reg,f,df,verbose=True)\n\npl.figure(4)\not.plot.plot1D_mat(a,b,Ge,'OT matrix Entrop. reg')\n\n#%% Example with Frobenius norm + entropic regularization with gcg\n\ndef f(G): return 0.5*np.sum(G**2)\ndef df(G): return G\n\nreg1=1e-1\nreg2=1e-1\n\nGel2=ot.optim.gcg(a,b,M,reg1,reg2,f,df,verbose=True)\n\npl.figure(5)\not.plot.plot1D_mat(a,b,Gel2,'OT entropic + matrix Frob. reg')" + "import numpy as np\nimport matplotlib.pylab as pl\nimport ot\n\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)\not.plot.plot1D_mat(a,b,G0,'OT matrix G0')\n\n#%% Example with Frobenius norm regularization\n\ndef f(G): return 0.5*np.sum(G**2)\ndef df(G): return G\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\ndef f(G): return np.sum(G*np.log(G))\ndef df(G): return np.log(G)+1\n\nreg=1e-3\n\nGe=ot.optim.cg(a,b,M,reg,f,df,verbose=True)\n\npl.figure(4)\not.plot.plot1D_mat(a,b,Ge,'OT matrix Entrop. reg')\n\n#%% Example with Frobenius norm + entropic regularization with gcg\n\ndef f(G): return 0.5*np.sum(G**2)\ndef df(G): return G\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)\not.plot.plot1D_mat(a,b,Gel2,'OT entropic + matrix Frob. reg')" ], "outputs": [], "metadata": { diff --git a/docs/source/auto_examples/plot_optim_OTreg.py b/docs/source/auto_examples/plot_optim_OTreg.py index 3c4d3f4..c585445 100644 --- a/docs/source/auto_examples/plot_optim_OTreg.py +++ b/docs/source/auto_examples/plot_optim_OTreg.py @@ -64,7 +64,7 @@ ot.plot.plot1D_mat(a,b,Ge,'OT matrix Entrop. reg') def f(G): return 0.5*np.sum(G**2) def df(G): return G -reg1=1e-1 +reg1=1e-3 reg2=1e-1 Gel2=ot.optim.gcg(a,b,M,reg1,reg2,f,df,verbose=True) diff --git a/docs/source/auto_examples/plot_optim_OTreg.rst b/docs/source/auto_examples/plot_optim_OTreg.rst index d6397ba..0dff327 100644 --- a/docs/source/auto_examples/plot_optim_OTreg.rst +++ b/docs/source/auto_examples/plot_optim_OTreg.rst @@ -483,10 +483,11 @@ Regularized OT with generic solver 200|1.607143e-01|-2.151971e-10 It. |Loss |Delta loss -------------------------------- - 0|-4.988764e-01|0.000000e+00 - 1|-4.993932e-01|-1.034993e-03 - 2|-4.993933e-01|-9.845917e-08 - 3|-4.993933e-01|-9.206594e-12 + 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 @@ -554,14 +555,14 @@ Regularized OT with generic solver def f(G): return 0.5*np.sum(G**2) def df(G): return G - reg1=1e-1 + reg1=1e-3 reg2=1e-1 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') -**Total running time of the script:** ( 0 minutes 2.358 seconds) +**Total running time of the script:** ( 0 minutes 2.422 seconds) -- cgit v1.2.3