From 9cd97796797b9b2853c6458a7f4e9347bb212978 Mon Sep 17 00:00:00 2001 From: RĂ©mi Flamary Date: Fri, 15 Mar 2019 11:56:10 +0100 Subject: update notebooks and documentation --- docs/cache_nbrun | 2 +- .../source/auto_examples/auto_examples_jupyter.zip | Bin 123577 -> 122957 bytes docs/source/auto_examples/auto_examples_python.zip | Bin 81978 -> 81905 bytes .../images/sphx_glr_plot_otda_color_images_001.png | Bin 144957 -> 145014 bytes .../images/sphx_glr_plot_otda_color_images_003.png | Bin 50401 -> 50472 bytes .../images/sphx_glr_plot_otda_color_images_005.png | Bin 234564 -> 326766 bytes ...phx_glr_plot_otda_mapping_colors_images_001.png | Bin 165592 -> 165658 bytes ...phx_glr_plot_otda_mapping_colors_images_003.png | Bin 80722 -> 80796 bytes ...phx_glr_plot_otda_mapping_colors_images_004.png | Bin 541314 -> 512309 bytes .../images/sphx_glr_plot_stochastic_005.png | Bin 10677 -> 10677 bytes .../images/sphx_glr_plot_stochastic_007.png | Bin 9563 -> 9483 bytes .../sphx_glr_plot_otda_color_images_thumb.png | Bin 51085 -> 49131 bytes ...x_glr_plot_otda_mapping_colors_images_thumb.png | Bin 58315 -> 56216 bytes docs/source/auto_examples/index.rst | 2 +- .../auto_examples/plot_otda_color_images.ipynb | 194 ++++++++++----------- .../source/auto_examples/plot_otda_color_images.py | 8 +- .../auto_examples/plot_otda_color_images.rst | 21 ++- .../plot_otda_mapping_colors_images.ipynb | 192 ++++++++++---------- .../plot_otda_mapping_colors_images.py | 2 +- .../plot_otda_mapping_colors_images.rst | 77 ++++---- docs/source/auto_examples/plot_stochastic.ipynb | 44 +---- docs/source/auto_examples/plot_stochastic.py | 11 +- docs/source/auto_examples/plot_stochastic.rst | 97 ++++------- 23 files changed, 298 insertions(+), 352 deletions(-) diff --git a/docs/cache_nbrun b/docs/cache_nbrun index 575adc8..6f10375 100644 --- a/docs/cache_nbrun +++ b/docs/cache_nbrun @@ -1 +1 @@ -{"plot_otda_mapping_colors_images.ipynb": "4f0587a00a3c082799a75a0ed36e9ce1", "plot_optim_OTreg.ipynb": "481801bb0d133ef350a65179cf8f739a", "plot_barycenter_1D.ipynb": "5f6fb8aebd8e2e91ebc77c923cb112b3", "plot_stochastic.ipynb": "e2c520150378ae4635f74509f687fa01", "plot_WDA.ipynb": "27f8de4c6d7db46497076523673eedfb", "plot_otda_linear_mapping.ipynb": "a472c767abe82020e0a58125a528785c", "plot_OT_1D_smooth.ipynb": "3a059103652225a0c78ea53895cf79e5", "plot_OT_L1_vs_L2.ipynb": "5d565b8aaf03be4309eba731127851dc", "plot_otda_color_images.ipynb": "d047d635f4987c81072383241590e21f", "plot_otda_classes.ipynb": "39087b6e98217851575f2271c22853a4", "plot_otda_d2.ipynb": "e6feae588103f2a8fab942e5f4eff483", "plot_otda_mapping.ipynb": "2f1ebbdc0f855d9e2b7adf9edec24d25", "plot_gromov.ipynb": "24f2aea489714d34779521f46d5e2c47", "plot_compute_emd.ipynb": "f5cd71cad882ec157dc8222721e9820c", "plot_OT_1D.ipynb": "b5348bdc561c07ec168a1622e5af4b93", "plot_gromov_barycenter.ipynb": "953e5047b886ec69ec621ec52f5e21d1", "plot_free_support_barycenter.ipynb": "246dd2feff4b233a4f1a553c5a202fdc", "plot_convolutional_barycenter.ipynb": "a72bb3716a1baaffd81ae267a673f9b6", "plot_otda_semi_supervised.ipynb": "f6dfb02ba2bbd939408ffcd22a3b007c", "plot_OT_2D_samples.ipynb": "07dbc14859fa019a966caa79fa0825bd", "plot_barycenter_lp_vs_entropic.ipynb": "51833e8c76aaedeba9599ac7a30eb357"} \ No newline at end of file +{"plot_otda_mapping_colors_images.ipynb": "cc8bf9a857f52e4a159fe71dfda19018", "plot_optim_OTreg.ipynb": "481801bb0d133ef350a65179cf8f739a", "plot_otda_color_images.ipynb": "f804d5806c7ac1a0901e4542b1eaa77b", "plot_stochastic.ipynb": "e18253354c8c1d72567a4259eb1094f7", "plot_WDA.ipynb": "27f8de4c6d7db46497076523673eedfb", "plot_otda_linear_mapping.ipynb": "a472c767abe82020e0a58125a528785c", "plot_OT_1D_smooth.ipynb": "3a059103652225a0c78ea53895cf79e5", "plot_OT_L1_vs_L2.ipynb": "5d565b8aaf03be4309eba731127851dc", "plot_barycenter_1D.ipynb": "5f6fb8aebd8e2e91ebc77c923cb112b3", "plot_otda_classes.ipynb": "39087b6e98217851575f2271c22853a4", "plot_otda_d2.ipynb": "e6feae588103f2a8fab942e5f4eff483", "plot_otda_mapping.ipynb": "2f1ebbdc0f855d9e2b7adf9edec24d25", "plot_gromov.ipynb": "24f2aea489714d34779521f46d5e2c47", "plot_compute_emd.ipynb": "f5cd71cad882ec157dc8222721e9820c", "plot_OT_1D.ipynb": "b5348bdc561c07ec168a1622e5af4b93", "plot_gromov_barycenter.ipynb": "953e5047b886ec69ec621ec52f5e21d1", "plot_free_support_barycenter.ipynb": "246dd2feff4b233a4f1a553c5a202fdc", "plot_convolutional_barycenter.ipynb": "a72bb3716a1baaffd81ae267a673f9b6", "plot_otda_semi_supervised.ipynb": "f6dfb02ba2bbd939408ffcd22a3b007c", "plot_OT_2D_samples.ipynb": "07dbc14859fa019a966caa79fa0825bd", "plot_barycenter_lp_vs_entropic.ipynb": "51833e8c76aaedeba9599ac7a30eb357"} \ No newline at end of file diff --git a/docs/source/auto_examples/auto_examples_jupyter.zip b/docs/source/auto_examples/auto_examples_jupyter.zip index 304bb06..88e1e9b 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 3be8a76..120a586 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_otda_color_images_001.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_001.png index 95f882a..7de991a 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_001.png and b/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_001.png differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_003.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_003.png index aa1a5d3..aac929b 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_003.png and b/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_003.png differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_005.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_005.png index d219bb3..5b8101b 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_005.png and b/docs/source/auto_examples/images/sphx_glr_plot_otda_color_images_005.png differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_001.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_001.png index 33134fc..d77e68a 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_001.png and b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_001.png differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_003.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_003.png index 42197e3..1199903 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_003.png and b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_003.png differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_004.png b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_004.png index d9101da..1c73e43 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_004.png and b/docs/source/auto_examples/images/sphx_glr_plot_otda_mapping_colors_images_004.png differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_005.png b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_005.png index 3d1e239..42e5007 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_005.png and b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_005.png differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_007.png b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_007.png index 986aa96..cda643b 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_stochastic_007.png and b/docs/source/auto_examples/images/sphx_glr_plot_stochastic_007.png differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_color_images_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_color_images_thumb.png index a919055..4d90437 100644 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_color_images_thumb.png and b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_color_images_thumb.png differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png index f7fd217..61a5137 100644 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png and b/docs/source/auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png differ diff --git a/docs/source/auto_examples/index.rst b/docs/source/auto_examples/index.rst index 259fca1..17a9710 100644 --- a/docs/source/auto_examples/index.rst +++ b/docs/source/auto_examples/index.rst @@ -229,7 +229,7 @@ This is a gallery of all the POT example files. .. raw:: html -
+
.. only:: html diff --git a/docs/source/auto_examples/plot_otda_color_images.ipynb b/docs/source/auto_examples/plot_otda_color_images.ipynb index 2daf406..103bdec 100644 --- a/docs/source/auto_examples/plot_otda_color_images.ipynb +++ b/docs/source/auto_examples/plot_otda_color_images.ipynb @@ -1,144 +1,144 @@ { - "nbformat_minor": 0, - "nbformat": 4, "cells": [ { - "execution_count": null, - "cell_type": "code", - "source": [ - "%matplotlib inline" - ], - "outputs": [], + "cell_type": "code", + "execution_count": null, "metadata": { "collapsed": false - } - }, - { + }, + "outputs": [], "source": [ - "\n# OT for image color adaptation\n\n\nThis example presents a way of transferring colors between two image\nwith Optimal Transport as introduced in [6]\n\n[6] Ferradans, S., Papadakis, N., Peyre, G., & Aujol, J. F. (2014).\nRegularized discrete optimal transport.\nSIAM Journal on Imaging Sciences, 7(3), 1853-1882.\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, + "%matplotlib inline" + ] + }, { - "execution_count": null, - "cell_type": "code", + "cell_type": "markdown", + "metadata": {}, "source": [ - "# Authors: Remi Flamary \n# Stanislas Chambon \n#\n# License: MIT License\n\nimport numpy as np\nfrom scipy import ndimage\nimport matplotlib.pylab as pl\nimport ot\n\n\nr = np.random.RandomState(42)\n\n\ndef im2mat(I):\n \"\"\"Converts and image to matrix (one pixel per line)\"\"\"\n return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))\n\n\ndef mat2im(X, shape):\n \"\"\"Converts back a matrix to an image\"\"\"\n return X.reshape(shape)\n\n\ndef minmax(I):\n return np.clip(I, 0, 1)" - ], - "outputs": [], + "\n# OT for image color adaptation\n\n\nThis example presents a way of transferring colors between two images\nwith Optimal Transport as introduced in [6]\n\n[6] Ferradans, S., Papadakis, N., Peyre, G., & Aujol, J. F. (2014).\nRegularized discrete optimal transport.\nSIAM Journal on Imaging Sciences, 7(3), 1853-1882.\n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, "metadata": { "collapsed": false - } - }, + }, + "outputs": [], + "source": [ + "# Authors: Remi Flamary \n# Stanislas Chambon \n#\n# License: MIT License\n\nimport numpy as np\nfrom scipy import ndimage\nimport matplotlib.pylab as pl\nimport ot\n\n\nr = np.random.RandomState(42)\n\n\ndef im2mat(I):\n \"\"\"Converts an image to matrix (one pixel per line)\"\"\"\n return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))\n\n\ndef mat2im(X, shape):\n \"\"\"Converts back a matrix to an image\"\"\"\n return X.reshape(shape)\n\n\ndef minmax(I):\n return np.clip(I, 0, 1)" + ] + }, { + "cell_type": "markdown", + "metadata": {}, "source": [ "Generate data\n-------------\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, + ] + }, { - "execution_count": null, - "cell_type": "code", - "source": [ - "# Loading images\nI1 = ndimage.imread('../data/ocean_day.jpg').astype(np.float64) / 256\nI2 = ndimage.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256\n\nX1 = im2mat(I1)\nX2 = im2mat(I2)\n\n# training samples\nnb = 1000\nidx1 = r.randint(X1.shape[0], size=(nb,))\nidx2 = r.randint(X2.shape[0], size=(nb,))\n\nXs = X1[idx1, :]\nXt = X2[idx2, :]" - ], - "outputs": [], + "cell_type": "code", + "execution_count": null, "metadata": { "collapsed": false - } - }, + }, + "outputs": [], + "source": [ + "# Loading images\nI1 = ndimage.imread('../data/ocean_day.jpg').astype(np.float64) / 256\nI2 = ndimage.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256\n\nX1 = im2mat(I1)\nX2 = im2mat(I2)\n\n# training samples\nnb = 1000\nidx1 = r.randint(X1.shape[0], size=(nb,))\nidx2 = r.randint(X2.shape[0], size=(nb,))\n\nXs = X1[idx1, :]\nXt = X2[idx2, :]" + ] + }, { + "cell_type": "markdown", + "metadata": {}, "source": [ "Plot original image\n-------------------\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, + ] + }, { - "execution_count": null, - "cell_type": "code", - "source": [ - "pl.figure(1, figsize=(6.4, 3))\n\npl.subplot(1, 2, 1)\npl.imshow(I1)\npl.axis('off')\npl.title('Image 1')\n\npl.subplot(1, 2, 2)\npl.imshow(I2)\npl.axis('off')\npl.title('Image 2')" - ], - "outputs": [], + "cell_type": "code", + "execution_count": null, "metadata": { "collapsed": false - } - }, + }, + "outputs": [], + "source": [ + "pl.figure(1, figsize=(6.4, 3))\n\npl.subplot(1, 2, 1)\npl.imshow(I1)\npl.axis('off')\npl.title('Image 1')\n\npl.subplot(1, 2, 2)\npl.imshow(I2)\npl.axis('off')\npl.title('Image 2')" + ] + }, { + "cell_type": "markdown", + "metadata": {}, "source": [ "Scatter plot of colors\n----------------------\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, + ] + }, { - "execution_count": null, - "cell_type": "code", - "source": [ - "pl.figure(2, figsize=(6.4, 3))\n\npl.subplot(1, 2, 1)\npl.scatter(Xs[:, 0], Xs[:, 2], c=Xs)\npl.axis([0, 1, 0, 1])\npl.xlabel('Red')\npl.ylabel('Blue')\npl.title('Image 1')\n\npl.subplot(1, 2, 2)\npl.scatter(Xt[:, 0], Xt[:, 2], c=Xt)\npl.axis([0, 1, 0, 1])\npl.xlabel('Red')\npl.ylabel('Blue')\npl.title('Image 2')\npl.tight_layout()" - ], - "outputs": [], + "cell_type": "code", + "execution_count": null, "metadata": { "collapsed": false - } - }, + }, + "outputs": [], + "source": [ + "pl.figure(2, figsize=(6.4, 3))\n\npl.subplot(1, 2, 1)\npl.scatter(Xs[:, 0], Xs[:, 2], c=Xs)\npl.axis([0, 1, 0, 1])\npl.xlabel('Red')\npl.ylabel('Blue')\npl.title('Image 1')\n\npl.subplot(1, 2, 2)\npl.scatter(Xt[:, 0], Xt[:, 2], c=Xt)\npl.axis([0, 1, 0, 1])\npl.xlabel('Red')\npl.ylabel('Blue')\npl.title('Image 2')\npl.tight_layout()" + ] + }, { + "cell_type": "markdown", + "metadata": {}, "source": [ "Instantiate the different transport algorithms and fit them\n-----------------------------------------------------------\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, + ] + }, { - "execution_count": null, - "cell_type": "code", - "source": [ - "# EMDTransport\not_emd = ot.da.EMDTransport()\not_emd.fit(Xs=Xs, Xt=Xt)\n\n# SinkhornTransport\not_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1)\not_sinkhorn.fit(Xs=Xs, Xt=Xt)\n\n# prediction between images (using out of sample prediction as in [6])\ntransp_Xs_emd = ot_emd.transform(Xs=X1)\ntransp_Xt_emd = ot_emd.inverse_transform(Xt=X2)\n\ntransp_Xs_sinkhorn = ot_emd.transform(Xs=X1)\ntransp_Xt_sinkhorn = ot_emd.inverse_transform(Xt=X2)\n\nI1t = minmax(mat2im(transp_Xs_emd, I1.shape))\nI2t = minmax(mat2im(transp_Xt_emd, I2.shape))\n\nI1te = minmax(mat2im(transp_Xs_sinkhorn, I1.shape))\nI2te = minmax(mat2im(transp_Xt_sinkhorn, I2.shape))" - ], - "outputs": [], + "cell_type": "code", + "execution_count": null, "metadata": { "collapsed": false - } - }, + }, + "outputs": [], + "source": [ + "# EMDTransport\not_emd = ot.da.EMDTransport()\not_emd.fit(Xs=Xs, Xt=Xt)\n\n# SinkhornTransport\not_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1)\not_sinkhorn.fit(Xs=Xs, Xt=Xt)\n\n# prediction between images (using out of sample prediction as in [6])\ntransp_Xs_emd = ot_emd.transform(Xs=X1)\ntransp_Xt_emd = ot_emd.inverse_transform(Xt=X2)\n\ntransp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=X1)\ntransp_Xt_sinkhorn = ot_sinkhorn.inverse_transform(Xt=X2)\n\nI1t = minmax(mat2im(transp_Xs_emd, I1.shape))\nI2t = minmax(mat2im(transp_Xt_emd, I2.shape))\n\nI1te = minmax(mat2im(transp_Xs_sinkhorn, I1.shape))\nI2te = minmax(mat2im(transp_Xt_sinkhorn, I2.shape))" + ] + }, { + "cell_type": "markdown", + "metadata": {}, "source": [ "Plot new images\n---------------\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, + ] + }, { - "execution_count": null, - "cell_type": "code", - "source": [ - "pl.figure(3, figsize=(8, 4))\n\npl.subplot(2, 3, 1)\npl.imshow(I1)\npl.axis('off')\npl.title('Image 1')\n\npl.subplot(2, 3, 2)\npl.imshow(I1t)\npl.axis('off')\npl.title('Image 1 Adapt')\n\npl.subplot(2, 3, 3)\npl.imshow(I1te)\npl.axis('off')\npl.title('Image 1 Adapt (reg)')\n\npl.subplot(2, 3, 4)\npl.imshow(I2)\npl.axis('off')\npl.title('Image 2')\n\npl.subplot(2, 3, 5)\npl.imshow(I2t)\npl.axis('off')\npl.title('Image 2 Adapt')\n\npl.subplot(2, 3, 6)\npl.imshow(I2te)\npl.axis('off')\npl.title('Image 2 Adapt (reg)')\npl.tight_layout()\n\npl.show()" - ], - "outputs": [], + "cell_type": "code", + "execution_count": null, "metadata": { "collapsed": false - } + }, + "outputs": [], + "source": [ + "pl.figure(3, figsize=(8, 4))\n\npl.subplot(2, 3, 1)\npl.imshow(I1)\npl.axis('off')\npl.title('Image 1')\n\npl.subplot(2, 3, 2)\npl.imshow(I1t)\npl.axis('off')\npl.title('Image 1 Adapt')\n\npl.subplot(2, 3, 3)\npl.imshow(I1te)\npl.axis('off')\npl.title('Image 1 Adapt (reg)')\n\npl.subplot(2, 3, 4)\npl.imshow(I2)\npl.axis('off')\npl.title('Image 2')\n\npl.subplot(2, 3, 5)\npl.imshow(I2t)\npl.axis('off')\npl.title('Image 2 Adapt')\n\npl.subplot(2, 3, 6)\npl.imshow(I2te)\npl.axis('off')\npl.title('Image 2 Adapt (reg)')\npl.tight_layout()\n\npl.show()" + ] } - ], + ], "metadata": { "kernelspec": { - "display_name": "Python 2", - "name": "python2", - "language": "python" - }, + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, "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" - } + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.7" } - } + }, + "nbformat": 4, + "nbformat_minor": 0 } \ No newline at end of file diff --git a/docs/source/auto_examples/plot_otda_color_images.py b/docs/source/auto_examples/plot_otda_color_images.py index e77aec0..62383a2 100644 --- a/docs/source/auto_examples/plot_otda_color_images.py +++ b/docs/source/auto_examples/plot_otda_color_images.py @@ -4,7 +4,7 @@ OT for image color adaptation ============================= -This example presents a way of transferring colors between two image +This example presents a way of transferring colors between two images with Optimal Transport as introduced in [6] [6] Ferradans, S., Papadakis, N., Peyre, G., & Aujol, J. F. (2014). @@ -27,7 +27,7 @@ r = np.random.RandomState(42) def im2mat(I): - """Converts and image to matrix (one pixel per line)""" + """Converts an image to matrix (one pixel per line)""" return I.reshape((I.shape[0] * I.shape[1], I.shape[2])) @@ -115,8 +115,8 @@ ot_sinkhorn.fit(Xs=Xs, Xt=Xt) transp_Xs_emd = ot_emd.transform(Xs=X1) transp_Xt_emd = ot_emd.inverse_transform(Xt=X2) -transp_Xs_sinkhorn = ot_emd.transform(Xs=X1) -transp_Xt_sinkhorn = ot_emd.inverse_transform(Xt=X2) +transp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=X1) +transp_Xt_sinkhorn = ot_sinkhorn.inverse_transform(Xt=X2) I1t = minmax(mat2im(transp_Xs_emd, I1.shape)) I2t = minmax(mat2im(transp_Xt_emd, I2.shape)) diff --git a/docs/source/auto_examples/plot_otda_color_images.rst b/docs/source/auto_examples/plot_otda_color_images.rst index 9c31ba7..ab0406e 100644 --- a/docs/source/auto_examples/plot_otda_color_images.rst +++ b/docs/source/auto_examples/plot_otda_color_images.rst @@ -7,7 +7,7 @@ OT for image color adaptation ============================= -This example presents a way of transferring colors between two image +This example presents a way of transferring colors between two images with Optimal Transport as introduced in [6] [6] Ferradans, S., Papadakis, N., Peyre, G., & Aujol, J. F. (2014). @@ -34,7 +34,7 @@ SIAM Journal on Imaging Sciences, 7(3), 1853-1882. def im2mat(I): - """Converts and image to matrix (one pixel per line)""" + """Converts an image to matrix (one pixel per line)""" return I.reshape((I.shape[0] * I.shape[1], I.shape[2])) @@ -168,8 +168,8 @@ Instantiate the different transport algorithms and fit them transp_Xs_emd = ot_emd.transform(Xs=X1) transp_Xt_emd = ot_emd.inverse_transform(Xt=X2) - transp_Xs_sinkhorn = ot_emd.transform(Xs=X1) - transp_Xt_sinkhorn = ot_emd.inverse_transform(Xt=X2) + transp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=X1) + transp_Xt_sinkhorn = ot_sinkhorn.inverse_transform(Xt=X2) I1t = minmax(mat2im(transp_Xs_emd, I1.shape)) I2t = minmax(mat2im(transp_Xt_emd, I2.shape)) @@ -235,11 +235,13 @@ Plot new images -**Total running time of the script:** ( 3 minutes 16.469 seconds) +**Total running time of the script:** ( 3 minutes 55.541 seconds) -.. container:: sphx-glr-footer +.. only :: html + + .. container:: sphx-glr-footer .. container:: sphx-glr-download @@ -252,6 +254,9 @@ Plot new images :download:`Download Jupyter notebook: plot_otda_color_images.ipynb ` -.. rst-class:: sphx-glr-signature - `Generated by Sphinx-Gallery `_ +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_otda_mapping_colors_images.ipynb b/docs/source/auto_examples/plot_otda_mapping_colors_images.ipynb index 56caa8a..baffef4 100644 --- a/docs/source/auto_examples/plot_otda_mapping_colors_images.ipynb +++ b/docs/source/auto_examples/plot_otda_mapping_colors_images.ipynb @@ -1,144 +1,144 @@ { - "nbformat_minor": 0, - "nbformat": 4, "cells": [ { - "execution_count": null, - "cell_type": "code", - "source": [ - "%matplotlib inline" - ], - "outputs": [], + "cell_type": "code", + "execution_count": null, "metadata": { "collapsed": false - } - }, + }, + "outputs": [], + "source": [ + "%matplotlib inline" + ] + }, { + "cell_type": "markdown", + "metadata": {}, "source": [ "\n# OT for image color adaptation with mapping estimation\n\n\nOT for domain adaptation with image color adaptation [6] with mapping\nestimation [8].\n\n[6] Ferradans, S., Papadakis, N., Peyre, G., & Aujol, J. F. (2014). Regularized\n discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3),\n 1853-1882.\n[8] M. Perrot, N. Courty, R. Flamary, A. Habrard, \"Mapping estimation for\n discrete optimal transport\", Neural Information Processing Systems (NIPS),\n 2016.\n\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, + ] + }, { - "execution_count": null, - "cell_type": "code", - "source": [ - "# Authors: Remi Flamary \n# Stanislas Chambon \n#\n# License: MIT License\n\nimport numpy as np\nfrom scipy import ndimage\nimport matplotlib.pylab as pl\nimport ot\n\nr = np.random.RandomState(42)\n\n\ndef im2mat(I):\n \"\"\"Converts and image to matrix (one pixel per line)\"\"\"\n return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))\n\n\ndef mat2im(X, shape):\n \"\"\"Converts back a matrix to an image\"\"\"\n return X.reshape(shape)\n\n\ndef minmax(I):\n return np.clip(I, 0, 1)" - ], - "outputs": [], + "cell_type": "code", + "execution_count": null, "metadata": { "collapsed": false - } - }, + }, + "outputs": [], + "source": [ + "# Authors: Remi Flamary \n# Stanislas Chambon \n#\n# License: MIT License\n\nimport numpy as np\nfrom scipy import ndimage\nimport matplotlib.pylab as pl\nimport ot\n\nr = np.random.RandomState(42)\n\n\ndef im2mat(I):\n \"\"\"Converts and image to matrix (one pixel per line)\"\"\"\n return I.reshape((I.shape[0] * I.shape[1], I.shape[2]))\n\n\ndef mat2im(X, shape):\n \"\"\"Converts back a matrix to an image\"\"\"\n return X.reshape(shape)\n\n\ndef minmax(I):\n return np.clip(I, 0, 1)" + ] + }, { + "cell_type": "markdown", + "metadata": {}, "source": [ "Generate data\n-------------\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, + ] + }, { - "execution_count": null, - "cell_type": "code", - "source": [ - "# Loading images\nI1 = ndimage.imread('../data/ocean_day.jpg').astype(np.float64) / 256\nI2 = ndimage.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256\n\n\nX1 = im2mat(I1)\nX2 = im2mat(I2)\n\n# training samples\nnb = 1000\nidx1 = r.randint(X1.shape[0], size=(nb,))\nidx2 = r.randint(X2.shape[0], size=(nb,))\n\nXs = X1[idx1, :]\nXt = X2[idx2, :]" - ], - "outputs": [], + "cell_type": "code", + "execution_count": null, "metadata": { "collapsed": false - } - }, + }, + "outputs": [], + "source": [ + "# Loading images\nI1 = ndimage.imread('../data/ocean_day.jpg').astype(np.float64) / 256\nI2 = ndimage.imread('../data/ocean_sunset.jpg').astype(np.float64) / 256\n\n\nX1 = im2mat(I1)\nX2 = im2mat(I2)\n\n# training samples\nnb = 1000\nidx1 = r.randint(X1.shape[0], size=(nb,))\nidx2 = r.randint(X2.shape[0], size=(nb,))\n\nXs = X1[idx1, :]\nXt = X2[idx2, :]" + ] + }, { + "cell_type": "markdown", + "metadata": {}, "source": [ "Domain adaptation for pixel distribution transfer\n-------------------------------------------------\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, + ] + }, { - "execution_count": null, - "cell_type": "code", - "source": [ - "# EMDTransport\not_emd = ot.da.EMDTransport()\not_emd.fit(Xs=Xs, Xt=Xt)\ntransp_Xs_emd = ot_emd.transform(Xs=X1)\nImage_emd = minmax(mat2im(transp_Xs_emd, I1.shape))\n\n# SinkhornTransport\not_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1)\not_sinkhorn.fit(Xs=Xs, Xt=Xt)\ntransp_Xs_sinkhorn = ot_emd.transform(Xs=X1)\nImage_sinkhorn = minmax(mat2im(transp_Xs_sinkhorn, I1.shape))\n\not_mapping_linear = ot.da.MappingTransport(\n mu=1e0, eta=1e-8, bias=True, max_iter=20, verbose=True)\not_mapping_linear.fit(Xs=Xs, Xt=Xt)\n\nX1tl = ot_mapping_linear.transform(Xs=X1)\nImage_mapping_linear = minmax(mat2im(X1tl, I1.shape))\n\not_mapping_gaussian = ot.da.MappingTransport(\n mu=1e0, eta=1e-2, sigma=1, bias=False, max_iter=10, verbose=True)\not_mapping_gaussian.fit(Xs=Xs, Xt=Xt)\n\nX1tn = ot_mapping_gaussian.transform(Xs=X1) # use the estimated mapping\nImage_mapping_gaussian = minmax(mat2im(X1tn, I1.shape))" - ], - "outputs": [], + "cell_type": "code", + "execution_count": null, "metadata": { "collapsed": false - } - }, + }, + "outputs": [], + "source": [ + "# EMDTransport\not_emd = ot.da.EMDTransport()\not_emd.fit(Xs=Xs, Xt=Xt)\ntransp_Xs_emd = ot_emd.transform(Xs=X1)\nImage_emd = minmax(mat2im(transp_Xs_emd, I1.shape))\n\n# SinkhornTransport\not_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1)\not_sinkhorn.fit(Xs=Xs, Xt=Xt)\ntransp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=X1)\nImage_sinkhorn = minmax(mat2im(transp_Xs_sinkhorn, I1.shape))\n\not_mapping_linear = ot.da.MappingTransport(\n mu=1e0, eta=1e-8, bias=True, max_iter=20, verbose=True)\not_mapping_linear.fit(Xs=Xs, Xt=Xt)\n\nX1tl = ot_mapping_linear.transform(Xs=X1)\nImage_mapping_linear = minmax(mat2im(X1tl, I1.shape))\n\not_mapping_gaussian = ot.da.MappingTransport(\n mu=1e0, eta=1e-2, sigma=1, bias=False, max_iter=10, verbose=True)\not_mapping_gaussian.fit(Xs=Xs, Xt=Xt)\n\nX1tn = ot_mapping_gaussian.transform(Xs=X1) # use the estimated mapping\nImage_mapping_gaussian = minmax(mat2im(X1tn, I1.shape))" + ] + }, { + "cell_type": "markdown", + "metadata": {}, "source": [ "Plot original images\n--------------------\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, + ] + }, { - "execution_count": null, - "cell_type": "code", - "source": [ - "pl.figure(1, figsize=(6.4, 3))\npl.subplot(1, 2, 1)\npl.imshow(I1)\npl.axis('off')\npl.title('Image 1')\n\npl.subplot(1, 2, 2)\npl.imshow(I2)\npl.axis('off')\npl.title('Image 2')\npl.tight_layout()" - ], - "outputs": [], + "cell_type": "code", + "execution_count": null, "metadata": { "collapsed": false - } - }, + }, + "outputs": [], + "source": [ + "pl.figure(1, figsize=(6.4, 3))\npl.subplot(1, 2, 1)\npl.imshow(I1)\npl.axis('off')\npl.title('Image 1')\n\npl.subplot(1, 2, 2)\npl.imshow(I2)\npl.axis('off')\npl.title('Image 2')\npl.tight_layout()" + ] + }, { + "cell_type": "markdown", + "metadata": {}, "source": [ "Plot pixel values distribution\n------------------------------\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, + ] + }, { - "execution_count": null, - "cell_type": "code", - "source": [ - "pl.figure(2, figsize=(6.4, 5))\n\npl.subplot(1, 2, 1)\npl.scatter(Xs[:, 0], Xs[:, 2], c=Xs)\npl.axis([0, 1, 0, 1])\npl.xlabel('Red')\npl.ylabel('Blue')\npl.title('Image 1')\n\npl.subplot(1, 2, 2)\npl.scatter(Xt[:, 0], Xt[:, 2], c=Xt)\npl.axis([0, 1, 0, 1])\npl.xlabel('Red')\npl.ylabel('Blue')\npl.title('Image 2')\npl.tight_layout()" - ], - "outputs": [], + "cell_type": "code", + "execution_count": null, "metadata": { "collapsed": false - } - }, + }, + "outputs": [], + "source": [ + "pl.figure(2, figsize=(6.4, 5))\n\npl.subplot(1, 2, 1)\npl.scatter(Xs[:, 0], Xs[:, 2], c=Xs)\npl.axis([0, 1, 0, 1])\npl.xlabel('Red')\npl.ylabel('Blue')\npl.title('Image 1')\n\npl.subplot(1, 2, 2)\npl.scatter(Xt[:, 0], Xt[:, 2], c=Xt)\npl.axis([0, 1, 0, 1])\npl.xlabel('Red')\npl.ylabel('Blue')\npl.title('Image 2')\npl.tight_layout()" + ] + }, { + "cell_type": "markdown", + "metadata": {}, "source": [ "Plot transformed images\n-----------------------\n\n" - ], - "cell_type": "markdown", - "metadata": {} - }, + ] + }, { - "execution_count": null, - "cell_type": "code", - "source": [ - "pl.figure(2, figsize=(10, 5))\n\npl.subplot(2, 3, 1)\npl.imshow(I1)\npl.axis('off')\npl.title('Im. 1')\n\npl.subplot(2, 3, 4)\npl.imshow(I2)\npl.axis('off')\npl.title('Im. 2')\n\npl.subplot(2, 3, 2)\npl.imshow(Image_emd)\npl.axis('off')\npl.title('EmdTransport')\n\npl.subplot(2, 3, 5)\npl.imshow(Image_sinkhorn)\npl.axis('off')\npl.title('SinkhornTransport')\n\npl.subplot(2, 3, 3)\npl.imshow(Image_mapping_linear)\npl.axis('off')\npl.title('MappingTransport (linear)')\n\npl.subplot(2, 3, 6)\npl.imshow(Image_mapping_gaussian)\npl.axis('off')\npl.title('MappingTransport (gaussian)')\npl.tight_layout()\n\npl.show()" - ], - "outputs": [], + "cell_type": "code", + "execution_count": null, "metadata": { "collapsed": false - } + }, + "outputs": [], + "source": [ + "pl.figure(2, figsize=(10, 5))\n\npl.subplot(2, 3, 1)\npl.imshow(I1)\npl.axis('off')\npl.title('Im. 1')\n\npl.subplot(2, 3, 4)\npl.imshow(I2)\npl.axis('off')\npl.title('Im. 2')\n\npl.subplot(2, 3, 2)\npl.imshow(Image_emd)\npl.axis('off')\npl.title('EmdTransport')\n\npl.subplot(2, 3, 5)\npl.imshow(Image_sinkhorn)\npl.axis('off')\npl.title('SinkhornTransport')\n\npl.subplot(2, 3, 3)\npl.imshow(Image_mapping_linear)\npl.axis('off')\npl.title('MappingTransport (linear)')\n\npl.subplot(2, 3, 6)\npl.imshow(Image_mapping_gaussian)\npl.axis('off')\npl.title('MappingTransport (gaussian)')\npl.tight_layout()\n\npl.show()" + ] } - ], + ], "metadata": { "kernelspec": { - "display_name": "Python 2", - "name": "python2", - "language": "python" - }, + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, "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" - } + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.7" } - } + }, + "nbformat": 4, + "nbformat_minor": 0 } \ No newline at end of file diff --git a/docs/source/auto_examples/plot_otda_mapping_colors_images.py b/docs/source/auto_examples/plot_otda_mapping_colors_images.py index 5f1e844..a20eca8 100644 --- a/docs/source/auto_examples/plot_otda_mapping_colors_images.py +++ b/docs/source/auto_examples/plot_otda_mapping_colors_images.py @@ -77,7 +77,7 @@ Image_emd = minmax(mat2im(transp_Xs_emd, I1.shape)) # SinkhornTransport ot_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1) ot_sinkhorn.fit(Xs=Xs, Xt=Xt) -transp_Xs_sinkhorn = ot_emd.transform(Xs=X1) +transp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=X1) Image_sinkhorn = minmax(mat2im(transp_Xs_sinkhorn, I1.shape)) ot_mapping_linear = ot.da.MappingTransport( diff --git a/docs/source/auto_examples/plot_otda_mapping_colors_images.rst b/docs/source/auto_examples/plot_otda_mapping_colors_images.rst index 8394fb0..2afdc8a 100644 --- a/docs/source/auto_examples/plot_otda_mapping_colors_images.rst +++ b/docs/source/auto_examples/plot_otda_mapping_colors_images.rst @@ -104,7 +104,7 @@ Domain adaptation for pixel distribution transfer # SinkhornTransport ot_sinkhorn = ot.da.SinkhornTransport(reg_e=1e-1) ot_sinkhorn.fit(Xs=Xs, Xt=Xt) - transp_Xs_sinkhorn = ot_emd.transform(Xs=X1) + transp_Xs_sinkhorn = ot_sinkhorn.transform(Xs=X1) Image_sinkhorn = minmax(mat2im(transp_Xs_sinkhorn, I1.shape)) ot_mapping_linear = ot.da.MappingTransport( @@ -132,39 +132,39 @@ Domain adaptation for pixel distribution transfer It. |Loss |Delta loss -------------------------------- - 0|3.680518e+02|0.000000e+00 - 1|3.592439e+02|-2.393116e-02 - 2|3.590632e+02|-5.030248e-04 - 3|3.589698e+02|-2.601358e-04 - 4|3.589118e+02|-1.614977e-04 - 5|3.588724e+02|-1.097608e-04 - 6|3.588436e+02|-8.035205e-05 - 7|3.588215e+02|-6.141923e-05 - 8|3.588042e+02|-4.832627e-05 - 9|3.587902e+02|-3.909574e-05 - 10|3.587786e+02|-3.225418e-05 - 11|3.587688e+02|-2.712592e-05 - 12|3.587605e+02|-2.314041e-05 - 13|3.587534e+02|-1.991287e-05 - 14|3.587471e+02|-1.744348e-05 - 15|3.587416e+02|-1.544523e-05 - 16|3.587367e+02|-1.364654e-05 - 17|3.587323e+02|-1.230435e-05 - 18|3.587284e+02|-1.093370e-05 - 19|3.587276e+02|-2.052728e-06 + 0|3.680534e+02|0.000000e+00 + 1|3.592501e+02|-2.391854e-02 + 2|3.590682e+02|-5.061555e-04 + 3|3.589745e+02|-2.610227e-04 + 4|3.589167e+02|-1.611644e-04 + 5|3.588768e+02|-1.109242e-04 + 6|3.588482e+02|-7.972733e-05 + 7|3.588261e+02|-6.166174e-05 + 8|3.588086e+02|-4.871697e-05 + 9|3.587946e+02|-3.919056e-05 + 10|3.587830e+02|-3.228124e-05 + 11|3.587731e+02|-2.744744e-05 + 12|3.587648e+02|-2.334451e-05 + 13|3.587576e+02|-1.995629e-05 + 14|3.587513e+02|-1.761058e-05 + 15|3.587457e+02|-1.542568e-05 + 16|3.587408e+02|-1.366315e-05 + 17|3.587365e+02|-1.221732e-05 + 18|3.587325e+02|-1.102488e-05 + 19|3.587303e+02|-6.062107e-06 It. |Loss |Delta loss -------------------------------- - 0|3.784758e+02|0.000000e+00 - 1|3.646352e+02|-3.656911e-02 - 2|3.642861e+02|-9.574714e-04 - 3|3.641523e+02|-3.672061e-04 - 4|3.640788e+02|-2.020990e-04 - 5|3.640321e+02|-1.282701e-04 - 6|3.640002e+02|-8.751240e-05 - 7|3.639765e+02|-6.521203e-05 - 8|3.639582e+02|-5.007767e-05 - 9|3.639439e+02|-3.938917e-05 - 10|3.639323e+02|-3.187865e-05 + 0|3.784871e+02|0.000000e+00 + 1|3.646491e+02|-3.656142e-02 + 2|3.642975e+02|-9.642655e-04 + 3|3.641626e+02|-3.702413e-04 + 4|3.640888e+02|-2.026301e-04 + 5|3.640419e+02|-1.289607e-04 + 6|3.640097e+02|-8.831646e-05 + 7|3.639861e+02|-6.487612e-05 + 8|3.639679e+02|-4.994063e-05 + 9|3.639536e+02|-3.941436e-05 + 10|3.639419e+02|-3.209753e-05 Plot original images @@ -283,11 +283,13 @@ Plot transformed images -**Total running time of the script:** ( 2 minutes 52.212 seconds) +**Total running time of the script:** ( 3 minutes 14.206 seconds) -.. container:: sphx-glr-footer +.. only :: html + + .. container:: sphx-glr-footer .. container:: sphx-glr-download @@ -300,6 +302,9 @@ Plot transformed images :download:`Download Jupyter notebook: plot_otda_mapping_colors_images.ipynb ` -.. rst-class:: sphx-glr-signature - `Generated by Sphinx-Gallery `_ +.. only:: html + + .. rst-class:: sphx-glr-signature + + `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/source/auto_examples/plot_stochastic.ipynb b/docs/source/auto_examples/plot_stochastic.ipynb index c6f0013..7f6ff3d 100644 --- a/docs/source/auto_examples/plot_stochastic.ipynb +++ b/docs/source/auto_examples/plot_stochastic.ipynb @@ -33,25 +33,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "COMPUTE TRANSPORTATION MATRIX FOR SEMI-DUAL PROBLEM\n############################################################################\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "print(\"------------SEMI-DUAL PROBLEM------------\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "DISCRETE CASE\nSample two discrete measures for the discrete case\n---------------------------------------------\n\nDefine 2 discrete measures a and b, the points where are defined the source\nand the target measures and finally the cost matrix c.\n\n" + "COMPUTE TRANSPORTATION MATRIX FOR SEMI-DUAL PROBLEM\n############################################################################\n############################################################################\n DISCRETE CASE:\n\n Sample two discrete measures for the discrete case\n ---------------------------------------------\n\n Define 2 discrete measures a and b, the points where are defined the source\n and the target measures and finally the cost matrix c.\n\n" ] }, { @@ -87,7 +69,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "SEMICONTINOUS CASE\nSample one general measure a, one discrete measures b for the semicontinous\ncase\n---------------------------------------------\n\nDefine one general measure a, one discrete measures b, the points where\nare defined the source and the target measures and finally the cost matrix c.\n\n" + "SEMICONTINOUS CASE:\n\nSample one general measure a, one discrete measures b for the semicontinous\ncase\n---------------------------------------------\n\nDefine one general measure a, one discrete measures b, the points where\nare defined the source and the target measures and finally the cost matrix c.\n\n" ] }, { @@ -202,25 +184,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "COMPUTE TRANSPORTATION MATRIX FOR DUAL PROBLEM\n############################################################################\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "print(\"------------DUAL PROBLEM------------\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "SEMICONTINOUS CASE\nSample one general measure a, one discrete measures b for the semicontinous\ncase\n---------------------------------------------\n\nDefine one general measure a, one discrete measures b, the points where\nare defined the source and the target measures and finally the cost matrix c.\n\n" + "COMPUTE TRANSPORTATION MATRIX FOR DUAL PROBLEM\n############################################################################\n############################################################################\n SEMICONTINOUS CASE:\n\n Sample one general measure a, one discrete measures b for the semicontinous\n case\n ---------------------------------------------\n\n Define one general measure a, one discrete measures b, the points where\n are defined the source and the target measures and finally the cost matrix c.\n\n" ] }, { @@ -323,7 +287,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.7" } }, "nbformat": 4, diff --git a/docs/source/auto_examples/plot_stochastic.py b/docs/source/auto_examples/plot_stochastic.py index b9375d4..742f8d9 100644 --- a/docs/source/auto_examples/plot_stochastic.py +++ b/docs/source/auto_examples/plot_stochastic.py @@ -21,9 +21,9 @@ import ot.plot ############################################################################# # COMPUTE TRANSPORTATION MATRIX FOR SEMI-DUAL PROBLEM ############################################################################# -print("------------SEMI-DUAL PROBLEM------------") ############################################################################# -# DISCRETE CASE +# DISCRETE CASE: +# # Sample two discrete measures for the discrete case # --------------------------------------------- # @@ -57,7 +57,8 @@ sag_pi = ot.stochastic.solve_semi_dual_entropic(a, b, M, reg, method, print(sag_pi) ############################################################################# -# SEMICONTINOUS CASE +# SEMICONTINOUS CASE: +# # Sample one general measure a, one discrete measures b for the semicontinous # case # --------------------------------------------- @@ -139,9 +140,9 @@ pl.show() ############################################################################# # COMPUTE TRANSPORTATION MATRIX FOR DUAL PROBLEM ############################################################################# -print("------------DUAL PROBLEM------------") ############################################################################# -# SEMICONTINOUS CASE +# SEMICONTINOUS CASE: +# # Sample one general measure a, one discrete measures b for the semicontinous # case # --------------------------------------------- diff --git a/docs/source/auto_examples/plot_stochastic.rst b/docs/source/auto_examples/plot_stochastic.rst index a49bc05..d531045 100644 --- a/docs/source/auto_examples/plot_stochastic.rst +++ b/docs/source/auto_examples/plot_stochastic.rst @@ -34,29 +34,14 @@ algorithms for descrete and semicontinous measures from the POT library. COMPUTE TRANSPORTATION MATRIX FOR SEMI-DUAL PROBLEM ############################################################################ +############################################################################ + DISCRETE CASE: + Sample two discrete measures for the discrete case + --------------------------------------------- - -.. code-block:: python - - print("------------SEMI-DUAL PROBLEM------------") - - - - -.. rst-class:: sphx-glr-script-out - - Out:: - - ------------SEMI-DUAL PROBLEM------------ - - -DISCRETE CASE -Sample two discrete measures for the discrete case ---------------------------------------------- - -Define 2 discrete measures a and b, the points where are defined the source -and the target measures and finally the cost matrix c. + Define 2 discrete measures a and b, the points where are defined the source + and the target measures and finally the cost matrix c. @@ -115,7 +100,8 @@ results. [4.15462212e-02 2.65987989e-02 7.23177216e-02 2.39440107e-03]] -SEMICONTINOUS CASE +SEMICONTINOUS CASE: + Sample one general measure a, one discrete measures b for the semicontinous case --------------------------------------------- @@ -174,15 +160,15 @@ results. Out:: - [3.9018759 7.63059124 3.93260224 2.67274989 1.43888443 3.26904884 - 2.78748299] [-2.48511647 -2.43621119 -0.93585194 5.8571796 ] - [[2.56614773e-02 9.96758169e-02 1.75151781e-02 4.67049862e-06] - [1.21201047e-01 1.24433535e-02 1.28173754e-03 7.93100436e-03] - [3.58778167e-03 7.64232233e-02 6.28459924e-02 1.45441936e-07] - [2.63551754e-02 3.35577920e-02 8.25011211e-02 4.43054320e-04] - [9.24518246e-03 7.03074064e-04 1.00325744e-02 1.22876312e-01] - [2.03656325e-02 8.45420425e-04 1.73604569e-03 1.19910044e-01] - [4.17781688e-02 2.66463708e-02 7.18353075e-02 2.59729583e-03]] + [3.98220325 7.76235856 3.97645524 2.72051681 1.23219313 3.07696856 + 2.84476972] [-2.65544161 -2.50838395 -0.9397765 6.10360206] + [[2.34528761e-02 1.00491956e-01 1.89058354e-02 6.47543413e-06] + [1.16616747e-01 1.32074516e-02 1.45653361e-03 1.15764107e-02] + [3.16154850e-03 7.42892944e-02 6.54061055e-02 1.94426150e-07] + [2.33152216e-02 3.27486992e-02 8.61986263e-02 5.94595747e-04] + [6.34131496e-03 5.31975896e-04 8.12724003e-03 1.27856612e-01] + [1.41744829e-02 6.49096245e-04 1.42704389e-03 1.26606520e-01] + [3.73127657e-02 2.62526499e-02 7.57727161e-02 3.51901117e-03]] Compare the results with the Sinkhorn algorithm @@ -288,30 +274,15 @@ Plot Sinkhorn results COMPUTE TRANSPORTATION MATRIX FOR DUAL PROBLEM ############################################################################ +############################################################################ + SEMICONTINOUS CASE: + Sample one general measure a, one discrete measures b for the semicontinous + case + --------------------------------------------- - -.. code-block:: python - - print("------------DUAL PROBLEM------------") - - - - -.. rst-class:: sphx-glr-script-out - - Out:: - - ------------DUAL PROBLEM------------ - - -SEMICONTINOUS CASE -Sample one general measure a, one discrete measures b for the semicontinous -case ---------------------------------------------- - -Define one general measure a, one discrete measures b, the points where -are defined the source and the target measures and finally the cost matrix c. + Define one general measure a, one discrete measures b, the points where + are defined the source and the target measures and finally the cost matrix c. @@ -365,15 +336,15 @@ Call ot.solve_dual_entropic and plot the results. Out:: - [ 1.29325617 5.0435082 1.30996326 0.05538236 -1.08113283 0.73711558 - 0.18086364] [0.08840343 0.17710082 1.68604226 8.37377551] - [[2.47763879e-02 1.00144623e-01 1.77492330e-02 4.25988443e-06] - [1.19568278e-01 1.27740478e-02 1.32714202e-03 7.39121816e-03] - [3.41581121e-03 7.57137404e-02 6.27992039e-02 1.30808430e-07] - [2.52245323e-02 3.34219732e-02 8.28754229e-02 4.00582912e-04] - [9.75329554e-03 7.71824343e-04 1.11085400e-02 1.22456628e-01] - [2.12304276e-02 9.17096580e-04 1.89946234e-03 1.18084973e-01] - [4.04179693e-02 2.68253041e-02 7.29410047e-02 2.37369404e-03]] + [0.92449986 2.75486107 1.07923806 0.02741145 0.61355413 1.81961594 + 0.12072562] [0.33831611 0.46806842 1.5640451 4.96947652] + [[2.20001105e-02 9.26497883e-02 1.08654588e-02 9.78995555e-08] + [1.55669974e-02 1.73279561e-03 1.19120878e-04 2.49058251e-05] + [3.48198483e-03 8.04151063e-02 4.41335396e-02 3.45115752e-09] + [3.14927954e-02 4.34760520e-02 7.13338154e-02 1.29442395e-05] + [6.81836550e-02 5.62182457e-03 5.35386584e-02 2.21568095e-02] + [8.04671052e-02 3.62163462e-03 4.96331605e-03 1.15837801e-02] + [4.88644009e-02 3.37903481e-02 6.07955004e-02 7.42743505e-05]] Compare the results with the Sinkhorn algorithm @@ -448,7 +419,7 @@ Plot Sinkhorn results -**Total running time of the script:** ( 0 minutes 22.857 seconds) +**Total running time of the script:** ( 0 minutes 20.889 seconds) -- cgit v1.2.3