optora.divergences.entropic_transport¶
Entropic optimal transport cost relative to a kernel-smoothed reference.
EntropicTransportDivergence
¶
Bases: Divergence
Excess entropic transport cost of a candidate over its smoothed reference.
For a reference distribution q and a candidate p on a shared finite
support with ground cost \(C\), a regularization strength \(\epsilon > 0\),
and a reference measure \(\nu\) on the support, the Sinkhorn distance of
Wang, Gao and Xie (2025) is
with \(H\) the relative entropy. Its minimum over p is attained at the
kernel-smoothed reference \(P^0 = q^\top Q\), where
\(Q_{ij} \propto \nu_j e^{-C_{ij}/\epsilon}\) is the row-stochastic Gibbs
kernel, and subtracting that minimum leaves
the second form being the concave semi-dual over column potentials
\(g\). It is nonnegative and vanishes exactly at its centre \(P^0\), not at
p == q, because entropic smoothing moves the centre of the ball off
the reference. optora.dro.SinkhornAmbiguitySet bounds this quantity
by its radius.
The semi-dual is maximized in two phases. Both stop once the L1
column-marginal violation, which is the norm of the semi-dual's
gradient, falls below tol.
- Sinkhorn scaling in the log domain, \(O(n^2)\) per iteration. It converges linearly at a rate that degrades as \(\max C/\epsilon\) grows, and at a sharp kernel it stalls far from the maximum.
- If Sinkhorn stops short, a Levenberg-Marquardt damped Newton method on the semi-dual with its exact Hessian (Brauer et al. 2017), \(O(n^3)\) per iteration, warm-started from the Sinkhorn potentials. A step is kept unless it lowers the semi-dual by more than the rounding error of its evaluation. The damping falls after every accepted step, so the method becomes a pure Newton method near the maximum, where it converges quadratically however sharp the kernel is.
The value returned is \(\epsilon\) times the semi-dual at the final potentials. Every dual point bounds the divergence from below, so an inexact solve can only understate it. Near the maximum the understatement is second order in the marginal violation, whereas the primal objective of the transport plan would be off to first order. The potentials are held fixed under autograd, so by the envelope theorem the gradient is exact once the solve has converged.
Zero-mass entries of either marginal are excluded from the solve exactly rather than clamped. A row with \(q_i = 0\) transports nothing, and a column with \(p_j = 0\) takes the potential \(-\infty\), the semi-dual's maximizer in that coordinate, which removes it from every row's normalizer. The value is then that of the problem restricted to the two supports, with no accuracy floor. The derivative with respect to the mass of an empty column is \(-\infty\), the slope of \(t \log t\) at zero. It is not representable, and autograd reports zero for it.
Attributes:
| Name | Type | Description |
|---|---|---|
cost |
Tensor
|
Square ground cost matrix of shape |
reference |
Tensor
|
Nonnegative reference measure \(\nu\) of shape |
epsilon |
Positive entropic regularization strength. |
|
max_iter |
Maximum number of Sinkhorn scaling iterations. |
|
newton_max_iter |
Maximum number of damped Newton iterations run
after Sinkhorn stops short of |
|
tol |
Convergence tolerance on the L1 column-marginal violation, floored at \(n\) times the machine epsilon of the working dtype, the rounding floor of the violation itself. |
|
eps |
Deprecated and unused. It is |
|
check_interval |
Sinkhorn iterations between host reads of the convergence flag. The potentials freeze once converged. The Newton phase, whose iterations are expensive, reads the flag after every iteration. |
__init__(cost, epsilon, reference=None, max_iter=1000, newton_max_iter=50, tol=1e-09, eps=None, check_interval=DEFAULT_CHECK_INTERVAL, validate=False)
¶
Initialize the entropic transport divergence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cost
|
Tensor
|
Square ground cost matrix of shape |
required |
epsilon
|
float
|
Positive entropic regularization strength. |
required |
reference
|
Tensor | None
|
Nonnegative reference measure of shape |
None
|
max_iter
|
int
|
Maximum number of Sinkhorn scaling iterations. |
1000
|
newton_max_iter
|
int
|
Maximum number of damped Newton iterations
run after Sinkhorn stops short of |
50
|
tol
|
float
|
Convergence tolerance on the L1 column-marginal violation,
over the whole batched problem. It is floored at |
1e-09
|
eps
|
float | None
|
Deprecated and ignored. Zero-mass marginal entries are
excluded from the solve exactly, so there is nothing left to
clamp. Passing it emits a |
None
|
check_interval
|
int
|
Sinkhorn iterations between host reads of the convergence flag. |
DEFAULT_CHECK_INTERVAL
|
validate
|
bool
|
Whether to check that |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
log_kernel(dtype)
¶
Return the row-stochastic Gibbs kernel \(\log Q\) in dtype.
The kernel is \(\log Q_{ij} = \log \nu_j - C_{ij}/\epsilon - \log
\sum_k \nu_k e^{-C_{ik}/\epsilon}\), normalized by logsumexp so
that a large cost over a small \(\epsilon\) never underflows a whole
row. Columns with \(\nu_j = 0\) are exactly -inf.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtype
|
dtype
|
Floating-point dtype to compute in. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
A tensor of shape |
Tensor
|
distributions. |
forward(p, q)
¶
Compute the excess entropic transport cost of p over q.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
Tensor
|
Candidate distribution of shape |
required |
q
|
Tensor
|
Reference distribution of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
\(D(p \,\|\, q)\) over the broadcast batch, clamped to be |
Tensor
|
nonnegative, computed in |
Tensor
|
and returned in the promoted dtype of |
Tensor
|
with mass where \(\nu\) has none admits no coupling and returns |
Tensor
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the last dimension of |