Skip to contents

On the real line the Kantorovich–Rubinstein dual of the \(p = 1\) transport problem, \(W_1(p, q) = \sup_{Lip(f) \le 1} (\int f dp - \int f dq)\), has the closed form \(W_1(p, q) = \int |F_p(x) - F_q(x)| dx\): the transport cost is the area between the two cumulative distribution functions. No linear programme is needed, which is why this function has no solver.

Usage

Wassdt(p, q, support = NULL)

Arguments

p, q

Numeric vectors: probability masses on support, or raw samples when support is NULL.

support

Numeric vector of common support points, strictly increasing and the same length as p and q, or NULL.

Value

Named list with distance, n_support, method.

Details

Two input conventions are accepted. With support given, p and q are probability masses on that common grid, both normalised to sum to one; the CDFs are then step functions constant between consecutive support points, so \(W_1 = \sum_i |P_i - Q_i| (s_{i+1} - s_i)\) with \(P\), \(Q\) the cumulative masses. With support omitted, p and q are raw samples and the empirical distributions are compared by the same closed form on the pooled order statistics.

Mirrors morie.fn.wassdt on the Python side.

References

Kantorovich L V & Rubinstein G S (1958). On a space of completely additive functions. Vestnik Leningrad. Univ. 13(7), 52–59. The one-dimensional closed form is Theorem 2.18 of Villani C (2009), Optimal Transport: Old and New, Springer.

Examples

Wassdt(c(0.2, 0.5, 0.3), c(0.4, 0.4, 0.2), support = c(0, 1, 2))$distance
#> [1] 0.3