Learn R Programming

WpProj (version 0.2.1)

wasserstein: Calculate Wasserstein distances

Description

[Experimental] This function will calculate exact or approximate Wasserstein distances between two groups of observations. Please note that this function will likely be deprecated in favor of using the native function from the approxOT package.

Usage

wasserstein(
  X,
  Y,
  p = 2,
  ground_p = 2,
  observation.orientation = c("rowwise", "colwise"),
  method = c("exact", "sinkhorn", "greenkhorn", "hilbert", "rank",
    "univariate.approximation", "univariate.approximation.pwr", "univariate"),
  ...
)

Value

A numeric value

Arguments

X

Matrix for first group

Y

Matrix for second group

p

Power of the Wasserstein distance

ground_p

Power of the distance metric. Usually same as p

observation.orientation

Are observations unique by rows or columns? One of "colwise" or "rowwise"

method

One of the outputs of transport_options()

...

additional options for sinkhorn based methods. epsilon and niter determining the hyperparameters for the negative entropy penalty

Examples

Run this code
if(rlang::is_installed("stats")) {
n <- 128
p <- 10
x <- matrix( stats::rnorm( p * n ), nrow = n, ncol = p )
y <- matrix( stats::rnorm( p * n ), nrow = n, ncol = p )

dist <- wasserstein(x,y, p = 2, ground_p = 1, observation.orientation = "rowwise",
            method = "hilbert") #fast
print(dist)
}

Run the code above in your browser using DataLab