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

Function solve

ot/solvers.py:57–601  ·  view source on GitHub ↗

r"""Solve the discrete optimal transport problem and return :any:`OTResult` object The function solves the following general optimal transport problem .. math:: \min_{\mathbf{T}\geq 0} \quad \sum_{i,j} T_{i,j}M_{i,j} + \lambda_r R(\mathbf{T}) + \lambda_1 U(\mathbf{T}\mathbf

(
    M,
    a=None,
    b=None,
    reg=None,
    c=None,
    reg_type="KL",
    unbalanced=None,
    unbalanced_type="KL",
    method=None,
    n_threads=1,
    max_iter=None,
    plan_init=None,
    potentials_init=None,
    tol=None,
    verbose=False,
    grad="autodiff",
)

Source from the content-addressed store, hash-verified

55
56
57def solve(
58 M,
59 a=None,
60 b=None,
61 reg=None,
62 c=None,
63 reg_type="KL",
64 unbalanced=None,
65 unbalanced_type="KL",
66 method=None,
67 n_threads=1,
68 max_iter=None,
69 plan_init=None,
70 potentials_init=None,
71 tol=None,
72 verbose=False,
73 grad="autodiff",
74):
75 r"""Solve the discrete optimal transport problem and return :any:`OTResult` object
76
77 The function solves the following general optimal transport problem
78
79 .. math::
80 \min_{\mathbf{T}\geq 0} \quad \sum_{i,j} T_{i,j}M_{i,j} + \lambda_r R(\mathbf{T}) +
81 \lambda_1 U(\mathbf{T}\mathbf{1},\mathbf{a}) +
82 \lambda_2 U(\mathbf{T}^T\mathbf{1},\mathbf{b})
83
84 The regularization is selected with `reg` (:math:`\lambda_r`) and `reg_type`. By
85 default ``reg=None`` and there is no regularization. The unbalanced marginal
86 penalization can be selected with `unbalanced` (:math:`(\lambda_1, \lambda_2)`) and
87 `unbalanced_type`. By default ``unbalanced=None`` and the function
88 solves the exact optimal transport problem (respecting the marginals).
89
90 Parameters
91 ----------
92 M : array-like, shape (dim_a, dim_b)
93 Loss matrix
94 a : array-like, shape (dim_a,), optional
95 Samples weights in the source domain (default is uniform)
96 b : array-like, shape (dim_b,), optional
97 Samples weights in the source domain (default is uniform)
98 reg : float, optional
99 Regularization weight :math:`\lambda_r`, by default None (no reg., exact
100 OT)
101 c : array-like, shape (dim_a, dim_b), optional (default=None)
102 Reference measure for the regularization.
103 If None, then use :math:`\mathbf{c} = \mathbf{a} \mathbf{b}^T`.
104 If :math:`\texttt{reg_type}=`'entropy', then :math:`\mathbf{c} = 1_{dim_a} 1_{dim_b}^T`.
105 reg_type : str, optional
106 Type of regularization :math:`R` either "KL", "L2", "entropy",
107 by default "KL". a tuple of functions can be provided for general
108 solver (see :any:`cg`). This is only used when ``reg!=None``.
109 unbalanced : float or indexable object of length 1 or 2
110 Marginal relaxation term.
111 If it is a scalar or an indexable object of length 1,
112 then the same relaxation is applied to both marginal relaxations.
113 The balanced OT can be recovered using :math:`unbalanced=float("inf")`.
114 For semi-relaxed case, use either

Callers 2

test_solve_batchFunction · 0.90
solve_sampleFunction · 0.85

Calls 15

get_backendFunction · 0.85
emd2Function · 0.85
mm_unbalancedFunction · 0.85
lbfgsb_unbalancedFunction · 0.85
cgFunction · 0.85
smooth_ot_dualFunction · 0.85
OTResultClass · 0.85
detachMethod · 0.80
sinkhorn_logFunction · 0.70
onesMethod · 0.45
sumMethod · 0.45

Tested by 1

test_solve_batchFunction · 0.72