Skip to content

Commit f51c6ab

Browse files
committed
update exmaple bary 1D for better notebook
1 parent 1d68c01 commit f51c6ab

12 files changed

+290
-124
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": "481801bb0d133ef350a65179cf8f739a", "plot_barycenter_1D.ipynb": "6063193f9ac87517acced2625edb9a54", "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_otda_semi_supervised.ipynb": "f6dfb02ba2bbd939408ffcd22a3b007c", "plot_OT_2D_samples.ipynb": "07dbc14859fa019a966caa79fa0825bd", "plot_barycenter_lp_vs_entropic.ipynb": "51833e8c76aaedeba9599ac7a30eb357"}
1+
{"plot_otda_mapping_colors_images.ipynb": "4f0587a00a3c082799a75a0ed36e9ce1", "plot_optim_OTreg.ipynb": "481801bb0d133ef350a65179cf8f739a", "plot_otda_color_images.ipynb": "d047d635f4987c81072383241590e21f", "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_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_otda_semi_supervised.ipynb": "f6dfb02ba2bbd939408ffcd22a3b007c", "plot_OT_2D_samples.ipynb": "07dbc14859fa019a966caa79fa0825bd", "plot_barycenter_lp_vs_entropic.ipynb": "51833e8c76aaedeba9599ac7a30eb357"}
1.08 KB
Binary file not shown.
308 Bytes
Binary file not shown.
-65.6 KB
Loading
69 Bytes
Loading
69 Bytes
Loading

docs/source/auto_examples/index.rst

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

230230
.. raw:: html
231231

232-
<div class="sphx-glr-thumbcontainer" tooltip="OT for domain adaptation with image color adaptation [6] with mapping estimation [8].">
232+
<div class="sphx-glr-thumbcontainer" tooltip="This example illustrates the computation of regularized Wassersyein Barycenter as proposed in [...">
233233

234234
.. only:: html
235235

236-
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png
236+
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_barycenter_1D_thumb.png
237237

238-
:ref:`sphx_glr_auto_examples_plot_otda_mapping_colors_images.py`
238+
:ref:`sphx_glr_auto_examples_plot_barycenter_1D.py`
239239

240240
.. raw:: html
241241

@@ -245,17 +245,17 @@ This is a gallery of all the POT example files.
245245
.. toctree::
246246
:hidden:
247247

248-
/auto_examples/plot_otda_mapping_colors_images
248+
/auto_examples/plot_barycenter_1D
249249

250250
.. raw:: html
251251

252-
<div class="sphx-glr-thumbcontainer" tooltip="This example illustrates the computation of regularized Wassersyein Barycenter as proposed in [...">
252+
<div class="sphx-glr-thumbcontainer" tooltip="OT for domain adaptation with image color adaptation [6] with mapping estimation [8].">
253253

254254
.. only:: html
255255

256-
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_barycenter_1D_thumb.png
256+
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_otda_mapping_colors_images_thumb.png
257257

258-
:ref:`sphx_glr_auto_examples_plot_barycenter_1D.py`
258+
:ref:`sphx_glr_auto_examples_plot_otda_mapping_colors_images.py`
259259

260260
.. raw:: html
261261

@@ -265,7 +265,7 @@ This is a gallery of all the POT example files.
265265
.. toctree::
266266
:hidden:
267267

268-
/auto_examples/plot_barycenter_1D
268+
/auto_examples/plot_otda_mapping_colors_images
269269

270270
.. raw:: html
271271

docs/source/auto_examples/plot_barycenter_1D.ipynb

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,79 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"# Author: Remi Flamary <remi.flamary@unice.fr>\n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\n# necessary for 3d plot even if not used\nfrom mpl_toolkits.mplot3d import Axes3D # noqa\nfrom matplotlib.collections import PolyCollection\n\n#\n# Generate data\n# -------------\n\n#%% parameters\n\nn = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na1 = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std\na2 = ot.datasets.make_1D_gauss(n, m=60, s=8)\n\n# creating matrix A containing all distributions\nA = np.vstack((a1, a2)).T\nn_distributions = A.shape[1]\n\n# loss matrix + normalization\nM = ot.utils.dist0(n)\nM /= M.max()\n\n#\n# Plot data\n# ---------\n\n#%% plot the distributions\n\npl.figure(1, figsize=(6.4, 3))\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\npl.tight_layout()\n\n#\n# Barycenter computation\n# ----------------------\n\n#%% barycenter computation\n\nalpha = 0.2 # 0<=alpha<=1\nweights = np.array([1 - alpha, alpha])\n\n# l2bary\nbary_l2 = A.dot(weights)\n\n# wasserstein\nreg = 1e-3\nbary_wass = ot.bregman.barycenter(A, M, reg, weights)\n\npl.figure(2)\npl.clf()\npl.subplot(2, 1, 1)\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\n\npl.subplot(2, 1, 2)\npl.plot(x, bary_l2, 'r', label='l2')\npl.plot(x, bary_wass, 'g', label='Wasserstein')\npl.legend()\npl.title('Barycenters')\npl.tight_layout()\n\n#\n# Barycentric interpolation\n# -------------------------\n\n#%% barycenter interpolation\n\nn_alpha = 11\nalpha_list = np.linspace(0, 1, n_alpha)\n\n\nB_l2 = np.zeros((n, n_alpha))\n\nB_wass = np.copy(B_l2)\n\nfor i in range(0, n_alpha):\n alpha = alpha_list[i]\n weights = np.array([1 - alpha, alpha])\n B_l2[:, i] = A.dot(weights)\n B_wass[:, i] = ot.bregman.barycenter(A, M, reg, weights)\n\n#%% plot interpolation\n\npl.figure(3)\n\ncmap = pl.cm.get_cmap('viridis')\nverts = []\nzs = alpha_list\nfor i, z in enumerate(zs):\n ys = B_l2[:, i]\n verts.append(list(zip(x, ys)))\n\nax = pl.gcf().gca(projection='3d')\n\npoly = PolyCollection(verts, facecolors=[cmap(a) for a in alpha_list])\npoly.set_alpha(0.7)\nax.add_collection3d(poly, zs=zs, zdir='y')\nax.set_xlabel('x')\nax.set_xlim3d(0, n)\nax.set_ylabel('$\\\\alpha$')\nax.set_ylim3d(0, 1)\nax.set_zlabel('')\nax.set_zlim3d(0, B_l2.max() * 1.01)\npl.title('Barycenter interpolation with l2')\npl.tight_layout()\n\npl.figure(4)\ncmap = pl.cm.get_cmap('viridis')\nverts = []\nzs = alpha_list\nfor i, z in enumerate(zs):\n ys = B_wass[:, i]\n verts.append(list(zip(x, ys)))\n\nax = pl.gcf().gca(projection='3d')\n\npoly = PolyCollection(verts, facecolors=[cmap(a) for a in alpha_list])\npoly.set_alpha(0.7)\nax.add_collection3d(poly, zs=zs, zdir='y')\nax.set_xlabel('x')\nax.set_xlim3d(0, n)\nax.set_ylabel('$\\\\alpha$')\nax.set_ylim3d(0, 1)\nax.set_zlabel('')\nax.set_zlim3d(0, B_l2.max() * 1.01)\npl.title('Barycenter interpolation with Wasserstein')\npl.tight_layout()\n\npl.show()"
29+
"# Author: Remi Flamary <remi.flamary@unice.fr>\n#\n# License: MIT License\n\nimport numpy as np\nimport matplotlib.pylab as pl\nimport ot\n# necessary for 3d plot even if not used\nfrom mpl_toolkits.mplot3d import Axes3D # noqa\nfrom matplotlib.collections import PolyCollection"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"metadata": {},
35+
"source": [
36+
"Generate data\n-------------\n\n"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {
43+
"collapsed": false
44+
},
45+
"outputs": [],
46+
"source": [
47+
"#%% parameters\n\nn = 100 # nb bins\n\n# bin positions\nx = np.arange(n, dtype=np.float64)\n\n# Gaussian distributions\na1 = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std\na2 = ot.datasets.make_1D_gauss(n, m=60, s=8)\n\n# creating matrix A containing all distributions\nA = np.vstack((a1, a2)).T\nn_distributions = A.shape[1]\n\n# loss matrix + normalization\nM = ot.utils.dist0(n)\nM /= M.max()"
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"metadata": {},
53+
"source": [
54+
"Plot data\n---------\n\n"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": null,
60+
"metadata": {
61+
"collapsed": false
62+
},
63+
"outputs": [],
64+
"source": [
65+
"#%% plot the distributions\n\npl.figure(1, figsize=(6.4, 3))\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\npl.tight_layout()"
66+
]
67+
},
68+
{
69+
"cell_type": "markdown",
70+
"metadata": {},
71+
"source": [
72+
"Barycenter computation\n----------------------\n\n"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"metadata": {
79+
"collapsed": false
80+
},
81+
"outputs": [],
82+
"source": [
83+
"#%% barycenter computation\n\nalpha = 0.2 # 0<=alpha<=1\nweights = np.array([1 - alpha, alpha])\n\n# l2bary\nbary_l2 = A.dot(weights)\n\n# wasserstein\nreg = 1e-3\nbary_wass = ot.bregman.barycenter(A, M, reg, weights)\n\npl.figure(2)\npl.clf()\npl.subplot(2, 1, 1)\nfor i in range(n_distributions):\n pl.plot(x, A[:, i])\npl.title('Distributions')\n\npl.subplot(2, 1, 2)\npl.plot(x, bary_l2, 'r', label='l2')\npl.plot(x, bary_wass, 'g', label='Wasserstein')\npl.legend()\npl.title('Barycenters')\npl.tight_layout()"
84+
]
85+
},
86+
{
87+
"cell_type": "markdown",
88+
"metadata": {},
89+
"source": [
90+
"Barycentric interpolation\n-------------------------\n\n"
91+
]
92+
},
93+
{
94+
"cell_type": "code",
95+
"execution_count": null,
96+
"metadata": {
97+
"collapsed": false
98+
},
99+
"outputs": [],
100+
"source": [
101+
"#%% barycenter interpolation\n\nn_alpha = 11\nalpha_list = np.linspace(0, 1, n_alpha)\n\n\nB_l2 = np.zeros((n, n_alpha))\n\nB_wass = np.copy(B_l2)\n\nfor i in range(0, n_alpha):\n alpha = alpha_list[i]\n weights = np.array([1 - alpha, alpha])\n B_l2[:, i] = A.dot(weights)\n B_wass[:, i] = ot.bregman.barycenter(A, M, reg, weights)\n\n#%% plot interpolation\n\npl.figure(3)\n\ncmap = pl.cm.get_cmap('viridis')\nverts = []\nzs = alpha_list\nfor i, z in enumerate(zs):\n ys = B_l2[:, i]\n verts.append(list(zip(x, ys)))\n\nax = pl.gcf().gca(projection='3d')\n\npoly = PolyCollection(verts, facecolors=[cmap(a) for a in alpha_list])\npoly.set_alpha(0.7)\nax.add_collection3d(poly, zs=zs, zdir='y')\nax.set_xlabel('x')\nax.set_xlim3d(0, n)\nax.set_ylabel('$\\\\alpha$')\nax.set_ylim3d(0, 1)\nax.set_zlabel('')\nax.set_zlim3d(0, B_l2.max() * 1.01)\npl.title('Barycenter interpolation with l2')\npl.tight_layout()\n\npl.figure(4)\ncmap = pl.cm.get_cmap('viridis')\nverts = []\nzs = alpha_list\nfor i, z in enumerate(zs):\n ys = B_wass[:, i]\n verts.append(list(zip(x, ys)))\n\nax = pl.gcf().gca(projection='3d')\n\npoly = PolyCollection(verts, facecolors=[cmap(a) for a in alpha_list])\npoly.set_alpha(0.7)\nax.add_collection3d(poly, zs=zs, zdir='y')\nax.set_xlabel('x')\nax.set_xlim3d(0, n)\nax.set_ylabel('$\\\\alpha$')\nax.set_ylim3d(0, 1)\nax.set_zlabel('')\nax.set_zlim3d(0, B_l2.max() * 1.01)\npl.title('Barycenter interpolation with Wasserstein')\npl.tight_layout()\n\npl.show()"
30102
]
31103
}
32104
],

docs/source/auto_examples/plot_barycenter_1D.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from mpl_toolkits.mplot3d import Axes3D # noqa
2626
from matplotlib.collections import PolyCollection
2727

28-
#
28+
##############################################################################
2929
# Generate data
3030
# -------------
3131

@@ -48,7 +48,7 @@
4848
M = ot.utils.dist0(n)
4949
M /= M.max()
5050

51-
#
51+
##############################################################################
5252
# Plot data
5353
# ---------
5454

@@ -60,7 +60,7 @@
6060
pl.title('Distributions')
6161
pl.tight_layout()
6262

63-
#
63+
##############################################################################
6464
# Barycenter computation
6565
# ----------------------
6666

@@ -90,7 +90,7 @@
9090
pl.title('Barycenters')
9191
pl.tight_layout()
9292

93-
#
93+
##############################################################################
9494
# Barycentric interpolation
9595
# -------------------------
9696

docs/source/auto_examples/plot_barycenter_1D.rst

Lines changed: 76 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,52 +18,34 @@ SIAM Journal on Scientific Computing, 37(2), A1111-A1138.
1818

1919

2020

21+
.. code-block:: python
2122
22-
.. rst-class:: sphx-glr-horizontal
23-
24-
25-
*
2623
27-
.. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_001.png
28-
:scale: 47
24+
# Author: Remi Flamary <remi.flamary@unice.fr>
25+
#
26+
# License: MIT License
2927
30-
*
28+
import numpy as np
29+
import matplotlib.pylab as pl
30+
import ot
31+
# necessary for 3d plot even if not used
32+
from mpl_toolkits.mplot3d import Axes3D # noqa
33+
from matplotlib.collections import PolyCollection
3134
32-
.. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_002.png
33-
:scale: 47
3435
35-
*
3636
37-
.. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_003.png
38-
:scale: 47
3937
40-
*
4138
42-
.. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_004.png
43-
:scale: 47
4439
4540
41+
Generate data
42+
-------------
4643

4744

4845

4946
.. code-block:: python
5047
5148
52-
# Author: Remi Flamary <remi.flamary@unice.fr>
53-
#
54-
# License: MIT License
55-
56-
import numpy as np
57-
import matplotlib.pylab as pl
58-
import ot
59-
# necessary for 3d plot even if not used
60-
from mpl_toolkits.mplot3d import Axes3D # noqa
61-
from matplotlib.collections import PolyCollection
62-
63-
#
64-
# Generate data
65-
# -------------
66-
6749
#%% parameters
6850
6951
n = 100 # nb bins
@@ -83,9 +65,19 @@ SIAM Journal on Scientific Computing, 37(2), A1111-A1138.
8365
M = ot.utils.dist0(n)
8466
M /= M.max()
8567
86-
#
87-
# Plot data
88-
# ---------
68+
69+
70+
71+
72+
73+
74+
Plot data
75+
---------
76+
77+
78+
79+
.. code-block:: python
80+
8981
9082
#%% plot the distributions
9183
@@ -95,9 +87,22 @@ SIAM Journal on Scientific Computing, 37(2), A1111-A1138.
9587
pl.title('Distributions')
9688
pl.tight_layout()
9789
98-
#
99-
# Barycenter computation
100-
# ----------------------
90+
91+
92+
93+
.. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_001.png
94+
:align: center
95+
96+
97+
98+
99+
Barycenter computation
100+
----------------------
101+
102+
103+
104+
.. code-block:: python
105+
101106
102107
#%% barycenter computation
103108
@@ -125,9 +130,22 @@ SIAM Journal on Scientific Computing, 37(2), A1111-A1138.
125130
pl.title('Barycenters')
126131
pl.tight_layout()
127132
128-
#
129-
# Barycentric interpolation
130-
# -------------------------
133+
134+
135+
136+
.. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_003.png
137+
:align: center
138+
139+
140+
141+
142+
Barycentric interpolation
143+
-------------------------
144+
145+
146+
147+
.. code-block:: python
148+
131149
132150
#%% barycenter interpolation
133151
@@ -194,7 +212,25 @@ SIAM Journal on Scientific Computing, 37(2), A1111-A1138.
194212
195213
pl.show()
196214
197-
**Total running time of the script:** ( 0 minutes 0.363 seconds)
215+
216+
217+
.. rst-class:: sphx-glr-horizontal
218+
219+
220+
*
221+
222+
.. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_005.png
223+
:scale: 47
224+
225+
*
226+
227+
.. image:: /auto_examples/images/sphx_glr_plot_barycenter_1D_006.png
228+
:scale: 47
229+
230+
231+
232+
233+
**Total running time of the script:** ( 0 minutes 0.413 seconds)
198234

199235

200236

0 commit comments

Comments
 (0)