Skip to content

Commit df29313

Browse files
authored
Merge pull request #141 from lchapel/partial-W-and-GW
[MRG] partial Wass and GW
2 parents adc5570 + de5679a commit df29313

File tree

9 files changed

+1501
-37
lines changed

9 files changed

+1501
-37
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ matrix:
1616
python: 3.7
1717
- os: linux
1818
sudo: required
19-
python: 2.7
19+
python: 3.8
2020
# - os: osx
2121
# sudo: required
2222
# language: generic

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ It provides the following solvers:
3030
* Unbalanced OT with KL relaxation distance and barycenter [10, 25].
3131
* Screening Sinkhorn Algorithm for OT [26].
3232
* JCPOT algorithm for multi-source domain adaptation with target shift [27].
33+
* Partial Wasserstein and Gromov-Wasserstein (exact [29] and entropic [3] formulations).
3334

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

@@ -259,4 +260,8 @@ You can also post bug reports and feature requests in Github issues. Make sure t
259260

260261
[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).
261262

262-
[27] Redko I., Courty N., Flamary R., Tuia D. (2019). [Optimal Transport for Multi-source Domain Adaptation under Target Shift](http://proceedings.mlr.press/v89/redko19a.html), Proceedings of the Twenty-Second International Conference on Artificial Intelligence and Statistics (AISTATS) 22, 2019.
263+
[27] Redko I., Courty N., Flamary R., Tuia D. (2019). [Optimal Transport for Multi-source Domain Adaptation under Target Shift](http://proceedings.mlr.press/v89/redko19a.html), Proceedings of the Twenty-Second International Conference on Artificial Intelligence and Statistics (AISTATS) 22, 2019.
264+
265+
[28] Caffarelli, L. A., McCann, R. J. (2020). [Free boundaries in optimal transport and Monge-Ampere obstacle problems](http://www.math.toronto.edu/~mccann/papers/annals2010.pdf), Annals of mathematics, 673-730.
266+
267+
[29] Chapel, L., Alaya, M., Gasso, G. (2019). [Partial Gromov-Wasserstein with Applications on Positive-Unlabeled Learning](https://arxiv.org/abs/2002.08276), arXiv preprint arXiv:2002.08276.

docs/source/all.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,9 @@ ot.unbalanced
8686

8787
.. automodule:: ot.unbalanced
8888
:members:
89+
90+
ot.partial
91+
-------------
92+
93+
.. automodule:: ot.partial
94+
:members:

docs/source/quickstart.rst

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,53 @@ implemented the main function :any:`ot.barycenter_unbalanced`.
645645
- :any:`auto_examples/plot_UOT_barycenter_1D`
646646

647647

648+
Partial optimal transport
649+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
650+
651+
Partial OT is a variant of the optimal transport problem when only a fixed amount of mass m
652+
is to be transported. The partial OT metric between two histograms a and b is defined as [28]_:
653+
654+
.. math::
655+
\gamma = \arg\min_\gamma <\gamma,M>_F
656+
657+
s.t.
658+
\gamma\geq 0 \\
659+
\gamma 1 \leq a\\
660+
\gamma^T 1 \leq b\\
661+
1^T \gamma^T 1 = m \leq \min\{\|a\|_1, \|b\|_1\}
662+
663+
664+
Interestingly the problem can be casted into a regular OT problem by adding reservoir points
665+
in which the surplus mass is sent [29]_. We provide a solver for partial OT
666+
in :any:`ot.partial`. The exact resolution of the problem is computed in :any:`ot.partial.partial_wasserstein`
667+
and :any:`ot.partial.partial_wasserstein2` that return respectively the OT matrix and the value of the
668+
linear term. The entropic solution of the problem is computed in :any:`ot.partial.entropic_partial_wasserstein`
669+
(see [3]_).
670+
671+
The partial Gromov-Wasserstein formulation of the problem
672+
673+
.. math::
674+
GW = \min_\gamma \sum_{i,j,k,l} L(C1_{i,k},C2_{j,l})*\gamma_{i,j}*\gamma_{k,l}
675+
676+
s.t.
677+
\gamma\geq 0 \\
678+
\gamma 1 \leq a\\
679+
\gamma^T 1 \leq b\\
680+
1^T \gamma^T 1 = m \leq \min\{\|a\|_1, \|b\|_1\}
681+
682+
is computed in :any:`ot.partial.partial_gromov_wasserstein` and in
683+
:any:`ot.partial.entropic_partial_gromov_wasserstein` when considering the entropic
684+
regularization of the problem.
685+
686+
687+
.. hint::
688+
689+
Examples of the use of :any:`ot.partial` are available in :
690+
691+
- :any:`auto_examples/plot_partial`
692+
693+
694+
648695
Gromov-Wasserstein
649696
^^^^^^^^^^^^^^^^^^
650697

@@ -921,3 +968,20 @@ References
921968
.. [25] Frogner C., Zhang C., Mobahi H., Araya-Polo M., Poggio T. :
922969
Learning with a Wasserstein Loss, Advances in Neural Information
923970
Processing Systems (NIPS) 2015
971+
972+
.. [26] Alaya M. Z., Bérar M., Gasso G., Rakotomamonjy A. (2019). Screening Sinkhorn
973+
Algorithm for Regularized Optimal Transport <https://papers.nips.cc/paper/9386-screening-sinkhorn-algorithm-for-regularized-optimal-transport>,
974+
Advances in Neural Information Processing Systems 33 (NeurIPS).
975+
976+
.. [27] Redko I., Courty N., Flamary R., Tuia D. (2019). Optimal Transport for Multi-source
977+
Domain Adaptation under Target Shift <http://proceedings.mlr.press/v89/redko19a.html>,
978+
Proceedings of the Twenty-Second International Conference on Artificial Intelligence
979+
and Statistics (AISTATS) 22, 2019.
980+
981+
.. [28] Caffarelli, L. A., McCann, R. J. (2020). Free boundaries in optimal transport and
982+
Monge-Ampere obstacle problems <http://www.math.toronto.edu/~mccann/papers/annals2010.pdf>,
983+
Annals of mathematics, 673-730.
984+
985+
.. [29] Chapel, L., Alaya, M., Gasso, G. (2019). Partial Gromov-Wasserstein with
986+
Applications on Positive-Unlabeled Learning <https://arxiv.org/abs/2002.08276>,
987+
arXiv preprint arXiv:2002.08276.

docs/source/readme.rst

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ It provides the following solvers:
3636
problem [18] and dual problem [19])
3737
- Non regularized free support Wasserstein barycenters [20].
3838
- Unbalanced OT with KL relaxation distance and barycenter [10, 25].
39+
- Screening Sinkhorn Algorithm for OT [26].
40+
- JCPOT algorithm for multi-source domain adaptation with target shift
41+
[27].
3942

4043
Some demonstrations (both in Python and Jupyter Notebook format) are
4144
available in the examples folder.
@@ -48,19 +51,19 @@ POT using the following bibtex reference:
4851

4952
::
5053

51-
@misc{flamary2017pot,
52-
title={POT Python Optimal Transport library},
53-
author={Flamary, R{'e}mi and Courty, Nicolas},
54-
url={https://github.com/rflamary/POT},
55-
year={2017}
56-
}
54+
@misc{flamary2017pot,
55+
title={POT Python Optimal Transport library},
56+
author={Flamary, R{'e}mi and Courty, Nicolas},
57+
url={https://github.com/rflamary/POT},
58+
year={2017}
59+
}
5760

5861
Installation
5962
------------
6063

6164
The library has been tested on Linux, MacOSX and Windows. It requires a
62-
C++ compiler for using the EMD solver and relies on the following Python
63-
modules:
65+
C++ compiler for building/installing the EMD solver and relies on the
66+
following Python modules:
6467

6568
- Numpy (>=1.11)
6669
- Scipy (>=1.0)
@@ -75,19 +78,19 @@ be installed prior to installing POT. This can be done easily with
7578

7679
::
7780

78-
pip install numpy cython
81+
pip install numpy cython
7982

8083
You can install the toolbox through PyPI with:
8184

8285
::
8386

84-
pip install POT
87+
pip install POT
8588

8689
or get the very latest version by downloading it and then running:
8790

8891
::
8992

90-
python setup.py install --user # for user install (no root)
93+
python setup.py install --user # for user install (no root)
9194

9295
Anaconda installation with conda-forge
9396
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -98,7 +101,7 @@ required dependencies:
98101

99102
::
100103

101-
conda install -c conda-forge pot
104+
conda install -c conda-forge pot
102105

103106
Post installation check
104107
^^^^^^^^^^^^^^^^^^^^^^^
@@ -108,7 +111,7 @@ without errors:
108111

109112
.. code:: python
110113
111-
import ot
114+
import ot
112115
113116
Note that for easier access the module is name ot instead of pot.
114117

@@ -121,9 +124,9 @@ below
121124
- **ot.dr** (Wasserstein dimensionality reduction) depends on autograd
122125
and pymanopt that can be installed with:
123126

124-
::
127+
::
125128

126-
pip install pymanopt autograd
129+
pip install pymanopt autograd
127130

128131
- **ot.gpu** (GPU accelerated OT) depends on cupy that have to be
129132
installed following instructions on `this
@@ -139,36 +142,36 @@ Short examples
139142

140143
- Import the toolbox
141144

142-
.. code:: python
145+
.. code:: python
143146
144-
import ot
147+
import ot
145148
146149
- Compute Wasserstein distances
147150

148-
.. code:: python
151+
.. code:: python
149152
150-
# a,b are 1D histograms (sum to 1 and positive)
151-
# M is the ground cost matrix
152-
Wd=ot.emd2(a,b,M) # exact linear program
153-
Wd_reg=ot.sinkhorn2(a,b,M,reg) # entropic regularized OT
154-
# if b is a matrix compute all distances to a and return a vector
153+
# a,b are 1D histograms (sum to 1 and positive)
154+
# M is the ground cost matrix
155+
Wd=ot.emd2(a,b,M) # exact linear program
156+
Wd_reg=ot.sinkhorn2(a,b,M,reg) # entropic regularized OT
157+
# if b is a matrix compute all distances to a and return a vector
155158
156159
- Compute OT matrix
157160

158-
.. code:: python
161+
.. code:: python
159162
160-
# a,b are 1D histograms (sum to 1 and positive)
161-
# M is the ground cost matrix
162-
T=ot.emd(a,b,M) # exact linear program
163-
T_reg=ot.sinkhorn(a,b,M,reg) # entropic regularized OT
163+
# a,b are 1D histograms (sum to 1 and positive)
164+
# M is the ground cost matrix
165+
T=ot.emd(a,b,M) # exact linear program
166+
T_reg=ot.sinkhorn(a,b,M,reg) # entropic regularized OT
164167
165168
- Compute Wasserstein barycenter
166169

167-
.. code:: python
170+
.. code:: python
168171
169-
# A is a n*d matrix containing d 1D histograms
170-
# M is the ground cost matrix
171-
ba=ot.barycenter(A,M,reg) # reg is regularization parameter
172+
# A is a n*d matrix containing d 1D histograms
173+
# M is the ground cost matrix
174+
ba=ot.barycenter(A,M,reg) # reg is regularization parameter
172175
173176
Examples and Notebooks
174177
~~~~~~~~~~~~~~~~~~~~~~
@@ -207,6 +210,10 @@ want a quick look:
207210
Wasserstein <https://github.com/rflamary/POT/blob/master/notebooks/plot_gromov.ipynb>`__
208211
- `Gromov Wasserstein
209212
Barycenter <https://github.com/rflamary/POT/blob/master/notebooks/plot_gromov_barycenter.ipynb>`__
213+
- `Fused Gromov
214+
Wasserstein <https://github.com/rflamary/POT/blob/master/notebooks/plot_fgw.ipynb>`__
215+
- `Fused Gromov Wasserstein
216+
Barycenter <https://github.com/rflamary/POT/blob/master/notebooks/plot_barycenter_fgw.ipynb>`__
210217

211218
You can also see the notebooks with `Jupyter
212219
nbviewer <https://nbviewer.jupyter.org/github/rflamary/POT/tree/master/notebooks/>`__.
@@ -237,6 +244,7 @@ The contributors to this library are
237244
- `Vayer Titouan <https://tvayer.github.io/>`__
238245
- `Hicham Janati <https://hichamjanati.github.io/>`__ (Unbalanced OT)
239246
- `Romain Tavenard <https://rtavenar.github.io/>`__ (1d Wasserstein)
247+
- `Mokhtar Z. Alaya <http://mzalaya.github.io/>`__ (Screenkhorn)
240248

241249
This toolbox benefit a lot from open source research and we would like
242250
to thank the following persons for providing some code (in various
@@ -274,11 +282,11 @@ References
274282
[1] Bonneel, N., Van De Panne, M., Paris, S., & Heidrich, W. (2011,
275283
December). `Displacement interpolation using Lagrangian mass
276284
transport <https://people.csail.mit.edu/sparis/publi/2011/sigasia/Bonneel_11_Displacement_Interpolation.pdf>`__.
277-
In ACM Transactions on Graphics (TOG) (Vol. 30, No. 6, p. 158). ACM.
285+
In ACM Transactions on Graphics (TOG) (Vol. 30, No. 6, p. 158). ACM.
278286

279287
[2] Cuturi, M. (2013). `Sinkhorn distances: Lightspeed computation of
280288
optimal transport <https://arxiv.org/pdf/1306.0895.pdf>`__. In Advances
281-
in Neural Information Processing Systems (pp. 2292-2300).
289+
in Neural Information Processing Systems (pp. 2292-2300).
282290

283291
[3] Benamou, J. D., Carlier, G., Cuturi, M., Nenna, L., & Peyré, G.
284292
(2015). `Iterative Bregman projections for regularized transportation
@@ -387,10 +395,30 @@ and Statistics, (AISTATS) 21, 2018
387395
graphs <http://proceedings.mlr.press/v97/titouan19a.html>`__ Proceedings
388396
of the 36th International Conference on Machine Learning (ICML).
389397

390-
[25] Frogner C., Zhang C., Mobahi H., Araya-Polo M., Poggio T. (2019).
398+
[25] Frogner C., Zhang C., Mobahi H., Araya-Polo M., Poggio T. (2015).
391399
`Learning with a Wasserstein Loss <http://cbcl.mit.edu/wasserstein/>`__
392400
Advances in Neural Information Processing Systems (NIPS).
393401

402+
[26] Alaya M. Z., Bérar M., Gasso G., Rakotomamonjy A. (2019).
403+
`Screening Sinkhorn Algorithm for Regularized Optimal
404+
Transport <https://papers.nips.cc/paper/9386-screening-sinkhorn-algorithm-for-regularized-optimal-transport>`__,
405+
Advances in Neural Information Processing Systems 33 (NeurIPS).
406+
407+
[27] Redko I., Courty N., Flamary R., Tuia D. (2019). `Optimal Transport
408+
for Multi-source Domain Adaptation under Target
409+
Shift <http://proceedings.mlr.press/v89/redko19a.html>`__, Proceedings
410+
of the Twenty-Second International Conference on Artificial Intelligence
411+
and Statistics (AISTATS) 22, 2019.
412+
413+
[28] Caffarelli, L. A., McCann, R. J. (2020). [Free boundaries in
414+
optimal transport and Monge-Ampere obstacle problems]
415+
(http://www.math.toronto.edu/~mccann/papers/annals2010.pdf), Annals of
416+
mathematics, 673-730.
417+
418+
[29] Chapel, L., Alaya, M., Gasso, G. (2019). [Partial
419+
Gromov-Wasserstein with Applications on Positive-Unlabeled Learning"]
420+
(https://arxiv.org/abs/2002.08276), arXiv preprint arXiv:2002.08276.
421+
394422
.. |PyPI version| image:: https://badge.fury.io/py/POT.svg
395423
:target: https://badge.fury.io/py/POT
396424
.. |Anaconda Cloud| image:: https://anaconda.org/conda-forge/pot/badges/version.svg

0 commit comments

Comments
 (0)