Machine Learning

Wasserstein Distance One Dimensional

Transport probability mass along a line and compare its minimum travel cost with the area between two CDFs.

By Riano · Published · Updated · Report a correction

Wasserstein Distance One Dimensional

The Wasserstein-1 distance (often called the earth mover's distance) computes the minimum cost required to transform one probability distribution into another. On a one-dimensional real line, this optimal transport has a closed-form solution: it equals the absolute area between the two cumulative distribution functions (CDFs).

In this module, two probability distributions P and Q are defined over fixed atoms at coordinates x = -1, 0, 2. We independently normalize two nonnegative integer weight vectors and compute the Wasserstein-1 distance for the coordinate cost |x - y|.

Worked Example: Exact Mass Transport

Let the atoms be x = -1, 0, 2. Suppose we define the unnormalized weights for P as Pw = (1, 1, 2) and for Q as Qw = (0, 3, 1).

First, we normalize them to sum to 1. Since both vectors sum to 4:

  1. P = (1/4, 1/4, 2/4)
  2. Q = (0, 3/4, 1/4)

Next, we compute their Cumulative Distribution Functions (CDFs):

Coordinate (x)-102
P(X ≤ x)1/42/44/4 = 1
Q(X ≤ x)03/44/4 = 1
Absolute Difference |P - Q|1/41/40

The Wasserstein-1 distance integrates the absolute difference between the CDFs over the real line. Since our distributions are discrete, the CDFs are step functions. The width of the step from -1 to 0 is 1, and from 0 to 2 is 2.

W1 = |FP(-1) - FQ(-1)| × 1 + |FP(0) - FQ(0)| × 2

W1 = (1/4) × 1 + (1/4) × 2 = 1/4 + 2/4 = 3/4

This is exactly the minimum cost of moving mass to match the distributions. We move 1/4 mass from x=-1 to x=0 (distance 1, cost 1/4), and we move 1/4 mass from x=2 to x=0 (distance 2, cost 2/4). The total transport cost is exactly 3/4.

Experimenting with Monotone Coupling

Open the Wasserstein Distance One Dimensional interactive module. You can independently adjust the integer weights for each distribution and see how the optimal monotone transport plan adapts.

  1. Set P weights to 1, 0, 0 (all mass at -1) and Q weights to 0, 0, 1 (all mass at 2). The CDF difference is 1 across the entire range from -1 to 2. The cost is exactly 3.
  2. Set P weights to 1, 0, 1 and Q weights to 0, 1, 0. The total distance is 3/2 (1.5). Watch the coupling arcs adjust to move mass efficiently.
  3. Try setting all weights to 0. The module correctly rejects any zero total weight rather than attempting to solve unbalanced optimal transport.

Limitations

For this one-dimensional coordinate cost, monotone quantile coupling attains the minimum and the Wasserstein-1 distance equals the absolute CDF-difference area. One-dimensional Wasserstein-2 also has a quantile formula, but not this same absolute-CDF-area identity. Finite transport problems in higher dimensions may require optimization; entropic Sinkhorn scaling solves a regularized problem. The minimum cost is well-defined even when other optimal couplings exist. This module distinguishes coordinate-sensitive cost from total variation on a fixed three-atom support.

References

The concepts demonstrated here rely on computational optimal transport theory.

  • Gabriel Peyré. Computational Optimal Transport. Course Notes (current Proposition 2.27 on page 5: quantile coupling and W1 integral of absolute CDF difference).

Experience it interactively

Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Wasserstein Distance One Dimensional module.

Try Wasserstein Distance One Dimensional on Riano →

More in Machine Learning