summaryrefslogtreecommitdiff
path: root/docs/source/auto_examples
diff options
context:
space:
mode:
authorRémi Flamary <remi.flamary@gmail.com>2018-02-16 15:13:59 +0100
committerRémi Flamary <remi.flamary@gmail.com>2018-02-16 15:13:59 +0100
commitbf78141c8849cce9b94a4e518bd6c7360e66f8dd (patch)
tree0642f657ee807b0def96e63faf86ebec98a31af7 /docs/source/auto_examples
parentfead9d6186020fdd37e167ddfa7a91c405188ce7 (diff)
update notebooks
Diffstat (limited to 'docs/source/auto_examples')
-rw-r--r--docs/source/auto_examples/auto_examples_jupyter.zipbin85906 -> 86995 bytes
-rw-r--r--docs/source/auto_examples/auto_examples_python.zipbin58682 -> 58992 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_gromov_001.pngbin16548 -> 45460 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_gromov_002.pngbin17330 -> 17362 bytes
-rw-r--r--docs/source/auto_examples/images/sphx_glr_plot_gromov_003.pngbin16530 -> 18617 bytes
-rw-r--r--docs/source/auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.pngbin17804 -> 25219 bytes
-rw-r--r--docs/source/auto_examples/index.rst32
-rw-r--r--docs/source/auto_examples/plot_gromov.ipynb120
-rw-r--r--docs/source/auto_examples/plot_gromov.py7
-rw-r--r--docs/source/auto_examples/plot_gromov.rst156
10 files changed, 208 insertions, 107 deletions
diff --git a/docs/source/auto_examples/auto_examples_jupyter.zip b/docs/source/auto_examples/auto_examples_jupyter.zip
index 42f42de..4703026 100644
--- a/docs/source/auto_examples/auto_examples_jupyter.zip
+++ b/docs/source/auto_examples/auto_examples_jupyter.zip
Binary files 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
--- a/docs/source/auto_examples/auto_examples_python.zip
+++ b/docs/source/auto_examples/auto_examples_python.zip
Binary files 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
--- a/docs/source/auto_examples/images/sphx_glr_plot_gromov_001.png
+++ b/docs/source/auto_examples/images/sphx_glr_plot_gromov_001.png
Binary files 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
--- a/docs/source/auto_examples/images/sphx_glr_plot_gromov_002.png
+++ b/docs/source/auto_examples/images/sphx_glr_plot_gromov_002.png
Binary files 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
--- a/docs/source/auto_examples/images/sphx_glr_plot_gromov_003.png
+++ b/docs/source/auto_examples/images/sphx_glr_plot_gromov_003.png
Binary files 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
--- 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
Binary files 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
- <div class="sphx-glr-thumbcontainer" tooltip="Illustration of 2D optimal transport between discributions that are weighted sum of diracs. The...">
+ <div class="sphx-glr-thumbcontainer" tooltip="This example is designed to show how to use the Gromov-Wassertsein distance computation in POT....">
.. 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
- <div class="sphx-glr-thumbcontainer" tooltip="Shows how to compute multiple EMD and Sinkhorn with two differnt ground metrics and plot their ...">
+ <div class="sphx-glr-thumbcontainer" tooltip="Illustration of 2D optimal transport between discributions that are weighted sum of diracs. The...">
.. 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
- <div class="sphx-glr-thumbcontainer" tooltip="This example illustrate the use of WDA as proposed in [11].">
+ <div class="sphx-glr-thumbcontainer" tooltip="Shows how to compute multiple EMD and Sinkhorn with two differnt ground metrics and plot their ...">
.. 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
- <div class="sphx-glr-thumbcontainer" tooltip="This example is designed to show how to use the Gromov-Wassertsein distance computation in POT....">
+ <div class="sphx-glr-thumbcontainer" tooltip="This example illustrate the use of WDA as proposed in [11].">
.. 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 <erwan.vautier@gmail.com>\n# Nicolas Courty <ncourty@irisa.fr>\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 <erwan.vautier@gmail.com>\n# Nicolas Courty <ncourty@irisa.fr>\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 <erwan.vautier@gmail.com>
+ # Nicolas Courty <ncourty@irisa.fr>
+ #
+ # 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 <erwan.vautier@gmail.com>
- # Nicolas Courty <ncourty@irisa.fr>
- #
- # 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)