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 \(\theta=(\theta_1,\theta_2)\) given by \[ \begin{align*} \theta_1~&\sim~\mathcal{N}(0,10)\,, \\ \theta_2~&\sim~\mathcal{N}(0.03(\theta_1^2-100),1)\,. \end{align*} \] 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.1321228 -2.7184071
output$acceptance
#> NULL

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

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


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

library(coda)
effectiveSize(chain)
#>     var1     var2 
#> 5500.536 2899.041
effectiveSize(chain^2)
#>     var1     var2 
#> 1379.634 3261.640