From bf78141c8849cce9b94a4e518bd6c7360e66f8dd Mon Sep 17 00:00:00 2001 From: RĂ©mi Flamary Date: Fri, 16 Feb 2018 15:13:59 +0100 Subject: update notebooks --- .../source/auto_examples/auto_examples_jupyter.zip | Bin 85906 -> 86995 bytes docs/source/auto_examples/auto_examples_python.zip | Bin 58682 -> 58992 bytes .../images/sphx_glr_plot_gromov_001.png | Bin 16548 -> 45460 bytes .../images/sphx_glr_plot_gromov_002.png | Bin 17330 -> 17362 bytes .../images/sphx_glr_plot_gromov_003.png | Bin 16530 -> 18617 bytes .../images/thumb/sphx_glr_plot_gromov_thumb.png | Bin 17804 -> 25219 bytes docs/source/auto_examples/index.rst | 32 ++--- docs/source/auto_examples/plot_gromov.ipynb | 120 ++++++++++++---- docs/source/auto_examples/plot_gromov.py | 7 +- docs/source/auto_examples/plot_gromov.rst | 156 ++++++++++++--------- 10 files changed, 208 insertions(+), 107 deletions(-) (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 42f42de..4703026 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 0fb2cda..7c7ff86 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_gromov_001.png b/docs/source/auto_examples/images/sphx_glr_plot_gromov_001.png index 09864f2..8672249 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_gromov_001.png and b/docs/source/auto_examples/images/sphx_glr_plot_gromov_001.png differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_gromov_002.png b/docs/source/auto_examples/images/sphx_glr_plot_gromov_002.png index b2e3fa4..c4eb8e0 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_gromov_002.png and b/docs/source/auto_examples/images/sphx_glr_plot_gromov_002.png differ diff --git a/docs/source/auto_examples/images/sphx_glr_plot_gromov_003.png b/docs/source/auto_examples/images/sphx_glr_plot_gromov_003.png index 73a322d..c17d386 100644 Binary files a/docs/source/auto_examples/images/sphx_glr_plot_gromov_003.png and b/docs/source/auto_examples/images/sphx_glr_plot_gromov_003.png differ diff --git a/docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.png b/docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.png index c54f6b3..210c010 100644 Binary files a/docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.png and b/docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.png differ diff --git a/docs/source/auto_examples/index.rst b/docs/source/auto_examples/index.rst index 227c40c..9d7c0f0 100644 --- a/docs/source/auto_examples/index.rst +++ b/docs/source/auto_examples/index.rst @@ -49,13 +49,13 @@ This is a gallery of all the POT example files. .. raw:: html -
+
.. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_OT_2D_samples_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.png - :ref:`sphx_glr_auto_examples_plot_OT_2D_samples.py` + :ref:`sphx_glr_auto_examples_plot_gromov.py` .. raw:: html @@ -65,17 +65,17 @@ This is a gallery of all the POT example files. .. toctree:: :hidden: - /auto_examples/plot_OT_2D_samples + /auto_examples/plot_gromov .. raw:: html -
+
.. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_compute_emd_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_OT_2D_samples_thumb.png - :ref:`sphx_glr_auto_examples_plot_compute_emd.py` + :ref:`sphx_glr_auto_examples_plot_OT_2D_samples.py` .. raw:: html @@ -85,17 +85,17 @@ This is a gallery of all the POT example files. .. toctree:: :hidden: - /auto_examples/plot_compute_emd + /auto_examples/plot_OT_2D_samples .. raw:: html -
+
.. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_WDA_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_compute_emd_thumb.png - :ref:`sphx_glr_auto_examples_plot_WDA.py` + :ref:`sphx_glr_auto_examples_plot_compute_emd.py` .. raw:: html @@ -105,17 +105,17 @@ This is a gallery of all the POT example files. .. toctree:: :hidden: - /auto_examples/plot_WDA + /auto_examples/plot_compute_emd .. raw:: html -
+
.. only:: html - .. figure:: /auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.png + .. figure:: /auto_examples/images/thumb/sphx_glr_plot_WDA_thumb.png - :ref:`sphx_glr_auto_examples_plot_gromov.py` + :ref:`sphx_glr_auto_examples_plot_WDA.py` .. raw:: html @@ -125,7 +125,7 @@ This is a gallery of all the POT example files. .. toctree:: :hidden: - /auto_examples/plot_gromov + /auto_examples/plot_WDA .. raw:: html diff --git a/docs/source/auto_examples/plot_gromov.ipynb b/docs/source/auto_examples/plot_gromov.ipynb index 6d6b522..57d6a4a 100644 --- a/docs/source/auto_examples/plot_gromov.ipynb +++ b/docs/source/auto_examples/plot_gromov.ipynb @@ -1,54 +1,126 @@ { + "nbformat_minor": 0, + "nbformat": 4, + "metadata": { + "language_info": { + "file_extension": ".py", + "codemirror_mode": { + "version": 3, + "name": "ipython" + }, + "nbconvert_exporter": "python", + "mimetype": "text/x-python", + "version": "3.5.2", + "name": "python", + "pygments_lexer": "ipython3" + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3", + "language": "python" + } + }, "cells": [ { + "outputs": [], + "source": [ + "%matplotlib inline" + ], "execution_count": null, "metadata": { "collapsed": false }, + "cell_type": "code" + }, + { + "source": [ + "\n# Gromov-Wasserstein example\n\n\nThis example is designed to show how to use the Gromov-Wassertsein distance\ncomputation in POT.\n\n" + ], + "metadata": {}, + "cell_type": "markdown" + }, + { "outputs": [], "source": [ - "%matplotlib inline" + "# Author: Erwan Vautier \n# Nicolas Courty \n#\n# License: MIT License\n\nimport scipy as sp\nimport numpy as np\nimport matplotlib.pylab as pl\nfrom mpl_toolkits.mplot3d import Axes3D # noqa\nimport ot" ], + "execution_count": null, + "metadata": { + "collapsed": false + }, "cell_type": "code" }, { - "metadata": {}, "source": [ - "\n# Gromov-Wasserstein example\n\n\nThis example is designed to show how to use the Gromov-Wassertsein distance\ncomputation in POT.\n\n" + "Sample two Gaussian distributions (2D and 3D)\n---------------------------------------------\n\nThe Gromov-Wasserstein distance allows to compute distances with samples that\ndo not belong to the same metric space. For demonstration purpose, we sample\ntwo Gaussian distributions in 2- and 3-dimensional spaces.\n\n" ], + "metadata": {}, "cell_type": "markdown" }, { + "outputs": [], + "source": [ + "n_samples = 30 # nb samples\n\nmu_s = np.array([0, 0])\ncov_s = np.array([[1, 0], [0, 1]])\n\nmu_t = np.array([4, 4, 4])\ncov_t = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])\n\n\nxs = ot.datasets.get_2D_samples_gauss(n_samples, mu_s, cov_s)\nP = sp.linalg.sqrtm(cov_t)\nxt = np.random.randn(n_samples, 3).dot(P) + mu_t" + ], "execution_count": null, "metadata": { "collapsed": false }, + "cell_type": "code" + }, + { + "source": [ + "Plotting the distributions\n--------------------------\n\n" + ], + "metadata": {}, + "cell_type": "markdown" + }, + { "outputs": [], "source": [ - "# Author: Erwan Vautier \n# Nicolas Courty \n#\n# License: MIT License\n\nimport scipy as sp\nimport numpy as np\nimport matplotlib.pylab as pl\nfrom mpl_toolkits.mplot3d import Axes3D # noqa\nimport ot\n\n\n#\n# Sample two Gaussian distributions (2D and 3D)\n# ---------------------------------------------\n#\n# The Gromov-Wasserstein distance allows to compute distances with samples that\n# do not belong to the same metric space. For demonstration purpose, we sample\n# two Gaussian distributions in 2- and 3-dimensional spaces.\n\n\nn_samples = 30 # nb samples\n\nmu_s = np.array([0, 0])\ncov_s = np.array([[1, 0], [0, 1]])\n\nmu_t = np.array([4, 4, 4])\ncov_t = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])\n\n\nxs = ot.datasets.get_2D_samples_gauss(n_samples, mu_s, cov_s)\nP = sp.linalg.sqrtm(cov_t)\nxt = np.random.randn(n_samples, 3).dot(P) + mu_t\n\n\n#\n# Plotting the distributions\n# --------------------------\n\n\nfig = pl.figure()\nax1 = fig.add_subplot(121)\nax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\nax2 = fig.add_subplot(122, projection='3d')\nax2.scatter(xt[:, 0], xt[:, 1], xt[:, 2], color='r')\npl.show()\n\n\n#\n# Compute distance kernels, normalize them and then display\n# ---------------------------------------------------------\n\n\nC1 = sp.spatial.distance.cdist(xs, xs)\nC2 = sp.spatial.distance.cdist(xt, xt)\n\nC1 /= C1.max()\nC2 /= C2.max()\n\npl.figure()\npl.subplot(121)\npl.imshow(C1)\npl.subplot(122)\npl.imshow(C2)\npl.show()\n\n#\n# Compute Gromov-Wasserstein plans and distance\n# ---------------------------------------------\n\np = ot.unif(n_samples)\nq = ot.unif(n_samples)\n\ngw0, log0 = ot.gromov.gromov_wasserstein(\n C1, C2, p, q, 'square_loss', verbose=True, log=True)\n\ngw, log = ot.gromov.entropic_gromov_wasserstein(\n C1, C2, p, q, 'square_loss', epsilon=5e-4, log=True, verbose=True)\n\n\nprint('Gromov-Wasserstein distances: ' + str(log0['gw_dist']))\nprint('Entropic Gromov-Wasserstein distances: ' + str(log['gw_dist']))\n\n\npl.figure(1, (10, 5))\n\npl.subplot(1, 2, 1)\npl.imshow(gw0, cmap='jet')\npl.title('Gromov Wasserstein')\n\npl.subplot(1, 2, 2)\npl.imshow(gw, cmap='jet')\npl.title('Entropic Gromov Wasserstein')\n\npl.show()" + "fig = pl.figure()\nax1 = fig.add_subplot(121)\nax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')\nax2 = fig.add_subplot(122, projection='3d')\nax2.scatter(xt[:, 0], xt[:, 1], xt[:, 2], color='r')\npl.show()" ], + "execution_count": null, + "metadata": { + "collapsed": false + }, "cell_type": "code" - } - ], - "metadata": { - "language_info": { - "name": "python", - "codemirror_mode": { - "name": "ipython", - "version": 3 + }, + { + "source": [ + "Compute distance kernels, normalize them and then display\n---------------------------------------------------------\n\n" + ], + "metadata": {}, + "cell_type": "markdown" + }, + { + "outputs": [], + "source": [ + "C1 = sp.spatial.distance.cdist(xs, xs)\nC2 = sp.spatial.distance.cdist(xt, xt)\n\nC1 /= C1.max()\nC2 /= C2.max()\n\npl.figure()\npl.subplot(121)\npl.imshow(C1)\npl.subplot(122)\npl.imshow(C2)\npl.show()" + ], + "execution_count": null, + "metadata": { + "collapsed": false }, - "nbconvert_exporter": "python", - "version": "3.5.2", - "pygments_lexer": "ipython3", - "file_extension": ".py", - "mimetype": "text/x-python" + "cell_type": "code" }, - "kernelspec": { - "display_name": "Python 3", - "name": "python3", - "language": "python" + { + "source": [ + "Compute Gromov-Wasserstein plans and distance\n---------------------------------------------\n\n" + ], + "metadata": {}, + "cell_type": "markdown" + }, + { + "outputs": [], + "source": [ + "p = ot.unif(n_samples)\nq = ot.unif(n_samples)\n\ngw0, log0 = ot.gromov.gromov_wasserstein(\n C1, C2, p, q, 'square_loss', verbose=True, log=True)\n\ngw, log = ot.gromov.entropic_gromov_wasserstein(\n C1, C2, p, q, 'square_loss', epsilon=5e-4, log=True, verbose=True)\n\n\nprint('Gromov-Wasserstein distances: ' + str(log0['gw_dist']))\nprint('Entropic Gromov-Wasserstein distances: ' + str(log['gw_dist']))\n\n\npl.figure(1, (10, 5))\n\npl.subplot(1, 2, 1)\npl.imshow(gw0, cmap='jet')\npl.title('Gromov Wasserstein')\n\npl.subplot(1, 2, 2)\npl.imshow(gw, cmap='jet')\npl.title('Entropic Gromov Wasserstein')\n\npl.show()" + ], + "execution_count": null, + "metadata": { + "collapsed": false + }, + "cell_type": "code" } - }, - "nbformat_minor": 0, - "nbformat": 4 + ] } \ No newline at end of file diff --git a/docs/source/auto_examples/plot_gromov.py b/docs/source/auto_examples/plot_gromov.py index 9188da9..5cd40f6 100644 --- a/docs/source/auto_examples/plot_gromov.py +++ b/docs/source/auto_examples/plot_gromov.py @@ -19,7 +19,7 @@ import matplotlib.pylab as pl from mpl_toolkits.mplot3d import Axes3D # noqa import ot - +############################################################################# # # Sample two Gaussian distributions (2D and 3D) # --------------------------------------------- @@ -42,7 +42,7 @@ xs = ot.datasets.get_2D_samples_gauss(n_samples, mu_s, cov_s) P = sp.linalg.sqrtm(cov_t) xt = np.random.randn(n_samples, 3).dot(P) + mu_t - +############################################################################# # # Plotting the distributions # -------------------------- @@ -55,7 +55,7 @@ ax2 = fig.add_subplot(122, projection='3d') ax2.scatter(xt[:, 0], xt[:, 1], xt[:, 2], color='r') pl.show() - +############################################################################# # # Compute distance kernels, normalize them and then display # --------------------------------------------------------- @@ -74,6 +74,7 @@ pl.subplot(122) pl.imshow(C2) pl.show() +############################################################################# # # Compute Gromov-Wasserstein plans and distance # --------------------------------------------- diff --git a/docs/source/auto_examples/plot_gromov.rst b/docs/source/auto_examples/plot_gromov.rst index ad29f7a..131861f 100644 --- a/docs/source/auto_examples/plot_gromov.rst +++ b/docs/source/auto_examples/plot_gromov.rst @@ -12,77 +12,38 @@ computation in POT. +.. code-block:: python -.. rst-class:: sphx-glr-horizontal - - - * - .. image:: /auto_examples/images/sphx_glr_plot_gromov_001.png - :scale: 47 + # Author: Erwan Vautier + # Nicolas Courty + # + # License: MIT License - * + import scipy as sp + import numpy as np + import matplotlib.pylab as pl + from mpl_toolkits.mplot3d import Axes3D # noqa + import ot - .. image:: /auto_examples/images/sphx_glr_plot_gromov_002.png - :scale: 47 -.. rst-class:: sphx-glr-script-out - Out:: - It. |Loss |Delta loss - -------------------------------- - 0|4.042674e-02|0.000000e+00 - 1|2.432476e-02|-6.619583e-01 - 2|2.170023e-02|-1.209448e-01 - 3|1.941223e-02|-1.178640e-01 - 4|1.823606e-02|-6.449667e-02 - 5|1.446641e-02|-2.605800e-01 - 6|1.184011e-02|-2.218140e-01 - 7|1.173274e-02|-9.150805e-03 - 8|1.173127e-02|-1.253458e-04 - 9|1.173126e-02|-1.256842e-06 - 10|1.173126e-02|-1.256876e-08 - 11|1.173126e-02|-1.256885e-10 - It. |Err - ------------------- - 0|7.034302e-02| - 10|1.044218e-03| - 20|5.426783e-08| - 30|3.532029e-12| - Gromov-Wasserstein distances: 0.0117312557987 - Entropic Gromov-Wasserstein distances: 0.0101639418389 +Sample two Gaussian distributions (2D and 3D) +--------------------------------------------- +The Gromov-Wasserstein distance allows to compute distances with samples that +do not belong to the same metric space. For demonstration purpose, we sample +two Gaussian distributions in 2- and 3-dimensional spaces. -| .. code-block:: python - # Author: Erwan Vautier - # Nicolas Courty - # - # License: MIT License - - import scipy as sp - import numpy as np - import matplotlib.pylab as pl - from mpl_toolkits.mplot3d import Axes3D # noqa - import ot - - - # - # Sample two Gaussian distributions (2D and 3D) - # --------------------------------------------- - # - # The Gromov-Wasserstein distance allows to compute distances with samples that - # do not belong to the same metric space. For demonstration purpose, we sample - # two Gaussian distributions in 2- and 3-dimensional spaces. - n_samples = 30 # nb samples @@ -98,9 +59,18 @@ computation in POT. xt = np.random.randn(n_samples, 3).dot(P) + mu_t - # - # Plotting the distributions - # -------------------------- + + + + + +Plotting the distributions +-------------------------- + + + +.. code-block:: python + fig = pl.figure() @@ -111,9 +81,21 @@ computation in POT. pl.show() - # - # Compute distance kernels, normalize them and then display - # --------------------------------------------------------- + + +.. image:: /auto_examples/images/sphx_glr_plot_gromov_001.png + :align: center + + + + +Compute distance kernels, normalize them and then display +--------------------------------------------------------- + + + +.. code-block:: python + C1 = sp.spatial.distance.cdist(xs, xs) @@ -129,9 +111,22 @@ computation in POT. pl.imshow(C2) pl.show() - # - # Compute Gromov-Wasserstein plans and distance - # --------------------------------------------- + + + +.. image:: /auto_examples/images/sphx_glr_plot_gromov_002.png + :align: center + + + + +Compute Gromov-Wasserstein plans and distance +--------------------------------------------- + + + +.. code-block:: python + p = ot.unif(n_samples) q = ot.unif(n_samples) @@ -159,7 +154,40 @@ computation in POT. pl.show() -**Total running time of the script:** ( 0 minutes 1.465 seconds) + + +.. image:: /auto_examples/images/sphx_glr_plot_gromov_003.png + :align: center + + +.. rst-class:: sphx-glr-script-out + + Out:: + + It. |Loss |Delta loss + -------------------------------- + 0|4.517558e-02|0.000000e+00 + 1|2.563483e-02|-7.622736e-01 + 2|2.443903e-02|-4.892972e-02 + 3|2.231600e-02|-9.513496e-02 + 4|1.676188e-02|-3.313541e-01 + 5|1.464792e-02|-1.443180e-01 + 6|1.454315e-02|-7.204526e-03 + 7|1.454142e-02|-1.185811e-04 + 8|1.454141e-02|-1.190466e-06 + 9|1.454141e-02|-1.190512e-08 + 10|1.454141e-02|-1.190520e-10 + It. |Err + ------------------- + 0|6.743761e-02| + 10|5.477003e-04| + 20|2.461503e-08| + 30|1.205155e-11| + Gromov-Wasserstein distances: 0.014541405718693563 + Entropic Gromov-Wasserstein distances: 0.015800739725237274 + + +**Total running time of the script:** ( 0 minutes 1.448 seconds) -- cgit v1.2.3