earthmover_dist: Earthmover distance (and general Wasserstein distance)

View source: R/evaluation.R

earthmover_distR Documentation

Earthmover distance (and general Wasserstein distance)

Description

i.e., wasserstein distance with L1 (p_param = 1); can also use other penalties > 1 (Not technically earthmover distance if using other p_param values)

Usage

earthmover_dist(batch1, batch2, whichdim = 1, numbins = 100, p_param = 1)

Arguments

batch1

matrix; subset of observations from an embedding correponding to some attribute (e.g., batch or phenotype)

batch2

matrix; subset of observations from an embedding correponding to some attribute (e.g., batch or phenotype)

whichdim

int; which dimension (i.e., column) from the embeddings is used. defaults on first

numbins

int; number of bins for the probability discretization (defaults to 100)

p_param

int; penalty parameter for general Wasserstein distance. Defaults to 1, which corresonds to earthmover.

Value

num; the distance

Examples

# To compare distributions of reduced dimension values to assess similarity, 
# e.g. as a metric for batch integration
embedding <- matrix(sample(x = seq(0,10,.1),1000, replace = TRUE),ncol = 5)
batch <- matrix(sample(c(1,2),200, replace = TRUE))
earthmover_dist(embedding[which(batch == 1),],embedding[which(batch == 2),]) 

laurenhsu1/corral documentation built on Feb. 19, 2023, 10:37 p.m.