r""" Solves the partial optimal transport problem for the quadratic cost and returns the partial GW discrepancy The function considers the following problem: .. math:: \gamma = \min_\gamma \quad \langle \gamma, \mathbf{M} \rangle_F .. math:: s.t. \ \gamma \math
(a, b, M, m=None, nb_dummies=1, log=False, **kwargs)
| 329 | |
| 330 | |
| 331 | def partial_wasserstein2(a, b, M, m=None, nb_dummies=1, log=False, **kwargs): |
| 332 | r""" |
| 333 | Solves the partial optimal transport problem for the quadratic cost |
| 334 | and returns the partial GW discrepancy |
| 335 | |
| 336 | The function considers the following problem: |
| 337 | |
| 338 | .. math:: |
| 339 | \gamma = \min_\gamma \quad \langle \gamma, \mathbf{M} \rangle_F |
| 340 | |
| 341 | .. math:: |
| 342 | s.t. \ \gamma \mathbf{1} &\leq \mathbf{a} |
| 343 | |
| 344 | \gamma^T \mathbf{1} &\leq \mathbf{b} |
| 345 | |
| 346 | \gamma &\geq 0 |
| 347 | |
| 348 | \mathbf{1}^T \gamma^T \mathbf{1} = m &\leq \min\{\|\mathbf{a}\|_1, \|\mathbf{b}\|_1\} |
| 349 | |
| 350 | |
| 351 | where : |
| 352 | |
| 353 | - :math:`\mathbf{M}` is the metric cost matrix |
| 354 | - :math:`\mathbf{a}` and :math:`\mathbf{b}` are source and target unbalanced distributions |
| 355 | - `m` is the amount of mass to be transported |
| 356 | |
| 357 | Parameters |
| 358 | ---------- |
| 359 | a : np.ndarray (dim_a,) |
| 360 | Unnormalized histogram of dimension `dim_a` |
| 361 | b : np.ndarray (dim_b,) |
| 362 | Unnormalized histograms of dimension `dim_b` |
| 363 | M : np.ndarray (dim_a, dim_b) |
| 364 | cost matrix for the quadratic cost |
| 365 | m : float, optional |
| 366 | amount of mass to be transported |
| 367 | nb_dummies : int, optional, default:1 |
| 368 | number of reservoir points to be added (to avoid numerical |
| 369 | instabilities, increase its value if an error is raised) |
| 370 | log : bool, optional |
| 371 | record log if True |
| 372 | **kwargs : dict |
| 373 | parameters can be directly passed to the emd solver |
| 374 | |
| 375 | |
| 376 | .. warning:: |
| 377 | When dealing with a large number of points, the EMD solver may face |
| 378 | some instabilities, especially when the mass associated to the dummy |
| 379 | point is large. To avoid them, increase the number of dummy points |
| 380 | (allows a smoother repartition of the mass over the points). |
| 381 | |
| 382 | |
| 383 | Returns |
| 384 | ------- |
| 385 | GW: float |
| 386 | partial GW discrepancy |
| 387 | log : dict |
| 388 | log dictionary returned only if `log` is `True` |
nothing calls this directly
no test coverage detected