AI Glossary / Mathematics and optimization / Intermediate

Earth mover's distance

Definition

Earth mover's distance, or EMD, measures how much work is needed to transform one distribution of mass into another when moving mass has a specified cost. For probability distributions with equal total mass and cost proportional to distance, it is commonly identified with the Wasserstein-1 distance. Smaller values indicate that less movement is needed under the chosen geometry.

What it means

The locations of the mass matter as well as the amounts. Two histograms may disagree in exactly the same number of bins, yet one disagreement may involve a small shift and the other a large shift. EMD recognizes that distinction through a ground distance between locations. In an application, locations might represent waiting times, colors or feature vectors. The result therefore depends on what distance means in that representation. It is not a universal similarity score independent of units or feature design.

How it works

For discrete probability distributions, assign nonnegative transport amounts from each source location to each target location. Each source must send its available probability mass, and each target must receive its required mass. Minimize the sum of transported mass multiplied by ground distance across all source - target pairs. This is an optimal transport problem. On the real line with absolute distance, Wasserstein-1 also equals the area between the two cumulative distribution functions. The name EMD is additionally used for normalized partial-transport formulations with unequal total weights, so check the precise definition before comparing reported values.

Three practical examples

  • A service-monitoring team can compare two waiting-time distributions and express their displacement in units of time.
  • An image-retrieval experiment can compare color distributions using a declared distance between colors rather than treating all different bins as equally unrelated.
  • A model-evaluation study can examine changes in a one-dimensional feature distribution, alongside sample-size uncertainty and other checks for data drift.

Think of it this way

Think of redistributing piles of soil to fill a prescribed arrangement of holes. Moving twice as much soil the same distance doubles the work; moving it twice as far also doubles the work in this simple cost model. The analogy explains the name, but the mass is usually probability, not physical material. It also leaves out alternative cost functions, partial matching and constraints that may appear in a particular implementation.

Worked example

Let distribution P place probability 0.5 at location 0 and 0.5 at location 4. Let Q place probability 0.5 at location 1 and 0.5 at location 3. Use absolute distance along the number line. Move the mass at 0 to 1 and the mass at 4 to 3. The cost is 0.5 × 1 + 0.5 × 1 = 1. To verify optimality, compare cumulative distributions: their absolute difference is 0.5 on [0, 1), zero on [1, 3), and 0.5 on [3, 4). The total area is 0.5 × 1 + 0.5 × 1 = 1. Both distributions have mean 2, so equal means do not imply zero EMD. Now let R concentrate all its probability at 2. Transporting P to R costs 0.5 × 2 + 0.5 × 2 = 2. In these examples, all probability mass must be accounted for. If locations represent minutes, the distances are 1 minute and 2 minutes; converting the locations to seconds multiplies both results by 60. These are exact calculations for the stated discrete distributions, not estimates of an unknown population difference.

Illustrative case study

In a fictional study, Birch Support compares response times before and after a scheduling change. Analysts compute an empirical Wasserstein-1 distance, inspect the underlying distributions and report it in minutes. They also keep the number of requests and the observation periods visible. A nonzero distance prompts investigation, but they do not attribute it to the scheduling change without further evidence. The case illustrates descriptive monitoring, not a causal experiment or a claim of improved service.

Common misconceptions and mistakes

EMD is not simply the difference between means, as the worked example shows. It is also not generally the sum of absolute differences between matching histogram-bin heights. Normalizing counts into probabilities removes information about total volume: two periods with very different request counts may then have identical distributions. A small distance on one feature does not establish that two datasets are interchangeable. Finally, partial matching with unequal mass can lose metric properties that hold for equal-mass distributions under a metric ground distance.

Business use

Define the representation, units, ground distance and mass-normalization rule before calculating EMD. Decide whether the question concerns distribution shape, total volume or both. Preserve bin locations when using histograms, and check whether coarse binning hides meaningful shifts. For empirical data, examine how the result varies with sampling and with the observation window. In several dimensions, feature scaling determines movement cost and can dominate the comparison. Report whether the algorithm computes the specified transport problem exactly or uses an approximation or regularized alternative.

People also ask

Is earth mover's distance always Wasserstein-1?

They coincide in the common equal-probability-mass formulation with distance cost, but EMD naming also covers other transport conventions.

Can distributions have different numbers of sample points?

Yes. Probability mass can be split among target locations; one-to-one matching is not required.

Does zero EMD mean two files are identical?

No. It means the represented distributions agree under the applicable metric conditions; record order and omitted features may still differ.

Check your understanding

P and Q in the worked example both have mean 2. Must their earth mover's distance be zero?

Answer: No. Their mass occupies different locations, and the minimum transport cost is 1 under absolute distance.

Related terms

  • Optimal transport
  • Probability distribution
  • Cumulative distribution function
  • Histogram
  • Wasserstein distance
  • distribution shift

Learn next

draw the two cumulative distribution functions and shade the areas that contribute to distance 1. Then compare two datasets with identical normalized histograms but different total counts. Explain why distribution distance and volume change answer different questions.

  • Cumulative distribution

More in Mathematics and optimization

  • Absolute error loss - Absolute error loss measures a numerical prediction's error as the absolute difference between its predicted and reference values: L(y,y-hat)=|y-y-hat|.
  • Active-set method - An active-set method is an optimization approach that works with a changing subset of constraints believed to be tight at the solution.
  • Adjoint state method - The adjoint state method computes how a chosen objective changes when the parameters of a mathematical model change.
  • Σ-algebra
  • Algebraic connectivity - Algebraic connectivity is the second-smallest eigenvalue of a graph's Laplacian matrix.
  • Algorithm IMED - Algorithm IMED, short for Indexed Minimum Empirical Divergence, is a method for choosing actions in a stochastic multi-armed bandit problem.

Sources

Sources: SciPy, wasserstein_distance documentation, https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.wasserstein_distance.html ; Rubner, Tomasi and Guibas, The Earth Mover's Distance as a Metric for Image Retrieval, https://ai.stanford.edu/~rubner/papers/rubnerIjcv00.pdf ; Google, Machine Learning Glossary, https://developers.google.com/machine-learning/glossary#earth-movers-distance . The three distributions, calculations and fictional monitoring case are original.

Previous: Early stopping Next: Echo State Network

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer