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

Function partial_wasserstein

ot/partial/partial_solvers.py:187–328  ·  view source on GitHub ↗

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} \rangle_F .. math:: s.t. \ \gamma \mathb

(a, b, M, m=None, nb_dummies=1, log=False, **kwargs)

Source from the content-addressed store, hash-verified

185
186
187def partial_wasserstein(a, b, M, m=None, nb_dummies=1, log=False, **kwargs):
188 r"""
189 Solves the partial optimal transport problem for the quadratic cost
190 and returns the OT plan
191
192 The function considers the following problem:
193
194 .. math::
195 \gamma = \mathop{\arg \min}_\gamma \quad \langle \gamma, \mathbf{M} \rangle_F
196
197 .. math::
198 s.t. \ \gamma \mathbf{1} &\leq \mathbf{a}
199
200 \gamma^T \mathbf{1} &\leq \mathbf{b}
201
202 \gamma &\geq 0
203
204 \mathbf{1}^T \gamma^T \mathbf{1} = m &\leq \min\{\|\mathbf{a}\|_1, \|\mathbf{b}\|_1\}
205
206
207 where :
208
209 - :math:`\mathbf{M}` is the metric cost matrix
210 - :math:`\mathbf{a}` and :math:`\mathbf{b}` are source and target unbalanced distributions
211 - `m` is the amount of mass to be transported
212
213 Parameters
214 ----------
215 a : np.ndarray (dim_a,)
216 Unnormalized histogram of dimension `dim_a`
217 b : np.ndarray (dim_b,)
218 Unnormalized histograms of dimension `dim_b`
219 M : np.ndarray (dim_a, dim_b)
220 cost matrix for the quadratic cost
221 m : float, optional
222 amount of mass to be transported
223 nb_dummies : int, optional, default:1
224 number of reservoir points to be added (to avoid numerical
225 instabilities, increase its value if an error is raised)
226 log : bool, optional
227 record log if True
228 **kwargs : dict
229 parameters can be directly passed to the emd solver
230
231
232 .. warning::
233 When dealing with a large number of points, the EMD solver may face
234 some instabilities, especially when the mass associated to the dummy
235 point is large. To avoid them, increase the number of dummy points
236 (allows a smoother repartition of the mass over the points).
237
238
239 Returns
240 -------
241 gamma : (dim_a, dim_b) ndarray
242 Optimal transportation matrix for the given parameters
243 log : dict
244 log dictionary returned only if `log` is `True`

Callers 1

partial_wasserstein2Function · 0.85

Calls 11

list_to_arrayFunction · 0.85
get_backendFunction · 0.85
emdFunction · 0.85
onesMethod · 0.45
minMethod · 0.45
stackMethod · 0.45
sumMethod · 0.45
concatenateMethod · 0.45
maxMethod · 0.45
zerosMethod · 0.45

Tested by

no test coverage detected