Skip to content

Commit 4e2f6b4

Browse files
committed
first shot part OT Wass
1 parent 8c93520 commit 4e2f6b4

File tree

4 files changed

+126
-27
lines changed

4 files changed

+126
-27
lines changed

docs/source/howto.rst

Lines changed: 0 additions & 25 deletions
This file was deleted.

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Contents
1313
:maxdepth: 3
1414

1515
self
16-
howto
16+
quickstart
1717
all
1818
auto_examples/index
1919

docs/source/quickstart.rst

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
2+
Quick start
3+
===========
4+
5+
6+
7+
In the following we provide some pointers about which functions and classes
8+
to use for different problems related to optimal transport (OT).
9+
10+
11+
Optimal transport and Wasserstein distance
12+
------------------------------------------
13+
14+
The optimal transport problem between discrete distributions is often expressed
15+
as
16+
.. math::
17+
\gamma^* = arg\min_\gamma \sum_{i,j}\gamma_{i,j}M_{i,j}
18+
19+
s.t. \gamma 1 = a; \gamma^T 1= b; \gamma\geq 0
20+
21+
where :
22+
23+
- :math:`M\in\mathbb{R}_+^{m\times n}` is the metric cost matrix defining the cost to move mass from bin :math:`a_i` to bin :math:`b_j`.
24+
- :math:`a` and :math:`b` are histograms (positive, sum to 1) that represent the weights of each samples in the source an target distributions.
25+
26+
Solving the linear program above can be done using the function :any:`ot.emd`
27+
that will return the optimal transport matrix :math:`\gamma^*`:
28+
29+
.. code:: python
30+
31+
# a,b are 1D histograms (sum to 1 and positive)
32+
# M is the ground cost matrix
33+
T=ot.emd(a,b,M) # exact linear program
34+
35+
.. hint::
36+
Examples of use for :any:`ot.emd` are available in the following examples:
37+
38+
- :any:`auto_examples/plot_OT_2D_samples`
39+
- :any:`auto_examples/plot_OT_1D`
40+
- :any:`auto_examples/plot_OT_L1_vs_L2`
41+
42+
43+
The value of the OT solution is often more of interest that the OT matrix :
44+
45+
.. math::
46+
W(a,b)=\min_\gamma \sum_{i,j}\gamma_{i,j}M_{i,j}
47+
48+
s.t. \gamma 1 = a; \gamma^T 1= b; \gamma\geq 0
49+
50+
51+
where :math:`W(a,b)` is the `Wasserstein distance
52+
<https://en.wikipedia.org/wiki/Wasserstein_metric>`_ between distributions a and b
53+
It is a metrix that has nice statistical
54+
properties. It can computed from an already estimated OT matrix with
55+
:code:`np.sum(T*M)` or directly with the function :any:`ot.emd2`.
56+
57+
.. code:: python
58+
59+
# a,b are 1D histograms (sum to 1 and positive)
60+
# M is the ground cost matrix
61+
W=ot.emd2(a,b,M) # Wasserstein distance / EMD value
62+
63+
.. note::
64+
In POT, most functions that solve OT or regularized OT problems have two
65+
versions that return the OT matrix or the value of the optimal solution. Fir
66+
instance :any:`ot.emd` return the OT matrix and :any:`ot.emd2` return the
67+
Wassertsein distance.
68+
69+
70+
Regularized Optimal Transport
71+
-----------------------------
72+
73+
Wasserstein Barycenters
74+
-----------------------
75+
76+
Monge mapping and Domain adaptation with Optimal transport
77+
----------------------------------------
78+
79+
80+
Other applications
81+
------------------
82+
83+
84+
GPU acceleration
85+
----------------
86+
87+
88+
89+
How to?
90+
-------
91+
92+
93+
94+
1. **How to solve a discrete optimal transport problem ?**
95+
96+
The solver for discrete is the function :py:mod:`ot.emd` that returns
97+
the OT transport matrix. If you want to solve a regularized OT you can
98+
use :py:mod:`ot.sinkhorn`.
99+
100+
101+
102+
Here is a simple use case:
103+
104+
.. code:: python
105+
106+
# a,b are 1D histograms (sum to 1 and positive)
107+
# M is the ground cost matrix
108+
T=ot.emd(a,b,M) # exact linear program
109+
T_reg=ot.sinkhorn(a,b,M,reg) # entropic regularized OT
110+
111+
More detailed examples can be seen on this
112+
:doc:`auto_examples/plot_OT_2D_samples`
113+
114+
115+
2. **Compute a Wasserstein distance**
116+
117+
118+
119+

docs/source/readme.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,12 @@ nbviewer <https://nbviewer.jupyter.org/github/rflamary/POT/tree/master/notebooks
206206
Acknowledgements
207207
----------------
208208

209-
The contributors to this library are:
209+
This toolbox has been created and is maintained by
210+
211+
- `Rémi Flamary <http://remi.flamary.com/>`__
212+
- `Nicolas Courty <http://people.irisa.fr/Nicolas.Courty/>`__
213+
214+
The contributors to this library are
210215

211216
- `Rémi Flamary <http://remi.flamary.com/>`__
212217
- `Nicolas Courty <http://people.irisa.fr/Nicolas.Courty/>`__

0 commit comments

Comments
 (0)