TL;DR
Optimal transport asks for the cheapest way to move one distribution of mass onto another, when every move has a cost. The answer is a plan: a record of how much mass leaves each place and arrives at each other place. The total cost of the best plan is the central object of the theory. When the cost is a power of distance (see Metric Space), that total gives the Wasserstein distance.
Where you'll see it: in comparing probability distributions, in training generative models such as GANs, in averaging several distributions into one, and in assigning jobs to workers at the lowest total cost.
Intuition
Earth from cuttings to embankments
In 1781 the French mathematician Gaspard Monge asked a practical question. A road builder must dig earth out of cuttings and pile it into embankments. Each cutting holds a fixed volume, each embankment needs a fixed volume, and moving earth costs its volume times the distance it travels. Which assignment of earth to places makes the total cost smallest?
Start with a tiny version. Two piles of 1 unit each sit at positions 0 and 10. Two holes, each needing 1 unit, sit at positions 1 and 11. Pairing the pile at 0 with the hole at 1, and the pile at 10 with the hole at 11, costs . The crossed pairing costs . The sensible pairing wins, and the cost measures how well a plan respects the geography.
Why allow splitting?
Monge's original problem requires every grain at a point to go to one destination . That is too strict. If one pile must feed two holes, no single destination works, because a pile cannot send each grain to two places. The fix, due to Leonid Kantorovich, is to let the plan split. Instead of saying where each grain goes, the plan says how much mass flows from each place to each other place. Those flows form a table, and finding the cheapest table is a linear problem, which we know how to solve.
flowchart LR A[Monge: a map T sends each point to one destination] --> B[Kantorovich: a plan splits mass between destinations] B --> C[Linear program, so solvable and convex] C --> D[Dual prices on sources and sinks] C --> E[Wasserstein distance when the cost is a power of distance]
The math
Setting
Let and be probability distributions on spaces and , which here represent the sources and the targets. Let be the cost of moving one unit of mass from to . Write for the set of couplings: joint distributions on whose first marginal is and whose second marginal is . This is the same notion as in the Wasserstein lesson, where the two distributions were called and .
Two formulations
Find a map that pushes forward to , written , meaning that the mass landing in any set equals , and that minimises
Find a coupling that minimises
Monge's version asks for a function, and Kantorovich's asks for a plan. Every map gives a plan, namely the coupling of with that puts all mass of at . So the Kantorovich value is never larger than the Monge value. The relaxation is strict in general: when is a single point and has two atoms, no map pushes onto , but a plan still exists.
The Kantorovich problem is linear in . The objective is linear, and the marginal constraints are linear equalities. For discrete distributions, with and (where is the distribution with all its mass at the point ), the problem becomes the linear program
with . Each is how much mass leaves source for target . Linear programs are convex, so a best plan can be found, and a dual problem can be written down as shown below.
Duality and prices
The dual of the Kantorovich problem is
Here and are functions on the sources and the targets, and the constraint is the one in the dual of a linear program (see Lagrangian Duality). The economic reading is clean. Think of as the price of a unit of supply at , and as the price of a unit of demand at . The constraint says no trader can buy at , ship to and sell there for more than the shipping cost. Under mild conditions the dual value equals the Kantorovich value, so the optimal plan and the optimal prices certify each other.
For the Wasserstein distance with , the dual reduces to the Kantorovich–Rubinstein form from the earlier lesson. Taking with turns the constraint into , which says is 1-Lipschitz (see Lipschitz Continuity): it never changes faster than the distance between the points.
The one-dimensional solution
On the real line with a cost of the form for a convex function (see Convex Function), the optimal plan is monotone: the lowest source goes to the lowest target, and so on. If has no atoms, the optimal map is
where is the cumulative distribution function of and is the inverse of the CDF of , its quantile function. This is the reason sorting solves one-dimensional transport: sorting is what the composition of the two CDFs does.
Quadratic cost and Brenier's theorem
With on and spread out (it has a density), the Monge problem has a unique solution. Yann Brenier proved in 1991 that this solution is the Gradient of a convex function: for some convex . So the best way to move one density onto another is to follow the slope of a convex landscape. This gives both a uniqueness result and a structural description of the optimal map.
Entropic regularisation
Exact transport becomes slow when there are many points. Marco Cuturi's 2013 idea was to add a small entropy penalty to the cost:
The added term is minus the Entropy of the plan, scaled by , so minimising it spreads the mass out. The penalised problem has a unique solution of the form , where . Sinkhorn's algorithm finds and by alternately rescaling: and then , where division is entrywise. Each step is one matrix-vector product, so the method is fast. As shrinks toward zero, the solution approaches the exact plan.
Worked examples
Let put all its mass, 1, at the point . Let put at and at . Use .
- Monge: a map must send the whole mass at to a single point . Then is a single point mass, which cannot equal , which has two atoms. No Monge map exists.
- Kantorovich: take the plan with and . Its first marginal is the point mass at , and its second marginal is . So is a valid coupling.
- Its cost is .
Interpretation: the plan splits the single pile between two holes, which Monge's map could not do. Since the plan is optimal here, the Kantorovich value is 1, and the Monge problem has no answer at all.
Let be uniform on , so each point has mass . Let be uniform on . Use .
- Sorted matching pairs , and . The squared costs are , and .
- Its total cost is .
- Check every pairing. Matching to the targets costs . Matching to costs . Matching to costs . Matching to costs . Matching to costs .
- The smallest sum over the six pairings is , the sorted one. So the optimal cost is .
Interpretation: with equal masses and a convex cost, the best plan is a one-to-one matching, and sorting finds it without checking every pairing. The check in step 3 confirms the claim on this small case.
Let and on the real line, with . Use .
- The CDF of turns each into a uniform number . The quantile function of turns into times the standard normal quantile at . Composing them gives .
- Check that pushes forward to . If , then , which is .
- The cost is .
- This agrees with the closed form from the Wasserstein lesson, .
Interpretation: the optimal way to widen a standard bell curve into one twice as wide is to stretch every point away from the centre by a factor of 2. The map is linear, as Brenier's theorem predicts for Gaussians.
Three workers A, B and C can each do one of three jobs, J1, J2 and J3. The hours each assignment takes are
Every worker takes one job and every job is taken, so the source and target masses are each on three points. Find the assignment with the fewest total hours.
- Enumerate the six one-to-one assignments and add the hours. Assigning A to J1, B to J2 and C to J3 gives .
- A to J1, B to J3 and C to J2 gives .
- A to J2, B to J1 and C to J3 gives .
- A to J2, B to J3 and C to J1 gives .
- A to J3, B to J1 and C to J2 gives .
- A to J3, B to J2 and C to J1 gives .
- The minimum is , with A on J2, B on J1 and C on J3. As an optimal transport plan with masses , this is on those three pairs, with cost hours per worker on average.
Interpretation: the plan is a permutation of the workers, so this assignment problem is optimal transport with equal masses. Real assignment problems have thousands of workers and jobs, which is why the exact linear program and the Sinkhorn approximation both matter in practice.
Tradeoffs and failure modes
| Situation | Problem | Better choice |
|---|---|---|
| Very many points | An exact linear program or assignment solver becomes slow | Entropic regularisation with Sinkhorn iterations, which trades a little accuracy for speed |
| You need a map, not a plan | A plan splits mass, so one source can feed many targets | Use Brenier's map for a quadratic cost on densities, or learn a map from samples |
| The cost is not a true distance | Results depend heavily on an arbitrary cost, and the Wasserstein guarantees do not apply | Pick the cost from the problem, and use only when is a power of a metric |
| High-dimensional continuous measures | No closed form, and sample estimates converge slowly and are biased | Project onto random directions and solve one-dimensional problems, the idea behind sliced transport |
| Unequal total masses | The standard formulation needs equal masses | Unbalanced transport, which lets mass be created or destroyed at a penalty |
Two cautions apply throughout. The answer depends on the cost , so a poor cost gives a precise but meaningless answer. And the regularised solution from Sinkhorn is biased: with a large the plan is too spread out, and with a small the iterations need more steps to converge.
History
Monge introduced the transport problem in 1781 in Mémoire sur la théorie des déblais et des remblais. For nearly two centuries it stayed a question about the geometry of earthworks. Leonid Kantorovich recast it as a linear problem in the early 1940s, which made it amenable to the methods that became linear programming. He shared the 1975 Nobel Memorial Prize in Economic Sciences with Tjalling Koopmans for work on the optimal allocation of resources. Yann Brenier's 1991 theorem gave the monotone gradient structure for quadratic costs. Cédric Villani's 2009 monograph Optimal Transport: Old and New made the theory central to analysis and geometry, and he received the Fields Medal in 2010, mainly for his work on Landau damping and the Boltzmann equation.
The applied turn came later. Rubner, Tomasi and Guibas used the earth mover's distance for comparing image colour histograms in the late 1990s. Marco Cuturi's 2013 entropic approach made the computations practical for large problems. Arjovsky, Chintala and Bottou used the Kantorovich–Rubinstein dual to train GANs in 2017. Since then optimal transport has spread into machine learning, statistics and economics, where it describes matching markets. It caught on because one object, the optimal plan, answers both "how far apart are these two distributions?" and "how do I move one into the other?".
Recap
Optimal transport asks how to move one distribution onto another at least total cost. Monge's version seeks a map, which can fail to exist. Kantorovich's version seeks a plan, a coupling of the two distributions, and it is a linear program, so it is convex and solvable. Its dual gives prices on sources and targets that certify the optimum. In one dimension the best plan is sorting, and for a quadratic cost on densities it is the gradient of a convex function. Adding an entropy penalty gives Sinkhorn's algorithm, which is fast enough for large problems. When the cost is a power of a metric, the optimal value is a Wasserstein distance. The theory feeds into generative models and into the study of the convex landscapes that optimal maps follow.
Check yourself
QuestionRecall: what is the difference between a Monge map and a Kantorovich plan?Show answer
A Monge map sends each source point to exactly one destination, so all the mass at a point goes to one place. A Kantorovich plan is a coupling that may split the mass at a point between several destinations. Every map gives a plan, so the Kantorovich value is at most the Monge value, and plans can exist when no map does.
QuestionComputation: let be uniform on and be uniform on . Use . Find the optimal cost.Show answer
Sorted matching pairs and , with squared costs and . The total is . The crossed pairing , costs . Since there are only two one-to-one matchings, the sorted one is optimal with cost 10.
QuestionWhy: why is the Kantorovich problem easier to solve than the Monge problem?Show answer
In the Kantorovich problem the objective is linear in the plan , and the marginal conditions are linear constraints. A linear problem over a convex set is convex, so local solutions are global ones and standard solvers apply. The Monge problem asks for a function satisfying a nonlinear constraint, , which can have no solution at all.
QuestionApplied: for a cost between a source and a target , suppose a dual pair assigns and . Is this pair feasible for the dual, and why does it matter?Show answer
It is not feasible. The dual constraint requires , but is larger than . In price terms, a trader could be paid to take a unit away from , ship it to for a cost of , and sell it there for . The net gain is , which is an arbitrage. A feasible dual pair cannot contain such an arbitrage, and only feasible pairs give a lower bound on the optimal cost.
Sources
- Wikipedia, "Optimal transport": https://en.wikipedia.org/wiki/Optimal_transport
- Cédric Villani, Optimal Transport: Old and New (Springer, 2009): https://doi.org/10.1007/978-3-540-71050-9
- Marco Cuturi, Sinkhorn Distances: Lightspeed Computation of Optimal Transport (2013): https://arxiv.org/abs/1306.0895