Read the equation
For probability distributions on a line, Wasserstein-1 distance is the integral of the absolute difference of their cumulative distributions. The function normalizes its input masses, computes cumulative sums, and returns their mean absolute difference. This corresponds to a particular equal-grid scaling; physical support coordinates or grid spacing are not supplied.
Terms & definitions
| Term | Meaning in this source |
|---|---|
| P | First distribution |
| Q | Second distribution |
| F_P | First cumulative distribution |
| F_Q | Second cumulative distribution |
How it works
Read the definition from its right-hand expression to the quantity on the left. Its surrounding source records the intended input, state, or parameter context. Where the source leaves an operation unspecified, this page preserves that gap.
Assumptions & limits
Nonnegative mass and nonzero totals are needed for valid input distributions.
Original context
Read the surrounding source passage
}
// ═══════════════════════════════════════════════════════════════════════════════
// OPTIMAL TRANSPORT EQUATIONS
// ═══════════════════════════════════════════════════════════════════════════════
// Wasserstein1D computes 1D Wasserstein-1 distance
// W_1(P,Q) = ∫|F_P(x) - F_Q(x)|dx
func Wasserstein1D(p, q []float64) float64 {
if len(p) != len(q) {
return math.Inf(1)
}
n := len(p)
// Compute CDFs
cdfP := make([]float64, n)
cdfQ := make([]float64, n)Exact original notation
W_1(P,Q) = ∫|F_P(x) - F_Q(x)|dx