function

transport.matrix.marginal_error

def marginal_error(log_plan: torch.Tensor, a: torch.Tensor, b: torch.Tensor) -> tuple[float, float]

Compute the max marginal error of a log-domain transport plan.

Useful for checking Sinkhorn convergence quality after ``solve()``. Works with any backend that returns a log-plan (``LOG_SINKHORN``, ``UNBALANCED_SINKHORN``, ``EXACT_EMD``).

Parameters

NameTypeDescription
log_plantorch.TensorLog-domain transport plan (B, N, M) or (N, M), as returned by ``solve()``.
atorch.TensorSource marginals (B, N) or (N,). Must match the ``a`` passed to ``solve()``, or uniform weights if ``a=None`` was used.
btorch.TensorTarget marginals (B, M) or (M,).

Returns

(row_err, col_err) — Max absolute deviation of plan row-sums and col-sums from ``a`` and ``b``, respectively.

Source: torchmatch/transport/matrix/_solve.py:231