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

Function weak_optimal_transport

ot/weak.py:16–130  ·  view source on GitHub ↗

r"""Solves the weak optimal transport problem between two empirical distributions .. math:: \gamma = \mathop{\arg \min}_\gamma \quad \sum_i \mathbf{a}_i \left(\mathbf{X^a}_i - \frac{1}{\mathbf{a}_i} \sum_j \gamma_{ij} \mathbf{X^b}_j \right)^2 s.t. \ \gamma \mathbf{1} = \mathbf

(
    Xa, Xb, a=None, b=None, verbose=False, log=False, G0=None, **kwargs
)

Source from the content-addressed store, hash-verified

14
15
16def weak_optimal_transport(
17 Xa, Xb, a=None, b=None, verbose=False, log=False, G0=None, **kwargs
18):
19 r"""Solves the weak optimal transport problem between two empirical distributions
20
21
22 .. math::
23 \gamma = \mathop{\arg \min}_\gamma \quad \sum_i \mathbf{a}_i \left(\mathbf{X^a}_i - \frac{1}{\mathbf{a}_i} \sum_j \gamma_{ij} \mathbf{X^b}_j \right)^2
24
25 s.t. \ \gamma \mathbf{1} = \mathbf{a}
26
27 \gamma^T \mathbf{1} = \mathbf{b}
28
29 \gamma \geq 0
30
31 where :
32
33 - :math:`X^a` and :math:`X^b` are the sample matrices.
34 - :math:`\mathbf{a}` and :math:`\mathbf{b}` are the sample weights
35
36
37 .. note:: This function is backend-compatible and will work on arrays
38 from all compatible backends. But the algorithm uses the C++ CPU backend
39 which can lead to copy overhead on GPU arrays.
40
41 Uses the conditional gradient algorithm to solve the problem proposed
42 in :ref:`[39] <references-weak>`.
43
44 Parameters
45 ----------
46 Xa : (ns,d) array-like, float
47 Source samples
48 Xb : (nt,d) array-like, float
49 Target samples
50 a : (ns,) array-like, float
51 Source histogram (uniform weight if empty list)
52 b : (nt,) array-like, float
53 Target histogram (uniform weight if empty list))
54 G0 : (ns,nt) array-like, float
55 initial guess (default is indep joint density)
56 numItermax : int, optional
57 Max number of iterations
58 numItermaxEmd : int, optional
59 Max number of iterations for emd
60 stopThr : float, optional
61 Stop threshold on the relative variation (>0)
62 stopThr2 : float, optional
63 Stop threshold on the absolute variation (>0)
64 verbose : bool, optional
65 Print information along iterations
66 log : bool, optional
67 record log if True
68
69
70 Returns
71 -------
72 gamma: array-like, shape (ns, nt)
73 Optimal transportation matrix for the given

Callers

nothing calls this directly

Calls 5

get_backendFunction · 0.85
cgFunction · 0.85
to_numpyMethod · 0.80
from_numpyMethod · 0.80
onesMethod · 0.45

Tested by

no test coverage detected