wasserstein {transport} | R Documentation |
Compute the Wasserstein Distance Between Two Objects
Description
Given two objects a
and b
that specify measures in R^d
, compute the Wasserstein distance of
order p
between the objects.
Usage
wasserstein(a, b, p=1, tplan=NULL, costm=NULL, prob=TRUE, ...)
Arguments
a , b |
two objects that describe mass distributions in |
p |
the power |
tplan |
an optional transference plan in the format returned by the function |
costm |
the matrix of costs between the support points of the measures. Ignored unless |
prob |
logical. Should the objects |
... |
further parameters passed to |
Details
The Wasserstein distance of order p
is defined as the p
-th root of the total cost incurred when transporting measure a
to measure b
in an optimal way, where the cost of transporting a unit of mass from x
to y
is given as the p
-th
power \|x-y\|^p
of the Euclidean distance.
If tplan
is supplied by the user, no checks are performed whether it is optimal for the given problem. So this
function may be used to compare different (maybe suboptimal) transference plans with regard to their total costs.
For further details on the algorithms used, see help of transport
.
Value
A single number, the Wasserstein distance for the specified problem.
Author(s)
Dominic Schuhmacher dschuhm1@uni-goettingen.de
See Also
plot
, transport
, wasserstein1d
Examples
#
# example for class 'pgrid'
#
wasserstein(random32a,random32b,p=1)
res <- transport(random32a,random32b,p=2)
wasserstein(random32a,random32b,p=1,res)
# is larger than above:
# the optimal transport for p=2 is not optimal for p=1
#
# example for class 'pp'
#
set.seed(27)
x <- pp(matrix(runif(500),250,2))
y <- pp(matrix(runif(500),250,2))
wasserstein(x,y,p=1)
wasserstein(x,y,p=2)