if (FALSE) {
#-------------------------------------------------------------------
# Free-Support Wasserstein Median of Multiple Gaussians
#
# * class 1 : samples from N((0,0), Id)
# * class 2 : samples from N((20,0), Id)
#
# We draw 8 empirical measures of size 50 from class 1, and
# 2 from class 2. All measures have uniform weights.
#-------------------------------------------------------------------
## GENERATE DATA
# 8 empirical measures from class 1
input_measures = vector("list", length=10L)
for (i in 1:8){
input_measures[[i]] = matrix(rnorm(50*2), ncol=2)
}
for (j in 9:10){
base_draw = matrix(rnorm(50*2), ncol=2)
base_draw[,1] = base_draw[,1] + 20
input_measures[[j]] = base_draw
}
## COMPUTE
# compute the Wasserstein median
run_median = rmedIRLS(input_measures, num_support = 50)
# compute the Wasserstein barycenter
run_bary = rbaryGD(input_measures, num_support = 50)
## VISUALIZE
opar <- par(no.readonly=TRUE)
# draw the base points of two classes
base_1 = matrix(rnorm(80*2), ncol=2)
base_2 = matrix(rnorm(20*2), ncol=2)
base_2[,1] = base_2[,1] + 20
base_mat = rbind(base_1, base_2)
plot(base_mat, col="gray80", pch=19)
# auxiliary information
title("estimated barycenter and median")
abline(v=0); abline(h=0)
# draw the barycenter and the median
points(run_bary$support, col="red", pch=19)
points(run_median$support, col="blue", pch=19)
par(opar)
}
Run the code above in your browser using DataLab