14 Optimal Transport and Sinkhorn Generative Modelling
Why Optimal Transport?
In Chapter 10 we replaced the Jensen–Shannon divergence with the Wasserstein-1 distance and showed that it gives the generator a meaningful gradient even when the data and model distributions have disjoint support. The Kantorovich–Rubinstein dual let us estimate with a Lipschitz-constrained critic, but we never actually computed the optimal transport plan, the map that tells us how to move mass from one distribution to the other.
This chapter fills that gap. We develop the theory of optimal transport from the ground up, derive an efficient algorithm, the Sinkhorn iteration, for computing an entropy-regularised transport plan, and show how it can be used as a drop-in loss for generative modelling.
Key Idea.
Optimal transport provides two things at once: a distance between distributions (how hard is it to morph into ?), and a transport plan (which part of should go where?). The distance measures quality; the plan provides geometric insight.
The Assignment Problem
We begin with the simplest version of the problem. Given two sets of points, and , and a cost function , we seek a one-to-one pairing that minimises the total cost:
Definition 1 (Assignment Problem).
(Assignment) where denotes the set of all permutations of .
A brute-force search considers all permutations, clearly intractable for any non-trivial . The Hungarian algorithm [1] solves the assignment problem in time.
Remark 1 (Limitations of the Assignment Formulation).
The assignment problem has three key limitations that motivate the move to optimal transport:
Equal cardinality: it requires .
No out-of-sample extension: a new point (Figure fig:sink:assignment) requires re-solving from scratch.
Cubic complexity: is prohibitive for the sample sizes () common in generative modelling.
Historical Note.
The problem of transporting mass at minimum cost was first posed by Gaspard Monge in 1781, who asked how to move a pile of earth to fill a hole of the same volume at minimum effort. In 1942, Leonid Kantorovich reformulated the problem by relaxing Monge's deterministic map to a probabilistic coupling, enabling linear-programming techniques. Kuhn [1] developed the Hungarian algorithm for the discrete case in 1955, crediting the Hungarian mathematicians König and Egerváry. For a historical account, see [2]. The modern computational breakthrough came from Cuturi [3], who showed that adding an entropic penalty reduces the complexity to near-linear time.
The Kantorovich Formulation
Kantorovich's insight was to replace Monge's deterministic map with a probabilistic coupling: instead of sending all the mass at to a single destination, we allow it to be split across multiple destinations.
Transport Plans and Couplings
Definition 2 (Kantorovich Optimal Transport).
Let and be discrete probability vectors (so ), and let be a cost matrix with entry . The coupling polytope is (Coupling) and the optimal transport cost is (OT) Each represents the amount of mass moved from source to destination . The marginal constraints ensure that all mass is transported and all capacity is filled.
Proposition 1 (Existence of an Optimal Plan).
The coupling polytope is a non-empty, convex, and compact subset of . Consequently, the linear objective attains its minimum on , and an optimal transport plan always exists.
Proof.
Non-empty: The product distribution satisfies both marginal constraints.
Convex: is the intersection of the non-negative orthant (convex) with affine hyperplanes (the marginal constraints), hence convex.
Compact: (since all entries are non-negative and each row and column sums to at most ), so it is bounded. It is also closed (intersection of closed sets). Bounded and closed in implies compact.
Existence follows from the extreme value theorem: a continuous function on a compact set attains its minimum.
Example 1 (Wasserstein-1 as Optimal Transport).
When and , the optimal transport cost becomes the Wasserstein-1 distance: This is exactly the distance used in the WGAN objective (Chapter 10), providing the bridge between the GAN training loss and the transport-theoretic framework developed here.
OT as a Linear Program
Definition 3 (OT as Linear Program).
Kantorovich Duality
The LP has a dual that provides a powerful computational and theoretical tool.
Theorem 1 (Kantorovich Duality).
The optimal transport cost satisfies the strong duality relation (DUAL) where and are the dual variables (also called Kantorovich potentials).
Proof.
Equation is an LP in standard form. The primal is feasible (the product coupling ) and bounded below (all costs are non-negative). LP strong duality then gives . For full details, see any LP text [4].
Remark 2 (Connection to the KR Dual).
When and both distributions are continuous, the constraint reduces to being -Lipschitz (with ), recovering the Kantorovich–Rubinstein representation used in Chapter 10. The Sinkhorn approach developed below solves the primal instead.
Entropic Regularisation
The cubic complexity of LP solvers makes direct computation of impractical for the sample sizes common in machine learning (). Cuturi [3] observed that adding a small entropy penalty to the objective yields a problem that can be solved in near-linear time.
Definition 4 (Entropy-Regularised OT).
For a regularisation parameter , the entropy-regularised optimal transport cost is (Entot) where is the (discrete) entropy of the plan.
Proposition 2 (Unique Optimal Plan).
Proof.
The linear term is convex (linear). The negative entropy has Hessian on the interior of . Since , we have , so is -strongly convex with respect to the norm. Scaling by gives -strong convexity of the full objective. A strongly convex function on a compact convex set has a unique minimiser.
Proposition 3 (Limiting Behaviour).
As , and converges to the maximum-entropy optimal plan.
As , (the product coupling), and .
Proof.
Part (i): As , the entropy penalty vanishes, so any minimiser of must also minimise on . Among the (possibly multiple) LP optima, the limit selects the one with maximum entropy (a consequence of -convergence of the regularised objective to the unregularised one).
Part (ii): As , the objective is dominated by , so the minimiser maximises entropy. Among all couplings with marginals and , the maximum-entropy coupling is the independent coupling (by the product rule for entropy: for any , with equality iff ).
Reformulation as KL Projection
Define the Gibbs kernel (Gibbs) so that is a probability distribution on . We now show that the entropy-regularised problem reduces to a KL projection.
Proposition 4 (Entropic OT as KL Minimisation).
(KL)
Proof.
Expanding the KL divergence: Since is independent of , minimising over is equivalent to minimising , which is times the objective in .
The Sinkhorn Algorithm
The KL reformulation reveals that the entropy-regularised problem is a projection of onto the intersection of two affine sets: the row-marginal constraint and the column-marginal constraint , so that . This is precisely the setting of alternating Bregman projections.
Alternating KL Projections
Definition 5 (Marginal Constraint Sets).
(PIP) Both are affine subsets of .
The alternating projection scheme initialises and iterates: (Altproj)
Closed-Form Projections
Proposition 5 (Row Projection).
The KL projection onto is (Rowproj) In matrix form: , where denotes element-wise division.
Proof.
We minimise subject to . Introducing Lagrange multipliers : Setting : Summing over and using the constraint : Substituting back gives .
By an identical argument with roles of rows and columns swapped:
Proposition 6 (Column Projection).
The KL projection onto is (Colproj) In matrix form: .
Matrix Scaling Form
The alternating projections suggest a diagonal scaling structure.
Theorem 2 (Sinkhorn Factorisation).
The entropy-regularised optimal plan has the form (Factor) for unique vectors , , where .
Proof.
Consider the full Lagrangian of with dual variables (row marginals) and (column marginals): Setting : Defining and , we obtain , which in matrix form is . The vectors are strictly positive since the exponential function is positive. Uniqueness (up to a common scalar) follows from the strict convexity of the objective.
Theorem 3 (Sinkhorn Iterations).
Proof.
We show by induction that the dual iterates produce the same plans as the primal alternating projections. Write .
Row update. Starting from , the row projection gives: where .
Column update. Similarly, the column projection gives with .
Convergence follows from the general theory of alternating Bregman projections onto affine sets [5]: the iterates converge to the unique point in that is closest to in KL divergence.
Algorithm 1 (Sinkhorn Algorithm).
Input: cost matrix , marginals , , regularisation , iterations . Output: approximate transport plan .
Compute the Gibbs kernel: .
Initialise .
For : enumerate
(row normalisation)
(column normalisation) enumerate
Return .
Each iteration costs (two matrix–vector products), so the total complexity is , near-linear when is a small constant.
Proposition 7 (Linear Convergence).
The Sinkhorn iterates converge linearly: there exists a contraction rate , depending on and the cost matrix , such that In practice, – iterations suffice for high accuracy. As , the rate and more iterations are needed; as , (instant convergence to the product coupling).
Example 2 (Worked Example).
Let , , , and Starting from :
.
, and so on.
After iterations the marginal violation is about , so the plan reproduces and to roughly eleven decimal places. True machine precision in double arithmetic (around ) takes about here. The gap between those two figures is a useful calibration: convergence is linear, so each additional handful of iterations buys several more digits, and is large relative to the costs in this instance, which makes the contraction unusually fast. Harder instances with smaller need the to quoted in Proposition Proposition 7.
Sinkhorn Divergence
The entropy-regularised cost has a subtle defect: it does not vanish when . Two separate effects are at work, and it is worth keeping them apart.
First, the entropy term rewards spreading, so the optimal plan is no longer the identity coupling even when the two distributions are the same, and the transport bill is therefore strictly positive where the unregularised optimum was zero. Second, the objective subtracts , and since this pushes the reported value down: with , and , the optimum has and , giving .
So , which is all the defect requires, but the sign depends on which term dominates and is not in general positive. This is why the repair below subtracts the two self-comparison terms rather than simply shifting by a constant.
Definition 6 (Sinkhorn Divergence).
The Sinkhorn divergence [6] is the debiased quantity (Divergence)
Proposition 8 (Properties of the Sinkhorn Divergence).
The Sinkhorn divergence satisfies:
Non-negativity: .
Identity of indiscernibles: if and only if .
Metrisation of weak convergence: if and only if weakly.
Interpolation: as , (unregularised OT); as , (the maximum mean discrepancy with kernel ) [7].
Insight.
The unregularised Wasserstein distance suffers from a curse of dimensionality: estimating it from samples in has error , which is catastrophically slow for images (). For the Sinkhorn divergence the situation is far better: the error decays at the dimension-free rate , so the exponent no longer degrades as grows. This is why entropic OT is the practical choice for generative modelling.
Be precise about what is and is not dimension-free here. It is the rate in . The constant is not: the bound of Genevay et al. [8] carries a factor , which grows with the dimension and blows up as . So is not a free parameter that can be sent to zero to recover unregularised OT while keeping the good rate; shrinking it trades the constant away. This is the statistical counterpart of the numerical tension described below, and it is why is tuned rather than minimised.
Caution.
The regularisation parameter requires careful tuning:
Too small (): the Gibbs kernel has entries near or , causing numerical underflow and slow convergence.
Too large (): the optimal plan approaches the independent coupling , losing all geometric information about the cost.
In practice, is set to a small fraction of the median pairwise cost.
Sinkhorn Generative Modelling
We now show how the Sinkhorn algorithm provides a differentiable loss function for training a generative model.
Architecture and Loss
Let be a generator network with parameters . Given a mini-batch of real samples and generated samples with , , we compute the pairwise cost matrix , run Sinkhorn iterations to obtain , and define the loss:
Definition 7 (Sinkhorn Generative Loss).
(Genloss) where denotes the Hadamard (element-wise) product, and are the Sinkhorn scaling vectors after iterations.
Key Idea.
The Sinkhorn iterations are a sequence of differentiable operations (matrix–vector products, element-wise divisions). Therefore, is differentiable with respect to , and we can backpropagate through all iterations to update the generator via gradient descent. No adversarial discriminator is needed; the Sinkhorn loss is a direct, critic-free measure of distributional distance.
Algorithm 2 (Sinkhorn Generative Modelling).
Input: training data , prior , regularisation , Sinkhorn iterations , learning rate , epochs . Output: trained generator parameters .
Initialise randomly.
For : enumerate
Sample mini-batch from training data.
Sample and compute .
Compute cost matrix: .
Compute Gibbs kernel: .
Run Sinkhorn iterations (Algorithm Algorithm 1) to obtain .
Compute loss: .
Update: . enumerate
Remark 3 (Comparison with WGAN).
| WGAN | Sinkhorn | |
| Distance | (KR dual) | (primal) |
| Estimation | Critic network | Direct matrix computation |
| Training | Min-max game | Single minimisation |
| Gradient | Through critic | Through Sinkhorn iters |
| Scalability | Any batch size | per batch |
| Stability | Lipschitz enforcement | tuning |
Computational Aspects and Extensions
Log-Domain Sinkhorn
Remark 4 (Numerical Stability).
When is small, the Gibbs kernel entries can underflow to zero, causing division-by-zero in the Sinkhorn iterations. The log-domain formulation works entirely in space: (U) where prevents over/underflow by working in log space throughout. This is essential for small .
Mini-Batch Optimal Transport
In practice, the cost matrix is computed from mini-batches of size –. The mini-batch Sinkhorn loss approximates the population-level Sinkhorn divergence: where and . Using the debiased Sinkhorn divergence instead of the raw entropic cost is critical here, as it eliminates the bias that would otherwise accumulate across mini-batches.
Extensions
Remark 5 (Unbalanced Optimal Transport).
When the total masses of and differ (e.g., in point cloud registration or partial matching), the marginal constraints are relaxed using KL penalties: where control how strictly the marginals are enforced. The Sinkhorn-like iterations for unbalanced OT involve an additional softmax damping step.
Remark 6 (Connection to Schrödinger Bridges).
The entropy-regularised OT problem is equivalent to the Schrödinger bridge problem: find the most likely stochastic process connecting distribution at time to distribution at time , given a reference Brownian motion. The Sinkhorn iterations correspond to the iterative proportional fitting (IPF) algorithm for Schrödinger bridges. This connection has recently inspired diffusion Schrödinger bridges, linking optimal transport to score-based diffusion models.
| Method | Complexity | Regularised? | Differentiable? |
| Hungarian algorithm | No | No | |
| LP (simplex) | No | No | |
| Auction algorithm | No | No | |
| Sinkhorn | Yes () | Yes | |
| Log-domain Sinkhorn | Yes | Yes (stable) |
Historical Note.
The Sinkhorn algorithm predates its use in machine learning by decades. Richard Sinkhorn proved in 1964 that alternating row and column normalisation of a positive matrix converges to a doubly stochastic matrix. Cuturi [3] connected this to optimal transport in 2013, showing that the Sinkhorn iteration solves the entropy-regularised OT problem and scales to thousands of points. Genevay et al. [6] introduced the debiased Sinkhorn divergence and demonstrated its use as a loss function for generative models. Feydy et al. [7] showed that Sinkhorn divergences interpolate between OT distances and kernel MMD, unifying two major families of distributional distances.
Exercises
Exercise 1 (Transport Plan Constraints).
Let and on three points with cost matrix . Write down all constraints that must satisfy. How many free variables does have after the marginal constraints? Find the optimal transport plan by inspection or by solving the LP.
Exercise 2 (Compactness of the Coupling Polytope).
Exercise 3 (Entropy Limit Behaviour).
Show that as , the entropy-regularised optimal plan converges to the product coupling . Hint: the product coupling uniquely maximises over . What does converge to?
Exercise 4 (Sinkhorn Marginal Satisfaction).
Starting from and , show that after the first row update , the plan satisfies exactly. Does it satisfy ?
Exercise 5 (Birkhoff–von Neumann and OT).
A doubly stochastic matrix has all row and column sums equal to . The Birkhoff–von Neumann theorem states that the set of doubly stochastic matrices is the convex hull of permutation matrices. Show that when , the coupling polytope where is the Birkhoff polytope. What does the unregularised optimal plan correspond to in this case?
Exercise 6 (Backpropagation Through Sinkhorn).
In Sinkhorn generative modelling, the loss depends on through the cost matrix . Argue that each Sinkhorn iteration (element-wise division, matrix–vector product) is composed of differentiable operations, so can be computed by automatic differentiation through all iterations. What is the memory cost of storing all intermediate for backpropagation?
Exercise 7 (WGAN vs. Sinkhorn).
Compare WGAN and Sinkhorn-based generative models along these axes:
How does each estimate the Wasserstein distance?
Which requires adversarial training, and why?
What are the computational bottlenecks of each?
In what regime (small vs. large ) is each preferred?
Exercise 8 (Log-Domain Stability).
Exercise 9 (Sinkhorn Divergence Debiasing).
Compute for with cost and . Verify that , confirming the bias of the raw entropic cost. Compute the debiased Sinkhorn divergence and verify it equals zero.
Exercise 10 (Kantorovich Duality Verification).
For , (a single point), and with , , :
Solve the primal OT problem directly (there is only one feasible plan).
Find dual potentials satisfying complementary slackness and verify strong duality.
Exercise 11 (Convergence Rate and ).
Run the Sinkhorn algorithm for the example of Example Example 2 with . For each , record the number of iterations needed to achieve . Verify empirically that increases as . What happens to the optimal plan as ?
Exercise 12 (Sample Complexity).
The unregularised distance has sample complexity in dimension . Explain why this is prohibitively slow for images (). The Sinkhorn divergence has sample complexity , independent of . Explain intuitively why the entropic regularisation “smooths out” the curse of dimensionality. Hint: the Gibbs kernel acts like a soft nearest-neighbour kernel.
References
-
The Hungarian method for the assignment problem
BibTeX
@article{kuhn1955, author = {Kuhn, H. W.}, title = {The Hungarian method for the assignment problem}, journal = {Naval Research Logistics Quarterly}, volume = {2}, number = {1-2}, pages = {83-97}, doi = {https://doi.org/10.1002/nav.3800020109}, url = {https://onlinelibrary.wiley.com/doi/abs/10.1002/nav.3800020109}, eprint = {https://onlinelibrary.wiley.com/doi/pdf/10.1002/nav.3800020109}, abstract = {Abstract Assuming that numerical scores are available for the performance of each of n persons on each of n jobs, the “assignment problem” is the quest for an assignment of persons to jobs so that the sum of the n scores so obtained is as large as possible. It is shown that ideas latent in the work of two Hungarian mathematicians may be exploited to yield a new method of solving this problem.}, year = {1955} }Journal article
-
A tale of three eras: The discovery and rediscovery of the Hungarian Method
BibTeX
@article{KUHN2012641, title = {A tale of three eras: The discovery and rediscovery of the Hungarian Method}, journal = {European Journal of Operational Research}, volume = {219}, number = {3}, pages = {641-651}, year = {2012}, note = {Feature Clusters}, issn = {0377-2217}, doi = {https://doi.org/10.1016/j.ejor.2011.11.008}, url = {https://www.sciencedirect.com/science/article/pii/S0377221711009957}, author = {Harold W. Kuhn}, keywords = {Assignment, Combinatorial optimization, Graph theory, Linear programing, Hungarian Method} }Journal article
-
Sinkhorn Distances: Lightspeed Computation of Optimal Transport
BibTeX
@inproceedings{cuturi2013sinkhorn, title={Sinkhorn Distances: Lightspeed Computation of Optimal Transport}, author={Cuturi, Marco}, booktitle={Advances in Neural Information Processing Systems}, year={2013} }Conference paper
-
Linear Programming: Foundations and Extensions
BibTeX
@book{vanderbei1998, title={Linear Programming: Foundations and Extensions}, author={Vanderbei, Robert J.}, publisher={Kluwer Academic Publishers}, year={1998}, address={Boston, MA} }Book
-
Proximity Maps for Convex Sets
BibTeX
@article{Cheney1959ProximityMF, title={Proximity Maps for Convex Sets}, author={Cheney, Ward and Goldstein, Allen A.}, journal={Proceedings of the American Mathematical Society}, volume={10}, number={3}, pages={448--450}, year={1959}, publisher={American Mathematical Society} }Journal article
-
Learning Generative Models with Sinkhorn Divergences
BibTeX
@inproceedings{genevay2018learning, title={Learning Generative Models with Sinkhorn Divergences}, author={Genevay, Aude and Peyr{\'e}, Gabriel and Cuturi, Marco}, booktitle={Proceedings of the International Conference on Artificial Intelligence and Statistics (AISTATS)}, year={2018} }Conference paper
-
Interpolating between Optimal Transport and MMD using Sinkhorn Divergences
BibTeX
@inproceedings{feydy2019interpolating, title={Interpolating between Optimal Transport and {MMD} using Sinkhorn Divergences}, author={Feydy, Jean and S{\'e}journ{\'e}, Thibault and Vialard, Fran{\c{c}}ois-Xavier and Amari, Shun-ichi and Trouv{\'e}, Alain and Peyr{\'e}, Gabriel}, booktitle={Proceedings of the International Conference on Artificial Intelligence and Statistics (AISTATS)}, year={2019} }Conference paper
-
Sample Complexity of Sinkhorn Divergences
BibTeX
@inproceedings{genevay2019sample, title={Sample Complexity of {S}inkhorn Divergences}, author={Genevay, Aude and Chizat, L{\'e}na{\"i}c and Bach, Francis and Cuturi, Marco and Peyr{\'e}, Gabriel}, booktitle={Proceedings of the International Conference on Artificial Intelligence and Statistics (AISTATS)}, year={2019} }Conference paper