MathLabs

Applied and computational mathematics

Optimal transport

Finding the cheapest way to reshape one distribution of mass into another — from moving piles of sand to comparing images, probability distributions, and populations of cells.

IntuitionMoving a pile of sand into a hole at the least possible cost

Imagine a big pile of sand of some shape, and a hole in the ground of the exact same total volume but a different shape. You want to move every grain of sand into the hole using as little total effort as possible, where moving one grain a distance dd costs dd units of work — grains that travel farther cost more to move. This is the optimal transport problem: given a source distribution of mass and a target distribution with the same total mass, find the cheapest way to rearrange one into the other.

It sounds like a purely physical puzzle about sand, but the same question — matching one distribution of stuff to another at the least cost — shows up whenever you compare two probability distributions, two images, two economic supply-and-demand profiles, or two shapes. Optimal transport measures exactly how different two distributions are, and tells you exactly how to morph one into the other.

Example: A minimal example: two piles, two holes

Suppose you have one unit of sand at position x=0x=0 and another unit at x=10x=10, and two unit-sized holes at y=1y=1 and y=9y=9. Moving a unit of sand a distance dd costs dd. There are only two ways to match piles to holes: send 0→10\to1 and 10→910\to9, or send 0→90\to9 and 10→110\to1. Which matching is cheaper, and what is the minimum total cost?

Solution

The direct (non-crossing) matching costs ∣0−1∣+∣10−9∣=1+1=2|0-1|+|10-9|=1+1=2. The crossing matching costs ∣0−9∣+∣10−1∣=9+9=18|0-9|+|10-1|=9+9=18. So the cheapest choice sends each pile to the nearer hole without the paths crossing, for a minimum total cost of 22. This is already a seed of a general fact used later: for cost ∣x−y∣|x-y| on the real line, an optimal transport plan is always order-preserving — it never routes two units of mass along crossing paths.

A bell-shaped standard normal density curve plotted over its domain with a shaded critical region, used here purely as an example of a smooth probability density that could serve as a source or target measure in an optimal transport problem.
This bell-shaped standard normal curve N(0,1)\mathcal N(0,1) is only a stand-in for "a typical smooth density" — it is not itself a transport plan. Imagine it as either the source or the target density in an optimal transport problem: the theory below finds the cheapest way to reshape a curve like this one into a different target density.

UndergraduateMonge's map and Kantorovich's relaxation

In 1781, the French mathematician and military engineer Gaspard Monge posed the problem precisely: given a source measure μ\mu on a space XX and a target measure ν\nu on a space YY with the same total mass, and a cost function c(x,y)c(x,y) giving the price of moving one unit of mass from xx to yy, find a map T:X→YT:X\to Y that **pushes μ\mu forward to ν\nu** — written T#μ=νT_{\#}\mu=\nu, meaning T#μ(A)=μ(T−1(A))T_{\#}\mu(A) = \mu(T^{-1}(A)) for every measurable set AA — while minimizing the total transport cost:

inf⁡T: T#μ=ν∫Xc(x,T(x)) dμ(x)\inf_{T:\ T_{\#}\mu = \nu} \int_X c(x, T(x))\, d\mu(x)

Monge's original formulation frequently has no solution at all. The starkest example: let μ=δ0\mu=\delta_0 be a single point mass at the origin, and let ν=12δ−1+12δ1\nu=\frac12\delta_{-1}+\frac12\delta_{1} split its mass between two points. Any map TT must send 00 to a single point T(0)T(0), so T#μT_{\#}\mu is again a point mass — it can never equal ν\nu, no matter how TT is chosen. Monge's problem is infeasible here even though a perfectly sensible way to move the mass obviously exists: split it, half going left and half going right. A deterministic map simply cannot split mass.

Definition: Transport plans and couplings

Given μ∈P(X)\mu\in\mathcal P(X) and ν∈P(Y)\nu\in\mathcal P(Y), a transport plan (or coupling) is a probability measure γ\gamma on X×YX\times Y whose two marginals recover μ\mu and ν\nu: Π(μ,ν)={γ∈P(X×Y):(πX)#γ=μ, (πY)#γ=ν}.\Pi(\mu,\nu) = \{\gamma \in \mathcal{P}(X\times Y) : (\pi_X)_{\#}\gamma = \mu,\ (\pi_Y)_{\#}\gamma = \nu\}. Interpret γ\gamma as "how much mass moves from near xx to near yy": a deterministic map TT corresponds to the special coupling γ=(id,T)#μ\gamma=(\mathrm{id},T)_{\#}\mu, but a general γ\gamma is also allowed to send a single point of mass to several destinations at once. The independent product μ⊗ν\mu\otimes\nu always lies in Π(μ,ν)\Pi(\mu,\nu), so — unlike the set of Monge maps — this set is never empty.

inf⁡γ∈Π(μ,ν)∫X×Yc(x,y) dγ(x,y)\inf_{\gamma \in \Pi(\mu,\nu)} \int_{X \times Y} c(x,y)\, d\gamma(x,y)

For probability measures μ\mu on XX, ν\nu on YY (Polish spaces) and a continuous, bounded-below cost cc, the Kantorovich problem is equal to a dual maximization over pairs of Kantorovich potentials φ:X→R\varphi:X\to\mathbb R, ψ:Y→R\psi:Y\to\mathbb R satisfying φ(x)+ψ(y)≤c(x,y)\varphi(x) + \psi(y) \le c(x,y) pointwise: min⁡γ∈Π(μ,ν)∫X×Yc dγ  =  sup⁡φ(x)+ψ(y)≤c(x,y)(∫Xφ dμ+∫Yψ dν),\min_{\gamma\in\Pi(\mu,\nu)}\int_{X\times Y} c\,d\gamma \;=\; \sup_{\varphi(x)+\psi(y)\le c(x,y)}\left(\int_X\varphi\,d\mu+\int_Y\psi\,d\nu\right), and both the minimum and the supremum are attained.

Why is it true?

Think of φ(x)\varphi(x) as a price charged for picking up mass at xx and ψ(y)\psi(y) as a price paid for dropping it off at yy, in a decentralized market of independent shippers. No shipper can profitably undercut the direct route: buying at φ(x)\varphi(x) and selling at ψ(y)\psi(y) can never beat physically moving the mass and paying c(x,y)c(x,y) — exactly the constraint φ(x)+ψ(y)≤c(x,y)\varphi(x)+\psi(y)\le c(x,y). In a market that clears optimally, equality φ(x)+ψ(y)=c(x,y)\varphi(x)+\psi(y)=c(x,y) holds exactly along the routes actually used by an optimal plan.

Proof

For finite discrete measures μ=∑ipiδxi\mu=\sum_i p_i\delta_{x_i}, ν=∑jqjδyj\nu=\sum_j q_j\delta_{y_j}, the Kantorovich problem is the finite linear program min⁡∑i,jcijγij\min \sum_{i,j} c_{ij}\gamma_{ij} subject to γij≥0\gamma_{ij}\ge0, ∑jγij=pi\sum_j\gamma_{ij}=p_i, ∑iγij=qj\sum_i\gamma_{ij}=q_j. Its LP dual is exactly max⁡∑ipiφi+∑jqjψj\max \sum_i p_i\varphi_i+\sum_j q_j\psi_j subject to φi+ψj≤cij\varphi_i+\psi_j\le c_{ij} for all i,ji,j — one dual variable per primal (marginal) constraint. The primal is feasible (the product coupling piqjp_iq_j always works) and bounded below by 00, and the feasible polytope {γij≥0}∩Π(μ,ν)\{\gamma_{ij}\ge0\}\cap\Pi(\mu,\nu) is compact, so strong linear-programming duality gives equality of the two optimal values, with both attained. This proves the theorem exactly in the discrete case; the general statement on Polish spaces follows from the same primal-dual pattern applied via Fenchel–Rockafellar duality to convex functionals on Cb(X×Y)C_b(X\times Y) (Kantorovich 1942; see Villani 2009, Theorem 5.10, for the full argument).

The proof above for finite measures is a direct application of linear-programming duality — exactly the primal-dual machinery from convex optimization: the transport plan γ\gamma is the primal variable, the potentials φ,ψ\varphi,\psi are the dual (Lagrange) variables attached to the marginal constraints, and strong duality holds because Π(μ,ν)\Pi(\mu,\nu) is compact and convex. This is the first of two genuine bridges from optimal transport to its neighboring fields: measure theory supplies the language (μ,ν,γ\mu,\nu,\gamma as measures, pushforwards, marginals), and convex duality supplies the proof technique.

AdvancedBrenier's theorem and the geometry of Wasserstein space

Let μ,ν\mu,\nu be probability measures on Rn\mathbb R^n with finite second moments, and suppose μ\mu is absolutely continuous with respect to Lebesgue measure. For the quadratic cost c(x,y)=∣x−y∣2c(x,y) = |x-y|^2 there exists a convex function φ:Rn→R\varphi:\mathbb R^n\to\mathbb R, unique up to an additive constant, such that T=∇φT = \nabla \varphi is well-defined μ\mu-almost everywhere, satisfies T#μ=νT_{\#}\mu=\nu, and is the (essentially) unique minimizer of both the Kantorovich problem and Monge's original problem.

Why is it true?

Any optimal plan for a strictly convex cost like ∣x−y∣2|x-y|^2 is supported on a **cc-cyclically monotone** set: no finite re-matching of pairs can lower the total cost. For the quadratic cost, cyclical monotonicity of a set of pairs (xi,yi)(x_i,y_i) turns out to be exactly the condition that some convex function φ\varphi has yiy_i in its subdifferential at xix_i for every ii — this is Rockafellar's theorem characterizing cyclically monotone sets as subdifferentials of convex functions. Since μ\mu is absolutely continuous, a convex function is differentiable μ\mu-almost everywhere (Alexandrov's theorem), turning the set-valued subdifferential into a genuine gradient map T=∇φT=\nabla\varphi.

Proof

(Sketch, following Brenier 1991.) Step 1: Kantorovich duality for c=∣x−y∣2c=|x-y|^2 lets one rewrite the optimal potentials via φ(x)=12∣x∣2−φ~(x)\varphi(x)=\tfrac12|x|^2-\tilde\varphi(x) so that φ\varphi is convex and its Legendre transform φ∗(y)=sup⁡x(x⋅y−φ(x))\varphi^*(y)=\sup_x(x\cdot y-\varphi(x)) plays the role of the second potential; the dual constraint becomes exactly y∈∂φ(x)y\in\partial\varphi(x) on the support of an optimal γ\gamma. Step 2: Rockafellar's theorem states that every cyclically monotone subset of Rn×Rn\mathbb R^n\times\mathbb R^n is contained in the graph of ∂φ\partial\varphi for some convex lower semicontinuous φ\varphi; the support of an optimal plan is cyclically monotone because γ\gamma minimizes ∫∣x−y∣2 dγ\int|x-y|^2\,d\gamma, so no finite re-matching among finitely many pairs on the support can strictly decrease ∑i∣xi−yi∣2\sum_i|x_i-y_i|^2. Step 3: because μ≪\mu\ll Lebesgue, φ\varphi is differentiable μ\mu-almost everywhere by Alexandrov's theorem, so γ\gamma is concentrated on the graph {(x,∇φ(x))}\{(x,\nabla\varphi(x))\}, i.e. γ=(id,∇φ)#μ\gamma=(\mathrm{id},\nabla\varphi)_{\#}\mu. This exhibits a deterministic optimal map T=∇φT=\nabla\varphi, so it also solves Monge's problem, and any other optimal map must agree with it μ\mu-almost everywhere by strict convexity of the cost.

Once the cost is fixed to ∣x−y∣2|x-y|^2, the minimal transport cost itself becomes a genuine distance between probability measures — the 2-Wasserstein distance W2W_2. The space P2(Rn)\mathcal P_2(\mathbb R^n) of probability measures with finite second moment, equipped with W2W_2, behaves remarkably like a genuine infinite-dimensional Riemannian manifold: Felix Otto's heuristic — now called Otto calculus — treats a tangent vector at μ\mu as a velocity field vv solving the continuity equation ∂tμ+∇ ⁣⋅(μv)=0\partial_t\mu+\nabla\!\cdot(\mu v)=0, with Riemannian metric ⟨v,w⟩μ=∫v⋅w dμ\langle v,w\rangle_\mu=\int v\cdot w\,d\mu. Geodesics in this formal Riemannian structure are exactly the constant-speed paths μt=((1−t) id+t T)#μ\mu_t=((1-t)\,\mathrm{id}+t\,T)_{\#}\mu built from the very Brenier map T=∇φT=\nabla\varphi above. This formal Riemannian structure on the space of measures is the second, genuine bridge — this time from optimal transport to Riemannian geometry.

W2(μ,ν)2=min⁡γ∈Π(μ,ν)∫∣x−y∣2 dγ(x,y)W_2(\mu,\nu)^2 = \min_{\gamma \in \Pi(\mu,\nu)} \int |x-y|^2\, d\gamma(x,y)

Example: Explicit optimal transport between two centered Gaussians

Let μ=N(0,1)\mu=\mathcal N(0,1) and ν=N(0,2.25)\nu=\mathcal N(0,2.25) be centered one-dimensional Gaussians with standard deviations σ1=1\sigma_1=1 and σ2=1.5\sigma_2=1.5. Use Brenier's theorem to write down the optimal transport map TT pushing μ\mu forward to ν\nu for the quadratic cost, and compute W2(μ,ν)W_2(\mu,\nu).

Solution

Both measures are centered, so the general 1D Gaussian optimal-transport map T(x)=m2+σ2σ1(x−m1)T(x) = m_2 + \frac{\sigma_2}{\sigma_1}(x - m_1) reduces to the pure scalar rescaling T(x)=σ2σ1x=1.5xT(x)=\frac{\sigma_2}{\sigma_1}x=1.5x. This is indeed the gradient of the convex quadratic φ(x)=0.75x2\varphi(x)=0.75x^2, since φ′(x)=1.5x=T(x)\varphi'(x)=1.5x=T(x), confirming Brenier's theorem. One can check directly that TT pushes μ\mu forward to ν\nu: if X∼N(0,1)X\sim\mathcal N(0,1) then 1.5X∼N(0,1.52)=N(0,2.25)=ν1.5X\sim\mathcal N(0,1.5^2)=\mathcal N(0,2.25)=\nu. The transport cost is ∫(T(x)−x)2 dμ(x)=∫(0.5x)2 dμ(x)=0.25⋅Var(X)=0.25\int(T(x)-x)^2\,d\mu(x)=\int(0.5x)^2\,d\mu(x)=0.25\cdot\mathrm{Var}(X)=0.25, so W2(μ,ν)=0.25=0.5=σ2−σ1W_2(\mu,\nu)=\sqrt{0.25}=0.5=\sigma_2-\sigma_1, matching the general Gaussian formula with equal means.

An interactive 2D linear-transformation grid showing the plane uniformly stretched by a factor of 1.5 along both the x and y axes (diagonal matrix with entries 1.5, 0, 0, 1.5), so a unit circle maps to a larger circle of radius 1.5 and a square grid maps to a uniformly larger square grid.
This widget natively draws a general 2D linear map (x,y)↦(ax+by,cx+dy)(x,y)\mapsto(ax+by,cx+dy). Here it is set to the purely diagonal, equal-scale case a=d=1.5a=d=1.5, b=c=0b=c=0, used as a visual analogy (applying the same scalar factor to both axes) for the explicit 1D Brenier map T(x)=1.5xT(x)=1.5x from the worked example above: by Brenier's theorem, moving the centered Gaussian N(0,1)\mathcal N(0,1) to the wider centered Gaussian N(0,2.25)\mathcal N(0,2.25) is achieved, for the quadratic cost, by the pure scalar dilation T(x)=1.5xT(x)=1.5x — the gradient of the convex function φ(x)=0.75x2\varphi(x)=0.75x^2. Try setting a≠da\ne d or b,c≠0b,c\ne0 to see maps that are no longer valid transport maps between isotropic Gaussians.

ResearchDisplacement convexity, curvature, and transport at scale

A geodesic μt\mu_t in the Wasserstein space (P2(Rn),W2)(\mathcal P_2(\mathbb R^n),W_2) is called a displacement interpolation; a functional FF on measures (such as the entropy ∫ρlog⁡ρ\int\rho\log\rho for μ=ρ dx\mu=\rho\,dx) is displacement convex if t↦F(μt)t\mapsto F(\mu_t) is convex along every such geodesic. Around 2006–2009, John Lott and Cédric Villani, and independently Karl-Theodor Sturm, used the displacement convexity of entropy along W2W_2-geodesics to define a synthetic (curvature-dimension) lower bound on Ricci curvature — the CD(K,N)\mathrm{CD}(K,N) condition — for completely general metric-measure spaces, with no smooth manifold structure required. Remarkably, these curvature-dimension bounds are stable under Gromov–Hausdorff limits, letting geometers make sense of "curved" spaces that arise as limits of Riemannian manifolds, or spaces (graphs, fractals, singular spaces) that were never smooth to begin with.

A very different, thoroughly contemporary application: in 2017 Martin Arjovsky, Soumith Chintala, and Léon Bottou proposed the Wasserstein GAN, replacing the Jensen–Shannon divergence used to train classical generative adversarial networks with the (dual, Kantorovich–Rubinstein form of the) Wasserstein-1 distance between the real and generated data distributions. Because W1W_1 stays well-behaved and gives useful gradients even when two distributions have disjoint support — unlike the Jensen–Shannon divergence, which saturates — WGAN training is markedly more stable and far less prone to mode collapse, and the technique remains a standard building block of modern generative modeling.

Why does Monge's original formulation of optimal transport sometimes have no solution at all, while Kantorovich's relaxation always has a minimizer (under mild conditions)?

By Brenier's theorem, for the quadratic cost c(x,y)=∣x−y∣2c(x,y)=|x-y|^2 and an absolutely continuous source measure μ\mu on Rn\mathbb R^n, what form does the optimal transport map TT take (almost everywhere)?

In the Kantorovich duality theorem, what constraint links the two Kantorovich potentials φ\varphi and ψ\psi in the dual problem?

Why did Cuturi's 2013 entropic regularization (leading to the Sinkhorn algorithm) transform computational optimal transport in machine learning?

References

  1. Cédric Villani (2009). Optimal Transport: Old and New
  2. Marco Cuturi (2013). Sinkhorn Distances: Lightspeed Computation of Optimal Transport · arXiv:1306.0895
  3. Yann Brenier (1991). Polar Factorization and Monotone Rearrangement of Vector-Valued Functions · DOI:10.1002/cpa.3160440402
  4. John Lott, Cédric Villani (2009). Ricci Curvature for Metric-Measure Spaces via Optimal Transport