Optimal transport

On this page 7

Optimal transport is the mathematical problem of finding the least costly way to move mass from one probability distribution to another, given a cost for moving one unit of mass between any two points. In optimization for artificial intelligence, it supplies both a well-posed linear program and a family of geometry-aware distances between distributions, the best known being the Wasserstein distance.

The problem dates back to Gaspard Monge in 1781 and was given its modern relaxed form by Leonid Kantorovich in the 1940s. Today it underpins generative model training, domain adaptation, single-cell biology, color transfer and the comparison of point clouds, largely because entropic regularization made it fast enough for large datasets.

How the optimal transport problem is formulated

Optimal transport takes a source distribution and a target distribution of equal total mass, plus a cost function c(x, y) that prices moving a unit from point x to point y. The goal is a plan that carries all mass from the source to the target at minimum total cost.

In the Monge formulation, every source point is sent to exactly one target point through a transport map. This is intuitive but may have no solution, for example when a single point mass must be split between two destinations. The Kantorovich relaxation instead searches over transport plans, joint distributions whose marginals equal the source and target, which allows mass to be split and guarantees that a solution exists under mild conditions.

For discrete distributions with n and m support points, the Kantorovich problem is a linear program with an n by m plan matrix, nonnegativity constraints and row and column sum constraints. Its Lagrangian dual introduces two potential functions, and strong duality links the optimal cost to the best pair of potentials.

The following table contrasts the two classical formulations.

AspectMonge formulationKantorovich formulation
Decision variableDeterministic transport mapJoint transport plan
Mass splittingNot allowedAllowed
Existence of a solutionNot guaranteedGuaranteed for lower semicontinuous costs
Problem classNonconvex in generalLinear program, hence convex
RelationSpecial case of the relaxationRecovers a map under Brenier conditions
Monge and Kantorovich formulations compared

Wasserstein distances and their properties

When the cost is a power p of a ground distance, the p-th root of the optimal cost defines the p-Wasserstein distance, a true metric on probability distributions. The case p equal to 1 is also called the earth mover’s distance, and p equal to 2 has a rich geometry linked to fluid dynamics through the Benamou-Brenier formula.

Unlike the Kullback-Leibler divergence, a Wasserstein distance stays finite and informative for distributions with disjoint supports. Two narrow peaks one unit apart have a distance of one, not infinity, which gives useful gradients when a model distribution does not yet overlap the data. This property motivated the Wasserstein generative adversarial network.

MeasureHandles disjoint supportsUses ground geometryTypical cost
Wasserstein distanceYesYesHigh without regularization
Sinkhorn divergenceYesYesModerate, GPU friendly
Sliced WassersteinYesPartly, through projectionsLow
Kullback-Leibler divergenceNoNoLow
Maximum mean discrepancyYesThrough the kernelLow to moderate
Optimal transport distances and divergences compared with alternatives

Algorithms for solving optimal transport

Exact discrete optimal transport can be solved with network simplex or interior-point methods, but the cost grows roughly as the cube of the number of points, which becomes impractical beyond a few thousand samples. Practical AI systems therefore rely on approximations.

Entropic regularization adds a penalty proportional to the negative entropy of the plan. The resulting problem is strictly convex and is solved by the Sinkhorn algorithm, which alternately rescales rows and columns of a kernel matrix. Each iteration costs only matrix-vector products, runs well on GPUs and is differentiable, so the transport cost can serve as a training loss.

SolverBest suited forMain trade-off
Network simplexExact plans up to a few thousand pointsCubic scaling, not differentiable
Sinkhorn iterationsLarge batches and differentiable lossesBlurred plan; small epsilon is unstable
Log-domain SinkhornSmall regularization valuesSlower but numerically stable
Sliced projectionsVery large point cloudsApproximates the true distance
Neural transport mapsContinuous maps and generalizationNonconvex training, no exactness guarantee
Solver choices for optimal transport

The regularization strength epsilon is the decisive setting. Large values give fast convergence and smooth plans; very small values approach the exact solution but require more iterations and log-domain computation to avoid numerical underflow.

Applications of optimal transport in AI

  • Generative modeling: Wasserstein losses and flow matching with optimal transport couplings produce straighter, easier-to-learn generation paths.
  • Domain adaptation: transport plans align feature distributions of a labeled source domain and an unlabeled target domain.
  • Single-cell biology: trajectory methods match cell populations measured at different time points.
  • Computer vision and graphics: color transfer, shape interpolation and point cloud comparison.
  • Fairness and evaluation: distances between prediction distributions of different groups or between generated and real samples.

Limitations and common pitfalls

Optimal transport suffers from a curse of dimensionality in sample complexity: the empirical Wasserstein distance converges to the true value slowly as dimension grows, so estimates from small samples in high dimensions are biased. Entropic versions and the debiased Sinkhorn divergence reduce this problem but do not remove it.

Results also depend heavily on the choice of ground cost. A squared Euclidean cost on raw pixels rarely reflects semantic similarity, so many systems compute transport in a learned feature space. Practitioners should also check that distributions are normalized to equal mass or switch to unbalanced optimal transport when they are not.

The simple explanation

Imagine several piles of sand and several holes of the same total size. You want to fill every hole with sand. Moving sand far costs more effort than moving it a short way.

Optimal transport finds the cheapest plan for moving all the sand. The total effort of that plan also tells you how different two distributions are. Piles that sit right next to their holes need little effort. Piles far away need much more. AI systems use this effort score to compare data, images and predictions in a way that respects distance.

How it is used in practice

A medical imaging team trains a tumor classifier on scans from one hospital and wants to use it at a second hospital whose scanners produce different contrast and noise patterns. Accuracy drops from 91 percent to 78 percent on the new site. The team extracts features from 5,000 labeled source scans and 5,000 unlabeled target scans and computes an entropic optimal transport plan between the two feature sets.

Using the plan, each source feature is moved toward its matched target region, and the classifier is retrained on the transported features. Sinkhorn iterations on a single GPU finish in under a minute per epoch. After adaptation, accuracy on held-out labeled target scans reaches about 87 percent, recovering most of the lost performance without labeling any new images at the second hospital.