Skip to content

Commit da37513

Browse files
authored
Merge pull request #121 from mzalaya/master
[WIP] add screenkhorn: screening Sinkhorn algorithm
2 parents 1b58440 + 6d4ccac commit da37513

File tree

5 files changed

+435
-9
lines changed

5 files changed

+435
-9
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ It provides the following solvers:
2828
* Stochastic Optimization for Large-scale Optimal Transport (semi-dual problem [18] and dual problem [19])
2929
* Non regularized free support Wasserstein barycenters [20].
3030
* Unbalanced OT with KL relaxation distance and barycenter [10, 25].
31+
* Screening Sinkhorn Algorithm for OT [26].
3132

3233
Some demonstrations (both in Python and Jupyter Notebook format) are available in the examples folder.
3334

@@ -180,6 +181,7 @@ The contributors to this library are
180181
* [Vayer Titouan](https://tvayer.github.io/)
181182
* [Hicham Janati](https://hichamjanati.github.io/) (Unbalanced OT)
182183
* [Romain Tavenard](https://rtavenar.github.io/) (1d Wasserstein)
184+
* [Mokhtar Z. Alaya](http://mzalaya.github.io/) (Screenkhorn)
183185

184186
This toolbox benefit a lot from open source research and we would like to thank the following persons for providing some code (in various languages):
185187

@@ -252,4 +254,6 @@ You can also post bug reports and feature requests in Github issues. Make sure t
252254

253255
[24] Vayer, T., Chapel, L., Flamary, R., Tavenard, R. and Courty, N. (2019). [Optimal Transport for structured data with application on graphs](http://proceedings.mlr.press/v97/titouan19a.html) Proceedings of the 36th International Conference on Machine Learning (ICML).
254256

255-
[25] Frogner C., Zhang C., Mobahi H., Araya-Polo M., Poggio T. (2019). [Learning with a Wasserstein Loss](http://cbcl.mit.edu/wasserstein/) Advances in Neural Information Processing Systems (NIPS).
257+
[25] Frogner C., Zhang C., Mobahi H., Araya-Polo M., Poggio T. (2015). [Learning with a Wasserstein Loss](http://cbcl.mit.edu/wasserstein/) Advances in Neural Information Processing Systems (NIPS).
258+
259+
[26] Alaya M. Z., Bérar M., Gasso G., Rakotomamonjy A. (2019). [Screening Sinkhorn Algorithm for Regularized Optimal Transport](https://papers.nips.cc/paper/9386-screening-sinkhorn-algorithm-for-regularized-optimal-transport), Advances in Neural Information Processing Systems 33 (NeurIPS).

examples/plot_screenkhorn_1D.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
===============================
4+
1D Screened optimal transport
5+
===============================
6+
7+
This example illustrates the computation of Screenkhorn:
8+
Screening Sinkhorn Algorithm for Optimal transport.
9+
"""
10+
11+
# Author: Mokhtar Z. Alaya <mokhtarzahdi.alaya@gmail.com>
12+
#
13+
# License: MIT License
14+
15+
import numpy as np
16+
import matplotlib.pylab as pl
17+
import ot.plot
18+
from ot.datasets import make_1D_gauss as gauss
19+
from ot.bregman import screenkhorn
20+
21+
##############################################################################
22+
# Generate data
23+
# -------------
24+
25+
#%% parameters
26+
27+
n = 100 # nb bins
28+
29+
# bin positions
30+
x = np.arange(n, dtype=np.float64)
31+
32+
# Gaussian distributions
33+
a = gauss(n, m=20, s=5) # m= mean, s= std
34+
b = gauss(n, m=60, s=10)
35+
36+
# loss matrix
37+
M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))
38+
M /= M.max()
39+
40+
##############################################################################
41+
# Plot distributions and loss matrix
42+
# ----------------------------------
43+
44+
#%% plot the distributions
45+
46+
pl.figure(1, figsize=(6.4, 3))
47+
pl.plot(x, a, 'b', label='Source distribution')
48+
pl.plot(x, b, 'r', label='Target distribution')
49+
pl.legend()
50+
51+
# plot distributions and loss matrix
52+
53+
pl.figure(2, figsize=(5, 5))
54+
ot.plot.plot1D_mat(a, b, M, 'Cost matrix M')
55+
56+
##############################################################################
57+
# Solve Screenkhorn
58+
# -----------------------
59+
60+
# Screenkhorn
61+
lambd = 2e-03 # entropy parameter
62+
ns_budget = 30 # budget number of points to be keeped in the source distribution
63+
nt_budget = 30 # budget number of points to be keeped in the target distribution
64+
65+
G_screen = screenkhorn(a, b, M, lambd, ns_budget, nt_budget, uniform=False, restricted=True, verbose=True)
66+
pl.figure(4, figsize=(5, 5))
67+
ot.plot.plot1D_mat(a, b, G_screen, 'OT matrix Screenkhorn')
68+
pl.show()

0 commit comments

Comments
 (0)