wasserstein1d {transport} | R Documentation |
Compute the Wasserstein Distance Between Two Univariate Samples
Description
Given two vectors a
and b
, compute the Wasserstein distance of
order p
between their empirical distributions.
Usage
wasserstein1d(a, b, p = 1, wa = NULL, wb = NULL)
Arguments
a , b |
two vectors. |
p |
a positive number. The order of the Wasserstein distance. |
wa , wb |
optional vectors of non-negative weights for |
Details
The Wasserstein distance of order p
is defined as the p
-th root of the total cost incurred when transporting a pile of mass into another pile of mass in an optimal way, where the cost of transporting a unit of mass from to
is given as the
p
-th power of the Euclidean distance.
In the present function the vector a
represents the locations on the real line of deposits of mass
and the vector
b
the locations of deposits of mass
. If the user specifies weights
wa
and wb
, these default masses are replaced by wa/sum(wa)
and wb/sum(wb)
, respectively.
In terms of the empirical distribution function of locations
with normalized weights
, and the corresponding function
for
b
, the Wasserstein distance in 1-d is given as
where and
are generalized inverses. If
, we also have
Value
A single number, the Wasserstein distance for the specified data.
Author(s)
Dominic Schuhmacher dschuhm1@uni-goettingen.de
See Also
Examples
x <- rnorm(200)
y <- rnorm(150,2)
wasserstein1d(x,y)