MCPcopy Create free account
hub / github.com/PythonOT/POT / partial_wasserstein2

Function partial_wasserstein2

ot/partial/partial_solvers.py:331–423  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

329
330
331def 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`

Callers

nothing calls this directly

Calls 4

list_to_arrayFunction · 0.85
get_backendFunction · 0.85
partial_wassersteinFunction · 0.85
sumMethod · 0.45

Tested by

no test coverage detected