Description Usage Arguments Details Value References See Also Examples
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.
1 | 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
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.