|
| 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 | + |
0 commit comments