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

Function solve_sample

ot/solvers.py:1351–1985  ·  view source on GitHub ↗

r"""Solve the discrete optimal transport problem using the samples in the source and target domains. 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_u U

(
    X_a,
    X_b,
    a=None,
    b=None,
    metric="sqeuclidean",
    reg=None,
    c=None,
    reg_type="KL",
    unbalanced=None,
    unbalanced_type="KL",
    lazy=False,
    batch_size=None,
    method=None,
    n_threads=1,
    max_iter=None,
    plan_init=None,
    rank=100,
    scaling=0.95,
    potentials_init=None,
    X_init=None,
    tol=None,
    verbose=False,
    grad="autodiff",
    random_state=None,
)

Source from the content-addressed store, hash-verified

1349
1350
1351def solve_sample(
1352 X_a,
1353 X_b,
1354 a=None,
1355 b=None,
1356 metric="sqeuclidean",
1357 reg=None,
1358 c=None,
1359 reg_type="KL",
1360 unbalanced=None,
1361 unbalanced_type="KL",
1362 lazy=False,
1363 batch_size=None,
1364 method=None,
1365 n_threads=1,
1366 max_iter=None,
1367 plan_init=None,
1368 rank=100,
1369 scaling=0.95,
1370 potentials_init=None,
1371 X_init=None,
1372 tol=None,
1373 verbose=False,
1374 grad="autodiff",
1375 random_state=None,
1376):
1377 r"""Solve the discrete optimal transport problem using the samples in the source and target domains.
1378
1379 The function solves the following general optimal transport problem
1380
1381 .. math::
1382 \min_{\mathbf{T}\geq 0} \quad \sum_{i,j} T_{i,j}M_{i,j} + \lambda_r R(\mathbf{T}) +
1383 \lambda_u U(\mathbf{T}\mathbf{1},\mathbf{a}) +
1384 \lambda_u U(\mathbf{T}^T\mathbf{1},\mathbf{b})
1385
1386 where the cost matrix :math:`\mathbf{M}` is computed from the samples in the
1387 source and target domains such that :math:`M_{i,j} = d(x_i,y_j)` where
1388 :math:`d` is a metric (by default the squared Euclidean distance).
1389
1390 The regularization is selected with `reg` (:math:`\lambda_r`) and `reg_type`. By
1391 default ``reg=None`` and there is no regularization. The unbalanced marginal
1392 penalization can be selected with `unbalanced` (:math:`\lambda_u`) and
1393 `unbalanced_type`. By default ``unbalanced=None`` and the function
1394 solves the exact optimal transport problem (respecting the marginals).
1395
1396 Parameters
1397 ----------
1398 X_a : array-like, shape (n_samples_a, dim)
1399 samples in the source domain
1400 X_b : array-like, shape (n_samples_b, dim)
1401 samples in the target domain
1402 a : array-like, shape (dim_a,), optional
1403 Samples weights in the source domain (default is uniform)
1404 b : array-like, shape (dim_b,), optional
1405 Samples weights in the source domain (default is uniform)
1406 reg : float, optional
1407 Regularization weight :math:`\lambda_r`, by default None (no reg., exact
1408 OT)

Callers

nothing calls this directly

Calls 11

solveFunction · 0.85
get_backendFunction · 0.85
wasserstein_1dFunction · 0.85
lowrank_sinkhornFunction · 0.85
empirical_sinkhorn2Function · 0.85
OTResultClass · 0.85
distFunction · 0.70

Tested by

no test coverage detected