ArticleslgStudy

mathematics

Earth mover's distance

Earth mover's distance is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Earth mover's distance rather than just read about it. In short: In computer science, the earth mover's distance (EMD) is a measure of dissimilarity between two frequency distributions, densities, or measures, over a metric space D. Informally, if the distributions are interpreted as two different ways of piling up earth (dirt) over D, the EMD captures the minimum cost of building the smaller pile using dirt taken from the larger, where cost is defined as the amount of dirt moved…

Key takeaways

  • Earth mover's distance belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Earth mover's distance to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Earth mover's distance from memory before moving on to harder problems.

Reference excerpt

In computer science, the earth mover's distance (EMD) is a measure of dissimilarity between two frequency distributions, densities, or measures, over a metric space D. Informally, if the distributions are interpreted as two different ways of piling up earth (dirt) over D, the EMD captures the minimum cost of building the smaller pile using dirt taken from the larger, where cost is defined as the amount of dirt moved multiplied by the distance over which it is moved. Over probability distributions, the earth mover's distance is also known as the Wasserstein metric W1, Kantorovich–Rubinstein metric, or Mallows's distance. It is the solution of the optimal transport problem, which in turn is also known as the Monge-Kantorovich problem, or sometimes the Hitchcock–Koopmans transportation problem; when the measures are uniform over a set of discrete elements, the same optimization problem is known as minimum weight bipartite matching.

Formal definitions The EMD between probability distributions P and Q can be defined as an infimum over joint probabilities:

EMD(P,Q)=infγ∈Π(P,Q)𝔼(x,y)∼γ[d(x,y)] where Π(P,Q) is the set of all joint distributions whose marginals are P and Q. By Kantorovich-Rubinstein duality, this can also be expressed as:

EMD(P,Q)=sup‖f‖L≤1𝔼x∼P[f(x)]−𝔼y∼Q[f(y)] where the supremum is taken over all 1-Lipschitz continuous functions, i.e. ‖∇f(x)‖≤1∀x.

EMD between signatures In some applications, it is convenient to represent a distribution P as a signature, or a collection of clusters, where the i-th cluster represents a feature of mass wi centered at pi. In this formulation, consider signatures P={(p1,wp1),(p2,wp2),...,(pm,wpm)} and Q={(q1,wq1),(q2,wq2),...,(qn,wqn)}. Let D=[di,j] be the ground distance between clusters pi and qj. Then the EMD between P and Q is given by the optimal flow F=[fi,j], with fi,j the flow between pi and qj, that minimizes the overall cost.

minF∑i=1m∑j=1nfi,jdi,j subject to the constraints:

fi,j≥0,1≤i≤m,1≤j≤n ∑j=1nfi,j≤wpi,1≤i≤m ∑i=1mfi,j≤wqj,1≤j≤n ∑i=1m∑j=1nfi,j=min⁡{ ∑i=1mwpi,∑j=1nwqj } The optimal flow F is found by solving this linear optimization problem. The earth mover's distance is defined as the work normalized by the total flow:

EMD(P,Q)=∑i=1m∑j=1nfi,jdi,j∑i=1m∑j=1nfi,j

Variants and extensions

Unequal probability mass Some applications may require the comparison of distributions with different total masses. One approach is to allow for partial matching, where dirt from the more massive distribution is rearranged to make the less massive, and any leftover "dirt" is discarded at no cost. Formally, let wP be the total weight of P, and wQ be the total weight of Q. We have:

EMD(P,Q)=1min⁡(wP,wQ)infγ∈Π≥(P,Q)∫d(x,y)dγ(x,y) where Π≥(P,Q) is the set of all measures whose projections are ≥P and ≥Q. Note that this generalization of EMD is not a true distance between distributions, as it does not satisfy the triangle inequality. An alternative approach is to allow for mass to be created or destroyed, on a global or local level, as an alternative to transportation, but with a cost penalty. In that case one must specify a real parameter α, the ratio between the cost of creating or destroying one unit of "dirt", and the cost of transporting it by a unit distance. This is equivalent to minimizing the sum of the earth moving cost plus α times the L1 distance between the rearranged pile and the second distribution. The resulting measure EMD^α is a true distance function.

More than two distributions The EMD can be extended naturally to the case where more than two distributions are compared. In this case, the "distance" between the many distributions is defined as the optimal value of a linear program. This generalized EMD may be computed exactly using a greedy algorithm, and the resulting functional has been shown to be Minkowski additive and convex monotone.

Computing the EMD The EMD can be computed by solving an instance of transportation problem, using any algorithm for minimum-cost flow problem, e.g. the network simplex algorithm. The Hungarian algorithm can be used to get the solution if the domain D is the set {0, 1}. If the domain is integral, it can be translated for the same algorithm by representing integral bins as multiple binary bins. As a special case, if D is a one-dimensional array of "bins" of length n, the EMD can be efficiently computed by scanning the array and keeping track of how much dirt needs to be transported between consecutive bins. Here the bins are zero-indexed:

EMD0=0EMDi+1=Pi+EMDi−QiTotal Distance=∑i=0n|EMDi|

EMD-based similarity analysis EMD-based similarity analysis (EMDSA) is an important and effective tool in many multimedia information retrieval and pattern recognition applications. However, the computational cost of EMD is super-cubic to the number of the "bins" given an arbitrary "D". Efficient and scalable EMD computation techniques for large scale data have been investigated using MapReduce, as well as bulk synchronous parallel and resilient distributed dataset.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Earth mover's distance

Start with the simplest possible case. Write down what Earth mover's distance claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Earth mover's distance before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Earth mover's distance ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Earth mover's distance

In research
Earth mover's distance appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Earth mover's distance in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Earth mover's distance is common in secondary-school and first-year university syllabi. It links to neighbouring topics Statistical distance, so understanding it makes those chapters shorter.
In everyday life
Look for Earth mover's distance outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Earth mover's distance” →

How to study Earth mover's distance in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Earth mover's distance means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Earth mover's distance out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Earth mover's distance in simple terms?

In computer science, the earth mover's distance (EMD) is a measure of dissimilarity between two frequency distributions, densities, or measures, over a metric space D. Informally, if the distributions are interpreted as two different ways of piling up earth (dirt) over D, the EMD captures the minim…

Why does Earth mover's distance matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Earth mover's distance?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Earth mover's distance.

Tags

  • Statistical distance

Keep exploring