Skip to content

Commit bf78141

Browse files
committed
update notebooks
1 parent fead9d6 commit bf78141

13 files changed

+361
-202
lines changed

docs/cache_nbrun

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"plot_otda_mapping_colors_images.ipynb": "4f0587a00a3c082799a75a0ed36e9ce1", "plot_optim_OTreg.ipynb": "2ec33a099bb67120a134332a20f29313", "plot_barycenter_1D.ipynb": "95708b025b6d96d97f579d30d268cbff", "plot_WDA.ipynb": "27f8de4c6d7db46497076523673eedfb", "plot_OT_L1_vs_L2.ipynb": "871d60931f5118c085342e11cb638336", "plot_otda_color_images.ipynb": "d047d635f4987c81072383241590e21f", "plot_otda_classes.ipynb": "44bb8cd93317b5d342cd62e26d9bbe60", "plot_otda_d2.ipynb": "1a9547f07317612e1a161b7d9f07a5a8", "plot_otda_mapping.ipynb": "d335a15af828aaa3439a1c67570d79d6", "plot_gromov.ipynb": "243e64c7d13afa8dfa10fc3ccb4e1e28", "plot_compute_emd.ipynb": "bd95981189df6adcb113d9b360ead734", "plot_OT_1D.ipynb": "54dfea8ccb61f30729519275785c494c", "plot_gromov_barycenter.ipynb": "953e5047b886ec69ec621ec52f5e21d1", "plot_otda_semi_supervised.ipynb": "0261d339a692e339e15d3634488905cc", "plot_OT_2D_samples.ipynb": "3f125714daa35ff3cfe5dae1f71265c4"}
1+
{"plot_otda_mapping_colors_images.ipynb": "4f0587a00a3c082799a75a0ed36e9ce1", "plot_optim_OTreg.ipynb": "2ec33a099bb67120a134332a20f29313", "plot_otda_color_images.ipynb": "d047d635f4987c81072383241590e21f", "plot_WDA.ipynb": "27f8de4c6d7db46497076523673eedfb", "plot_OT_L1_vs_L2.ipynb": "871d60931f5118c085342e11cb638336", "plot_barycenter_1D.ipynb": "95708b025b6d96d97f579d30d268cbff", "plot_otda_classes.ipynb": "44bb8cd93317b5d342cd62e26d9bbe60", "plot_otda_d2.ipynb": "1a9547f07317612e1a161b7d9f07a5a8", "plot_otda_mapping.ipynb": "d335a15af828aaa3439a1c67570d79d6", "plot_gromov.ipynb": "825d79eba255314fe11469c64d38fc3d", "plot_compute_emd.ipynb": "bd95981189df6adcb113d9b360ead734", "plot_OT_1D.ipynb": "54dfea8ccb61f30729519275785c494c", "plot_gromov_barycenter.ipynb": "953e5047b886ec69ec621ec52f5e21d1", "plot_otda_semi_supervised.ipynb": "0261d339a692e339e15d3634488905cc", "plot_OT_2D_samples.ipynb": "3f125714daa35ff3cfe5dae1f71265c4"}
1.06 KB
Binary file not shown.
310 Bytes
Binary file not shown.
28.2 KB
Loading
32 Bytes
Loading
2.04 KB
Loading
7.24 KB
Loading

docs/source/auto_examples/index.rst

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ This is a gallery of all the POT example files.
4949

5050
.. raw:: html
5151

52-
<div class="sphx-glr-thumbcontainer" tooltip="Illustration of 2D optimal transport between discributions that are weighted sum of diracs. The...">
52+
<div class="sphx-glr-thumbcontainer" tooltip="This example is designed to show how to use the Gromov-Wassertsein distance computation in POT....">
5353

5454
.. only:: html
5555

56-
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_OT_2D_samples_thumb.png
56+
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.png
5757

58-
:ref:`sphx_glr_auto_examples_plot_OT_2D_samples.py`
58+
:ref:`sphx_glr_auto_examples_plot_gromov.py`
5959

6060
.. raw:: html
6161

@@ -65,17 +65,17 @@ This is a gallery of all the POT example files.
6565
.. toctree::
6666
:hidden:
6767

68-
/auto_examples/plot_OT_2D_samples
68+
/auto_examples/plot_gromov
6969

7070
.. raw:: html
7171

72-
<div class="sphx-glr-thumbcontainer" tooltip="Shows how to compute multiple EMD and Sinkhorn with two differnt ground metrics and plot their ...">
72+
<div class="sphx-glr-thumbcontainer" tooltip="Illustration of 2D optimal transport between discributions that are weighted sum of diracs. The...">
7373

7474
.. only:: html
7575

76-
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_compute_emd_thumb.png
76+
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_OT_2D_samples_thumb.png
7777

78-
:ref:`sphx_glr_auto_examples_plot_compute_emd.py`
78+
:ref:`sphx_glr_auto_examples_plot_OT_2D_samples.py`
7979

8080
.. raw:: html
8181

@@ -85,17 +85,17 @@ This is a gallery of all the POT example files.
8585
.. toctree::
8686
:hidden:
8787

88-
/auto_examples/plot_compute_emd
88+
/auto_examples/plot_OT_2D_samples
8989

9090
.. raw:: html
9191

92-
<div class="sphx-glr-thumbcontainer" tooltip="This example illustrate the use of WDA as proposed in [11].">
92+
<div class="sphx-glr-thumbcontainer" tooltip="Shows how to compute multiple EMD and Sinkhorn with two differnt ground metrics and plot their ...">
9393

9494
.. only:: html
9595

96-
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_WDA_thumb.png
96+
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_compute_emd_thumb.png
9797

98-
:ref:`sphx_glr_auto_examples_plot_WDA.py`
98+
:ref:`sphx_glr_auto_examples_plot_compute_emd.py`
9999

100100
.. raw:: html
101101

@@ -105,17 +105,17 @@ This is a gallery of all the POT example files.
105105
.. toctree::
106106
:hidden:
107107

108-
/auto_examples/plot_WDA
108+
/auto_examples/plot_compute_emd
109109

110110
.. raw:: html
111111

112-
<div class="sphx-glr-thumbcontainer" tooltip="This example is designed to show how to use the Gromov-Wassertsein distance computation in POT....">
112+
<div class="sphx-glr-thumbcontainer" tooltip="This example illustrate the use of WDA as proposed in [11].">
113113

114114
.. only:: html
115115

116-
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_gromov_thumb.png
116+
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_WDA_thumb.png
117117

118-
:ref:`sphx_glr_auto_examples_plot_gromov.py`
118+
:ref:`sphx_glr_auto_examples_plot_WDA.py`
119119

120120
.. raw:: html
121121

@@ -125,7 +125,7 @@ This is a gallery of all the POT example files.
125125
.. toctree::
126126
:hidden:
127127

128-
/auto_examples/plot_gromov
128+
/auto_examples/plot_WDA
129129

130130
.. raw:: html
131131

Lines changed: 96 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,126 @@
11
{
2+
"nbformat_minor": 0,
3+
"nbformat": 4,
4+
"metadata": {
5+
"language_info": {
6+
"file_extension": ".py",
7+
"codemirror_mode": {
8+
"version": 3,
9+
"name": "ipython"
10+
},
11+
"nbconvert_exporter": "python",
12+
"mimetype": "text/x-python",
13+
"version": "3.5.2",
14+
"name": "python",
15+
"pygments_lexer": "ipython3"
16+
},
17+
"kernelspec": {
18+
"display_name": "Python 3",
19+
"name": "python3",
20+
"language": "python"
21+
}
22+
},
223
"cells": [
324
{
25+
"outputs": [],
26+
"source": [
27+
"%matplotlib inline"
28+
],
429
"execution_count": null,
530
"metadata": {
631
"collapsed": false
732
},
33+
"cell_type": "code"
34+
},
35+
{
36+
"source": [
37+
"\n# Gromov-Wasserstein example\n\n\nThis example is designed to show how to use the Gromov-Wassertsein distance\ncomputation in POT.\n\n"
38+
],
39+
"metadata": {},
40+
"cell_type": "markdown"
41+
},
42+
{
843
"outputs": [],
944
"source": [
10-
"%matplotlib inline"
45+
"# 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"
1146
],
47+
"execution_count": null,
48+
"metadata": {
49+
"collapsed": false
50+
},
1251
"cell_type": "code"
1352
},
1453
{
15-
"metadata": {},
1654
"source": [
17-
"\n# Gromov-Wasserstein example\n\n\nThis example is designed to show how to use the Gromov-Wassertsein distance\ncomputation in POT.\n\n"
55+
"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"
1856
],
57+
"metadata": {},
1958
"cell_type": "markdown"
2059
},
2160
{
61+
"outputs": [],
62+
"source": [
63+
"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"
64+
],
2265
"execution_count": null,
2366
"metadata": {
2467
"collapsed": false
2568
},
69+
"cell_type": "code"
70+
},
71+
{
72+
"source": [
73+
"Plotting the distributions\n--------------------------\n\n"
74+
],
75+
"metadata": {},
76+
"cell_type": "markdown"
77+
},
78+
{
2679
"outputs": [],
2780
"source": [
28-
"# 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()"
81+
"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()"
2982
],
83+
"execution_count": null,
84+
"metadata": {
85+
"collapsed": false
86+
},
3087
"cell_type": "code"
31-
}
32-
],
33-
"metadata": {
34-
"language_info": {
35-
"name": "python",
36-
"codemirror_mode": {
37-
"name": "ipython",
38-
"version": 3
88+
},
89+
{
90+
"source": [
91+
"Compute distance kernels, normalize them and then display\n---------------------------------------------------------\n\n"
92+
],
93+
"metadata": {},
94+
"cell_type": "markdown"
95+
},
96+
{
97+
"outputs": [],
98+
"source": [
99+
"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()"
100+
],
101+
"execution_count": null,
102+
"metadata": {
103+
"collapsed": false
39104
},
40-
"nbconvert_exporter": "python",
41-
"version": "3.5.2",
42-
"pygments_lexer": "ipython3",
43-
"file_extension": ".py",
44-
"mimetype": "text/x-python"
105+
"cell_type": "code"
45106
},
46-
"kernelspec": {
47-
"display_name": "Python 3",
48-
"name": "python3",
49-
"language": "python"
107+
{
108+
"source": [
109+
"Compute Gromov-Wasserstein plans and distance\n---------------------------------------------\n\n"
110+
],
111+
"metadata": {},
112+
"cell_type": "markdown"
113+
},
114+
{
115+
"outputs": [],
116+
"source": [
117+
"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()"
118+
],
119+
"execution_count": null,
120+
"metadata": {
121+
"collapsed": false
122+
},
123+
"cell_type": "code"
50124
}
51-
},
52-
"nbformat_minor": 0,
53-
"nbformat": 4
125+
]
54126
}

docs/source/auto_examples/plot_gromov.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from mpl_toolkits.mplot3d import Axes3D # noqa
2020
import ot
2121

22-
22+
#############################################################################
2323
#
2424
# Sample two Gaussian distributions (2D and 3D)
2525
# ---------------------------------------------
@@ -42,7 +42,7 @@
4242
P = sp.linalg.sqrtm(cov_t)
4343
xt = np.random.randn(n_samples, 3).dot(P) + mu_t
4444

45-
45+
#############################################################################
4646
#
4747
# Plotting the distributions
4848
# --------------------------
@@ -55,7 +55,7 @@
5555
ax2.scatter(xt[:, 0], xt[:, 1], xt[:, 2], color='r')
5656
pl.show()
5757

58-
58+
#############################################################################
5959
#
6060
# Compute distance kernels, normalize them and then display
6161
# ---------------------------------------------------------
@@ -74,6 +74,7 @@
7474
pl.imshow(C2)
7575
pl.show()
7676

77+
#############################################################################
7778
#
7879
# Compute Gromov-Wasserstein plans and distance
7980
# ---------------------------------------------

0 commit comments

Comments
 (0)