This demo shows how to use the malt function from the malt library to sample from the Banana distribution.
Banana distribution θ = (θ1, θ2)
given by
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