Beyond the convex framework

This demo shows how to use the malt function from the malt library to sample from the Banana distribution.

library(malt)

Banana distribution θ = (θ1, θ2) given by θ1  N(0,10),θ2  N(0.03(θ12100),1). It is a simple modification of a two dimensional Gaussian target with level sets that are highly non-convex.

The potential and its gradient are specified as follows:

U=function(theta){
(theta[1]^2/10+(theta[2]-0.03*(theta[1]^2-100))^2)/2
}
grad=function(theta){
c(theta[1]/10+0.06*theta[1]*(0.03*(theta[1]^2-100)-theta[2]),theta[2]-0.03*(theta[1]^2-100))
}
d=2
init=rep(5,d)
n_steps=5000
g=0.1
h=1.5
L=6
output=malt(init, U, grad, n_steps, g, h, L)
chain=output$samples
apply(chain,2,mean)
#> [1] -0.003203299 -2.703817032
output$acceptance
#> NULL

plot(chain[,1],type="l")

plot(chain[,2],type="l")


plot(chain[,1],chain[,2])

library(coda)
effectiveSize(chain)
#>     var1     var2 
#> 5951.215 3622.023
effectiveSize(chain^2)
#>     var1     var2 
#> 1958.678 3791.770