wasserstein_metric: wasserstein_metric

Description Usage Arguments Details Value References See Also Examples

View source: R/RcppExports.R

Description

The order p Wasserstein metric (or distance) is defined as the p-th root of the total cost of turning one pile of mass x into a new pile of mass y. The cost a single transport x_i into y_i is the p-th power of the euclidean distance between x_i and y_i.

Usage

1
wasserstein_metric(x, y, p = 1, wa_ = NULL, wb_ = NULL)

Arguments

x

NumericVector representing an empirical distribution under condition A

y

NumericVector representing an empirical distribution under condition B

p

order of the wasserstein distance

wa_

NumericVector representing the weights of datapoints (interpreted as clusters) in x

wb_

NumericVector representing the weights of datapoints (interpreted as clusters) in y

Details

The masses in x and y can also be represented as clusters P and Q with weights W_P and W_Q. The wasserstein distance then becomes the optimal flow F, which is the sum of all optimal flows f_{ij} from (p_i, w_{p,i}) to (q_i, w_{q,i}).

This implementation of the Wasserstein metric is a Rcpp reimplementation of the wasserstein1d function by Dominic Schuhmacher from the package transport.

Value

The wasserstein (transport) distance between x and y

References

Schefzik and Goncalves 2019

See Also

[squared_wass_approx()], [squared_wass_decomp()] for different approximations of the wasserstein distance

Examples

1
2
3
4
5
6
7
# input: one dimensional data in two conditions
x <- rnorm(100, 42, 2)
y <- c(rnorm(61, 20, 1), rnorm(41, 40, 2))
# output: The exact Wasserstein distance between the two input
# vectors. Reimplementation of the wasserstein1d function found in
# the packge transport.
d.wass <- wasserstein_metric(x,y,2)

waddR documentation built on Nov. 8, 2020, 8:32 p.m.