Pairwise Distance/Dissimilarities between Gaussian distributions
1 2 3 4 5 6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | ## test with 1-dimensional Gaussian distributions
list1d = list()
for (i in 1:15){
val.center = rnorm(1, sd=0.25)
val.sd = runif(1, min=0.75,max=1)
list1d[[i]] = wrapgauss1d(mean=val.center, sd=val.sd)
}
for (j in 16:40){
val.center = rnorm(1, sd=0.25) + 10
val.sd = runif(1, min=4.75,max=5)
list1d[[j]] = wrapgauss1d(mean=val.center, sd=val.sd)
}
## compute pairwise distance
d1wass2 = gauss.pdist(list1d, type="wass2")
d1kl = gauss.pdist(list1d, type="kl")
d1skl = gauss.pdist(list1d, type="skl")
d1cs = gauss.pdist(list1d, type="cs")
d1bh = gauss.pdist(list1d, type="bh")
## visualize
opar <- par(mfrow=c(2,3), pty="s")
image(d1wass2[,40:1], axes=FALSE, main="pdist: 2-Wasserstein")
image(d1kl[,40:1], axes=FALSE, main="pdist: KL")
image(d1skl[,40:1], axes=FALSE, main="pdist: Symmetric KL")
image(d1cs[,40:1], axes=FALSE, main="pdist: Cauchy-Schwarz")
image(d1bh[,40:1], axes=FALSE, main="pdist: Bhattacharyya")
par(opar)
## Not run:
## test with 5-dimensional Gaussian distributions
list5d = list()
for (i in 1:20){
vec.center = rmvnorm(1, mean=rep(0,5))
list5d[[i]] = wrapgaussNd(mu=vec.center, sigma=diag(5))
}
for (j in 21:40){
vec.center = rmvnorm(1, mean=rep(0,5)+1.5)
mysig = matrix(rnorm(100*5), ncol=5)
mysig = t(mysig)%*%mysig
list5d[[j]] = wrapgaussNd(mu=vec.center, sigma=mysig)
}
## compute pairwise distance
d5wass2 = gauss.pdist(list5d, type="wass2")
d5kl = gauss.pdist(list5d, type="kl")
d5skl = gauss.pdist(list5d, type="skl")
d5cs = gauss.pdist(list5d, type="cs")
d5bh = gauss.pdist(list5d, type="bh")
## visualize
opar <- par(mfrow=c(2,3), pty="s")
image(d5wass2[,40:1], axes=FALSE, main="pdist: 2-Wasserstein")
image(d5kl[,40:1], axes=FALSE, main="pdist: KL")
image(d5skl[,40:1], axes=FALSE, main="pdist: Symmetric KL")
image(d5cs[,40:1], axes=FALSE, main="pdist: Cauchy-Schwarz")
image(d5bh[,40:1], axes=FALSE, main="pdist: Bhattacharyya")
par(opar)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.