wasserstein_metric {waddR} | R Documentation |
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.
wasserstein_metric(x, y, p = 1, wa_ = NULL, wb_ = NULL)
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 |
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.
The wasserstein (transport) distance between x and y
Schefzik and Goncalves 2019
[squared_wass_approx()], [squared_wass_decomp()] for different approximations of the wasserstein distance
# 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)