M6.3 Fifty Thousand Warehouses: Sinkhorn and Minibatch Approximations
Builds on3 notes
A table with 2.5 billion entries
Three-by-three transport needs nine entries. Fifty thousand by fifty thousand needs , about 20 GB for one double-precision matrix alone. Solver costs depend on the algorithm and structure; no single cubic complexity describes every transport LP.
Such sizes arise with image features, customers, or particles. Exact dense computation can become impractical.
We can modify the objective to favor diffuse plans, or restrict each solve to a small sample. What changes in each approach, and how does its result compare with the original cost?
DiscussionQ1
How can computational convenience enter the optimization objective? What quantity does minibatch transport estimate?
Show the reasoning
One modification rewards entropy , encouraging dispersed mass rather than concentration:
This is entropic optimal transport. Positive trades original transport cost against entropy. The raw transport cost of its feasible solution cannot be below the unregularized optimum.
Minibatch OT samples sources and targets and solves their empirical problem. Compare with population . The expected squared cost is no smaller; individual batches can be lower, and taking a square root does not preserve this proof.
Smooth the objective or restrict the endpoints
A finite transport LP admits a vertex optimum with at most positive entries, though not every optimum is a vertex. Dense data representation can remain expensive despite that sparsity.
With positive marginals, finite costs, and , the entropy-regularized optimum is unique and strictly positive on the allowed full table. It has kernel with diagonal scalings on both sides. Alternating row and column normalization finds those scalings.
Minibatches make each table smaller but restrict available partners. Missing nearby destinations in a sampled batch can force longer routes. This is a different source of error from entropy regularization.
Regularization strength and batch size alter different aspects of the coupling.
Sinkhorn
Optimal-plan shape. Introduce row and column Lagrange multipliers and differentiate each entry:
The multipliers give positive factors , so . Only scaling factors remain unknown, though storing and multiplying the kernel can still require work.
Sinkhorn updates. Enforce the two marginal constraints alternately:
Update with fixed, then with fixed. For strictly positive kernels and marginals, Sinkhorn–Knopp scaling converges [3], with reciprocal scale freedom in . Cuturi [1] applied it to entropic OT. Each dense iteration costs ; iteration count depends on the problem, regularization, and tolerance.
For unit total mass, favors the independent coupling . As , solutions approach the unregularized optimal set, selecting by entropy when relevant. Small regularization can slow convergence and cause numerical underflow; larger regularization often eases computation but does not supply a universal runtime guarantee.
Raw cost bias: a feasible satisfies by definition of the exact optimum. Comparing regularized objectives also gives . Distinguish this raw cost from the objective that subtracts entropy.
DetailsLog-domain updates, finite bias bounds, and Sinkhorn divergence
Direct exponentiation can underflow at small ε. Set f=εlogu and g=εlogv. A row update is fᵢ=εlogaᵢ−εlogΣⱼexp((gⱼ−cᵢⱼ)/ε), evaluated with log-sum-exp. Columns update analogously.
For a finite unit-mass table, optimality gives
This is a finite-problem bound, not a universal continuous-law rate.
The Sinkhorn divergence subtracts self terms:
Use one consistent definition of the regularized optimal value, not raw transport costs mixed with regularized values. Equality on identical laws follows by cancellation; further properties need cost and kernel assumptions [5].
Minibatch bias
Sample empirical laws from the two populations and solve their quadratic OT problems. Two statements matter.
Expected squared cost: the optimal transport value is jointly convex in its marginals, because mixtures of feasible plans remain feasible for mixture marginals. Since empirical marginals are unbiased as measures, Jensen gives
For identical continuous populations, population distance is zero while independent finite empirical sets usually differ. Rates depend on dimension, moments, and regularity; there is no universal formula [2,4].
Average pairing: has population marginals and is a valid population coupling. Its expected cost bounds population OT from above. At , independent sampling gives exactly the independent coupling. Large-batch cost convergence needs moment conditions; convergence toward a specified optimizer also requires conditions such as uniqueness.
Both approaches can create less concentrated pairings than an exact map, but minibatch spreading has no universal entropy ordering against every population optimum. Their common cost conclusions also differ: entropic raw cost is bounded for each feasible solve, whereas the population minibatch comparison is an expectation statement.
Choose according to the task
Dense Sinkhorn retains an kernel or equivalent block computations. Minibatches need pairwise storage but introduce sampling effects and within-batch restrictions. Memory, solver accuracy, and intended use determine the tradeoff.
Ask whether the goal is a distance estimate or training pairs. The two approximations can be combined; neither is universally best or the only large-scale option.
Check both marginal residuals and avoid underflow. Positive kernels have the stated scaling guarantee; merely having no entirely zero row or column is insufficient for arbitrary sparse kernels. For minibatches, state the sampling scheme and keep expected squared cost distinct from individual outcomes and expected unsquared distance.
Compare three computations on a smaller problem
import numpy as np
from scipy.special import logsumexp
from scipy.optimize import linear_sum_assignment
rng = np.random.default_rng(0)
n,d = 2000,2
X = rng.normal(0,1,(n,d))
Y = rng.normal(0,1,(n,d))@np.diag([2,.5])+np.array([3,0])
print('population W2 squared:',10.25)
C = ((X[:,None,:]-Y[None,:,:])**2).sum(-1)
r,c = linear_sum_assignment(C)
print('full empirical OT:',C[r,c].mean())
def sinkhorn_log(C,eps,iters=1000):
m,n = C.shape
loga,logb = np.full(m,-np.log(m)),np.full(n,-np.log(n))
f,g = np.zeros(m),np.zeros(n)
for _ in range(iters):
f = eps*(loga-logsumexp((g[None,:]-C)/eps,axis=1))
g = eps*(logb-logsumexp((f[:,None]-C)/eps,axis=0))
logP = (f[:,None]+g[None,:]-C)/eps
P = np.exp(logP)
entropy = -np.sum(P[P>0]*logP[P>0])
residual = max(np.abs(P.sum(1)-np.exp(loga)).sum(),np.abs(P.sum(0)-np.exp(logb)).sum())
return (P*C).sum(),entropy,residual
for eps in [.05,.2,1.,5.]:
print('epsilon, cost, entropy, residual:',eps,*sinkhorn_log(C,eps))
def minibatch_w2(C,B,reps=200):
vals = []
for _ in range(reps):
i = rng.choice(C.shape[0],B,replace=False)
j = rng.choice(C.shape[1],B,replace=False)
S = C[np.ix_(i,j)]
r,c = linear_sum_assignment(S)
vals.append(S[r,c].mean())
return np.mean(vals)
for B in [8,32,128,512]:
print('batch:',B,minibatch_w2(C,B))
Y2 = rng.normal(0,1,(n,d))
C2 = ((X[:,None,:]-Y2[None,:,:])**2).sum(-1)
for B in [8,512]:
print('same population:',B,minibatch_w2(C2,B,50))
Compare population Gaussian cost 10.25 with the full empirical assignment, regularized costs, and minibatch averages. A particular empirical sample can lie above or below the population value; upward bias is an expected squared-cost claim. The displayed subset sampling is conditional on fixed empirical laws, so its expected-cost comparison can also be made against their full empirical optimum.
At small , too few iterations may give a raw cost below exact empirical OT because the approximate matrix has not satisfied both margins. This does not contradict the feasible-coupling bound. Inspect residuals, continue iterations, and use an appropriate stopping criterion before interpreting costs.
For identical populations, independent empirical samples still give positive costs, especially at small batch sizes. This is sampling and minibatch bias rather than a proof the populations differ. Direct-domain kernels at very small regularization can also underflow and break updates; log-domain arithmetic addresses that separate numerical issue.
Inspect coupling, cost, entropy, and marginal residuals as each approximation updates.
Check your understanding
References
- Cuturi, M. Sinkhorn Distances: Lightspeed Computation of Optimal Transport. NeurIPS 2013.
- Peyré, G., Cuturi, M. Computational Optimal Transport. Foundations and Trends in Machine Learning 11(5–6), 2019.
- Sinkhorn, R., Knopp, P. Concerning Nonnegative Matrices and Doubly Stochastic Matrices. Pacific Journal of Mathematics 21(2), 1967.
- Fatras, K., Zine, Y., Flamary, R., Gribonval, R., Courty, N. Learning with Minibatch Wasserstein: Asymptotic and Gradient Properties. AISTATS 2020.
- Genevay, A., Peyré, G., Cuturi, M. Learning Generative Models with Sinkhorn Divergences. AISTATS 2018.