r""" Solves the partial optimal transport problem for the quadratic cost and returns the OT plan The function considers the following problem: .. math:: \gamma = \mathop{\arg \min}_\gamma \quad \langle \gamma, (\mathbf{M} - \lambda) \rangle_F .. math:: s.t. \ \
(
a, b, M, reg_m=None, nb_dummies=1, log=False, **kwargs
)
| 18 | |
| 19 | |
| 20 | def partial_wasserstein_lagrange( |
| 21 | a, b, M, reg_m=None, nb_dummies=1, log=False, **kwargs |
| 22 | ): |
| 23 | r""" |
| 24 | Solves the partial optimal transport problem for the quadratic cost |
| 25 | and returns the OT plan |
| 26 | |
| 27 | The function considers the following problem: |
| 28 | |
| 29 | .. math:: |
| 30 | \gamma = \mathop{\arg \min}_\gamma \quad \langle \gamma, (\mathbf{M} - \lambda) \rangle_F |
| 31 | |
| 32 | .. math:: |
| 33 | s.t. \ \gamma \mathbf{1} &\leq \mathbf{a} |
| 34 | |
| 35 | \gamma^T \mathbf{1} &\leq \mathbf{b} |
| 36 | |
| 37 | \gamma &\geq 0 |
| 38 | |
| 39 | \mathbf{1}^T \gamma^T \mathbf{1} = m & |
| 40 | \leq \min\{\|\mathbf{a}\|_1, \|\mathbf{b}\|_1\} |
| 41 | |
| 42 | |
| 43 | or equivalently (see Chizat, L., Peyré, G., Schmitzer, B., & Vialard, F. X. |
| 44 | (2018). An interpolating distance between optimal transport and Fisher–Rao |
| 45 | metrics. Foundations of Computational Mathematics, 18(1), 1-44.) |
| 46 | |
| 47 | .. math:: |
| 48 | \gamma = \mathop{\arg \min}_\gamma \quad \langle \gamma, \mathbf{M} \rangle_F + |
| 49 | \sqrt{\frac{\lambda}{2} (\|\gamma \mathbf{1} - \mathbf{a}\|_1 + \|\gamma^T \mathbf{1} - \mathbf{b}\|_1)} |
| 50 | |
| 51 | s.t. \ \gamma \geq 0 |
| 52 | |
| 53 | |
| 54 | where : |
| 55 | |
| 56 | - :math:`\mathbf{M}` is the metric cost matrix |
| 57 | - :math:`\mathbf{a}` and :math:`\mathbf{b}` are source and target unbalanced distributions |
| 58 | - :math:`\lambda` is the lagrangian cost. Tuning its value allows attaining |
| 59 | a given mass to be transported `m` |
| 60 | |
| 61 | The formulation of the problem has been proposed in |
| 62 | :ref:`[28] <references-partial-wasserstein-lagrange>` |
| 63 | |
| 64 | |
| 65 | Parameters |
| 66 | ---------- |
| 67 | a : np.ndarray (dim_a,) |
| 68 | Unnormalized histogram of dimension `dim_a` |
| 69 | b : np.ndarray (dim_b,) |
| 70 | Unnormalized histograms of dimension `dim_b` |
| 71 | M : np.ndarray (dim_a, dim_b) |
| 72 | cost matrix for the quadratic cost |
| 73 | reg_m : float, optional |
| 74 | Lagrangian cost |
| 75 | nb_dummies : int, optional, default:1 |
| 76 | number of reservoir points to be added (to avoid numerical |
| 77 | instabilities, increase its value if an error is raised) |
no test coverage detected