riem.wasserstein {Riemann}R Documentation

Wasserstein Distance between Empirical Measures

Description

Given two empirical measures μ,ν\mu, \nu consisting of MM and NN observations, pp-Wasserstein distance for p1p\geq 1 between two empirical measures is defined as

Wp(μ,ν)=(infγΓ(μ,ν)M×Md(x,y)pdγ(x,y))1/p\mathcal{W}_p (\mu, \nu) = \left( \inf_{\gamma \in \Gamma(\mu, \nu)} \int_{\mathcal{M}\times \mathcal{M}} d(x,y)^p d \gamma(x,y) \right)^{1/p}

where Γ(μ,ν)\Gamma(\mu, \nu) denotes the collection of all measures/couplings on M×M\mathcal{M}\times \mathcal{M} whose marginals are μ\mu and ν\nu on the first and second factors, respectively.

Usage

riem.wasserstein(
  riemobj1,
  riemobj2,
  p = 2,
  geometry = c("intrinsic", "extrinsic"),
  ...
)

Arguments

riemobj1

a S3 "riemdata" class for MM manifold-valued data, which are atoms of μ\mu.

riemobj2

a S3 "riemdata" class for NN manifold-valued data, which are atoms of ν\nu.

p

an exponent for Wasserstein distance Wp\mathcal{W}_p (default: 2).

geometry

(case-insensitive) name of geometry; either geodesic ("intrinsic") or embedded ("extrinsic") geometry.

...

extra parameters including

weight1

a length-MM weight vector for μ\mu; if NULL (default), uniform weight is set.

weight2

a length-NN weight vector for ν\nu; if NULL (default), uniform weight is set.

Value

a named list containing

distance

Wp\mathcal{W_p} distance between two empirical measures.

plan

an (M×N)(M\times N) matrix whose rowSums and columnSums are weight1 and weight2 respectively.

Examples

#-------------------------------------------------------------------
#          Example on Sphere : a dataset with two types
#
# class 1 : 20 perturbed data points near (1,0,0) on S^2 in R^3
# class 2 : 30 perturbed data points near (0,1,0) on S^2 in R^3
#-------------------------------------------------------------------
## GENERATE DATA
mydata1 = list()
mydata2 = list()
for (i in 1:20){
  tgt = c(1, stats::rnorm(2, sd=0.1))
  mydata1[[i]] = tgt/sqrt(sum(tgt^2))
}
for (i in 1:30){
  tgt = c(rnorm(1,sd=0.1),1,rnorm(1,sd=0.1))
  mydata2[[i]] = tgt/sqrt(sum(tgt^2))
}
myriem1 = wrap.sphere(mydata1)
myriem2 = wrap.sphere(mydata2)

## COMPUTE p-WASSERSTEIN DISTANCES
dist1 = riem.wasserstein(myriem1, myriem2, p=1)
dist2 = riem.wasserstein(myriem1, myriem2, p=2)
dist5 = riem.wasserstein(myriem1, myriem2, p=5)

pm1 = paste0("p=1: dist=",round(dist1$distance,3))
pm2 = paste0("p=2: dist=",round(dist2$distance,3))
pm5 = paste0("p=5: dist=",round(dist5$distance,3))

## VISUALIZE TRANSPORT PLAN AND DISTANCE
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,3))
image(dist1$plan, axes=FALSE, main=pm1)
image(dist2$plan, axes=FALSE, main=pm2)
image(dist5$plan, axes=FALSE, main=pm5)
par(opar)


[Package Riemann version 0.1.4 Index]