Skip to content

Commit ae1ede4

Browse files
committed
update doc+notebooks for convolutional
1 parent 9fb56be commit ae1ede4

11 files changed

+536
-6
lines changed

RELEASES.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66

77
*This is a beta release and is still a work in progress*
88

9-
#### TODO
10-
11-
[] Remove deprecated OTDA Classes (PR #48)
12-
[] Speedup Sinkhorn with einsum + bench (PR #58)
13-
[] Stochastic ot (PR #62)
149

1510
#### Features
1611

@@ -25,6 +20,12 @@
2520
* Stochastic OT in the dual and semi-dual (PR #52 and PR #62)
2621
* Free support barycenters (PR #56)
2722
* Speed-up Sinkhorn function (PR #57 and PR #58)
23+
* Add convolutional Wassersein barycenters for 2D images (PR #64)
24+
* Add Greedy Sinkhorn variant (Greenkhorn) (PR #66)
25+
26+
#### Deprecation
27+
28+
Deprecated OTDA Classes were removed for version 0.5 (PR #48), it has been a year and the deprecation message.
2829

2930
#### Closed issues
3031

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_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+
{"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"}
3.87 KB
Binary file not shown.
2.55 KB
Binary file not shown.
312 KB
Loading
53.1 KB
Loading

docs/source/auto_examples/index.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,26 @@ This is a gallery of all the POT example files.
147147

148148
/auto_examples/plot_compute_emd
149149

150+
.. raw:: html
151+
152+
<div class="sphx-glr-thumbcontainer" tooltip="This example is designed to illustrate how the Convolutional Wasserstein Barycenter function of...">
153+
154+
.. only:: html
155+
156+
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_convolutional_barycenter_thumb.png
157+
158+
:ref:`sphx_glr_auto_examples_plot_convolutional_barycenter.py`
159+
160+
.. raw:: html
161+
162+
</div>
163+
164+
165+
.. toctree::
166+
:hidden:
167+
168+
/auto_examples/plot_convolutional_barycenter
169+
150170
.. raw:: html
151171

152172
<div class="sphx-glr-thumbcontainer" tooltip=" ">
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": false
8+
},
9+
"outputs": [],
10+
"source": [
11+
"%matplotlib inline"
12+
]
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"metadata": {},
17+
"source": [
18+
"\n# Convolutional Wasserstein Barycenter example\n\n\nThis example is designed to illustrate how the Convolutional Wasserstein Barycenter\nfunction of POT works.\n\n"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"metadata": {
25+
"collapsed": false
26+
},
27+
"outputs": [],
28+
"source": [
29+
"# Author: Nicolas Courty <ncourty@irisa.fr>\n#\n# License: MIT License\n\n\nimport numpy as np\nimport pylab as pl\nimport ot"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"metadata": {},
35+
"source": [
36+
"Data preparation\n----------------\n\nThe four distributions are constructed from 4 simple images\n\n"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {
43+
"collapsed": false
44+
},
45+
"outputs": [],
46+
"source": [
47+
"f1 = 1 - pl.imread('../data/redcross.png')[:, :, 2]\nf2 = 1 - pl.imread('../data/duck.png')[:, :, 2]\nf3 = 1 - pl.imread('../data/heart.png')[:, :, 2]\nf4 = 1 - pl.imread('../data/tooth.png')[:, :, 2]\n\nA = []\nf1 = f1 / np.sum(f1)\nf2 = f2 / np.sum(f2)\nf3 = f3 / np.sum(f3)\nf4 = f4 / np.sum(f4)\nA.append(f1)\nA.append(f2)\nA.append(f3)\nA.append(f4)\nA = np.array(A)\n\nnb_images = 5\n\n# those are the four corners coordinates that will be interpolated by bilinear\n# interpolation\nv1 = np.array((1, 0, 0, 0))\nv2 = np.array((0, 1, 0, 0))\nv3 = np.array((0, 0, 1, 0))\nv4 = np.array((0, 0, 0, 1))"
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"metadata": {},
53+
"source": [
54+
"Barycenter computation and visualization\n----------------------------------------\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+
"pl.figure(figsize=(10, 10))\npl.title('Convolutional Wasserstein Barycenters in POT')\ncm = 'Blues'\n# regularization parameter\nreg = 0.004\nfor i in range(nb_images):\n for j in range(nb_images):\n pl.subplot(nb_images, nb_images, i * nb_images + j + 1)\n tx = float(i) / (nb_images - 1)\n ty = float(j) / (nb_images - 1)\n\n # weights are constructed by bilinear interpolation\n tmp1 = (1 - tx) * v1 + tx * v2\n tmp2 = (1 - tx) * v3 + tx * v4\n weights = (1 - ty) * tmp1 + ty * tmp2\n\n if i == 0 and j == 0:\n pl.imshow(f1, cmap=cm)\n pl.axis('off')\n elif i == 0 and j == (nb_images - 1):\n pl.imshow(f3, cmap=cm)\n pl.axis('off')\n elif i == (nb_images - 1) and j == 0:\n pl.imshow(f2, cmap=cm)\n pl.axis('off')\n elif i == (nb_images - 1) and j == (nb_images - 1):\n pl.imshow(f4, cmap=cm)\n pl.axis('off')\n else:\n # call to barycenter computation\n pl.imshow(ot.bregman.convolutional_barycenter2d(A, reg, weights), cmap=cm)\n pl.axis('off')\npl.show()"
66+
]
67+
}
68+
],
69+
"metadata": {
70+
"kernelspec": {
71+
"display_name": "Python 3",
72+
"language": "python",
73+
"name": "python3"
74+
},
75+
"language_info": {
76+
"codemirror_mode": {
77+
"name": "ipython",
78+
"version": 3
79+
},
80+
"file_extension": ".py",
81+
"mimetype": "text/x-python",
82+
"name": "python",
83+
"nbconvert_exporter": "python",
84+
"pygments_lexer": "ipython3",
85+
"version": "3.6.5"
86+
}
87+
},
88+
"nbformat": 4,
89+
"nbformat_minor": 0
90+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
#%%
3+
# -*- coding: utf-8 -*-
4+
"""
5+
============================================
6+
Convolutional Wasserstein Barycenter example
7+
============================================
8+
9+
This example is designed to illustrate how the Convolutional Wasserstein Barycenter
10+
function of POT works.
11+
"""
12+
13+
# Author: Nicolas Courty <ncourty@irisa.fr>
14+
#
15+
# License: MIT License
16+
17+
18+
import numpy as np
19+
import pylab as pl
20+
import ot
21+
22+
##############################################################################
23+
# Data preparation
24+
# ----------------
25+
#
26+
# The four distributions are constructed from 4 simple images
27+
28+
29+
f1 = 1 - pl.imread('../data/redcross.png')[:, :, 2]
30+
f2 = 1 - pl.imread('../data/duck.png')[:, :, 2]
31+
f3 = 1 - pl.imread('../data/heart.png')[:, :, 2]
32+
f4 = 1 - pl.imread('../data/tooth.png')[:, :, 2]
33+
34+
A = []
35+
f1 = f1 / np.sum(f1)
36+
f2 = f2 / np.sum(f2)
37+
f3 = f3 / np.sum(f3)
38+
f4 = f4 / np.sum(f4)
39+
A.append(f1)
40+
A.append(f2)
41+
A.append(f3)
42+
A.append(f4)
43+
A = np.array(A)
44+
45+
nb_images = 5
46+
47+
# those are the four corners coordinates that will be interpolated by bilinear
48+
# interpolation
49+
v1 = np.array((1, 0, 0, 0))
50+
v2 = np.array((0, 1, 0, 0))
51+
v3 = np.array((0, 0, 1, 0))
52+
v4 = np.array((0, 0, 0, 1))
53+
54+
55+
##############################################################################
56+
# Barycenter computation and visualization
57+
# ----------------------------------------
58+
#
59+
60+
pl.figure(figsize=(10, 10))
61+
pl.title('Convolutional Wasserstein Barycenters in POT')
62+
cm = 'Blues'
63+
# regularization parameter
64+
reg = 0.004
65+
for i in range(nb_images):
66+
for j in range(nb_images):
67+
pl.subplot(nb_images, nb_images, i * nb_images + j + 1)
68+
tx = float(i) / (nb_images - 1)
69+
ty = float(j) / (nb_images - 1)
70+
71+
# weights are constructed by bilinear interpolation
72+
tmp1 = (1 - tx) * v1 + tx * v2
73+
tmp2 = (1 - tx) * v3 + tx * v4
74+
weights = (1 - ty) * tmp1 + ty * tmp2
75+
76+
if i == 0 and j == 0:
77+
pl.imshow(f1, cmap=cm)
78+
pl.axis('off')
79+
elif i == 0 and j == (nb_images - 1):
80+
pl.imshow(f3, cmap=cm)
81+
pl.axis('off')
82+
elif i == (nb_images - 1) and j == 0:
83+
pl.imshow(f2, cmap=cm)
84+
pl.axis('off')
85+
elif i == (nb_images - 1) and j == (nb_images - 1):
86+
pl.imshow(f4, cmap=cm)
87+
pl.axis('off')
88+
else:
89+
# call to barycenter computation
90+
pl.imshow(ot.bregman.convolutional_barycenter2d(A, reg, weights), cmap=cm)
91+
pl.axis('off')
92+
pl.show()
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
2+
3+
.. _sphx_glr_auto_examples_plot_convolutional_barycenter.py:
4+
5+
6+
============================================
7+
Convolutional Wasserstein Barycenter example
8+
============================================
9+
10+
This example is designed to illustrate how the Convolutional Wasserstein Barycenter
11+
function of POT works.
12+
13+
14+
15+
.. code-block:: python
16+
17+
18+
# Author: Nicolas Courty <ncourty@irisa.fr>
19+
#
20+
# License: MIT License
21+
22+
23+
import numpy as np
24+
import pylab as pl
25+
import ot
26+
27+
28+
29+
30+
31+
32+
33+
Data preparation
34+
----------------
35+
36+
The four distributions are constructed from 4 simple images
37+
38+
39+
40+
.. code-block:: python
41+
42+
43+
44+
f1 = 1 - pl.imread('../data/redcross.png')[:, :, 2]
45+
f2 = 1 - pl.imread('../data/duck.png')[:, :, 2]
46+
f3 = 1 - pl.imread('../data/heart.png')[:, :, 2]
47+
f4 = 1 - pl.imread('../data/tooth.png')[:, :, 2]
48+
49+
A = []
50+
f1 = f1 / np.sum(f1)
51+
f2 = f2 / np.sum(f2)
52+
f3 = f3 / np.sum(f3)
53+
f4 = f4 / np.sum(f4)
54+
A.append(f1)
55+
A.append(f2)
56+
A.append(f3)
57+
A.append(f4)
58+
A = np.array(A)
59+
60+
nb_images = 5
61+
62+
# those are the four corners coordinates that will be interpolated by bilinear
63+
# interpolation
64+
v1 = np.array((1, 0, 0, 0))
65+
v2 = np.array((0, 1, 0, 0))
66+
v3 = np.array((0, 0, 1, 0))
67+
v4 = np.array((0, 0, 0, 1))
68+
69+
70+
71+
72+
73+
74+
75+
76+
Barycenter computation and visualization
77+
----------------------------------------
78+
79+
80+
81+
82+
.. code-block:: python
83+
84+
85+
pl.figure(figsize=(10, 10))
86+
pl.title('Convolutional Wasserstein Barycenters in POT')
87+
cm = 'Blues'
88+
# regularization parameter
89+
reg = 0.004
90+
for i in range(nb_images):
91+
for j in range(nb_images):
92+
pl.subplot(nb_images, nb_images, i * nb_images + j + 1)
93+
tx = float(i) / (nb_images - 1)
94+
ty = float(j) / (nb_images - 1)
95+
96+
# weights are constructed by bilinear interpolation
97+
tmp1 = (1 - tx) * v1 + tx * v2
98+
tmp2 = (1 - tx) * v3 + tx * v4
99+
weights = (1 - ty) * tmp1 + ty * tmp2
100+
101+
if i == 0 and j == 0:
102+
pl.imshow(f1, cmap=cm)
103+
pl.axis('off')
104+
elif i == 0 and j == (nb_images - 1):
105+
pl.imshow(f3, cmap=cm)
106+
pl.axis('off')
107+
elif i == (nb_images - 1) and j == 0:
108+
pl.imshow(f2, cmap=cm)
109+
pl.axis('off')
110+
elif i == (nb_images - 1) and j == (nb_images - 1):
111+
pl.imshow(f4, cmap=cm)
112+
pl.axis('off')
113+
else:
114+
# call to barycenter computation
115+
pl.imshow(ot.bregman.convolutional_barycenter2d(A, reg, weights), cmap=cm)
116+
pl.axis('off')
117+
pl.show()
118+
119+
120+
121+
.. image:: /auto_examples/images/sphx_glr_plot_convolutional_barycenter_001.png
122+
:align: center
123+
124+
125+
126+
127+
**Total running time of the script:** ( 1 minutes 11.608 seconds)
128+
129+
130+
131+
.. only :: html
132+
133+
.. container:: sphx-glr-footer
134+
135+
136+
.. container:: sphx-glr-download
137+
138+
:download:`Download Python source code: plot_convolutional_barycenter.py <plot_convolutional_barycenter.py>`
139+
140+
141+
142+
.. container:: sphx-glr-download
143+
144+
:download:`Download Jupyter notebook: plot_convolutional_barycenter.ipynb <plot_convolutional_barycenter.ipynb>`
145+
146+
147+
.. only:: html
148+
149+
.. rst-class:: sphx-glr-signature
150+
151+
`Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_

0 commit comments

Comments
 (0)