# NOT RUN {
mu1 <- c(-1, -1)
mu2 <- c(+1, +1)
sigma.sq <- 0.16
ub <- c(1.5, 3)
X0 <- matrix(c(-2,-1, 0,-2, 0, 1, 0, 1, 1,
-2,-1,-2, 0, 0, 0, 2, 1, 2), ncol = 2)
f <- function(x) {
px <- 1/4/pi/sqrt(sigma.sq) * exp(-1/2/sigma.sq *
sum((x - mu1)^2)) + 1/4/pi/sqrt(sigma.sq) *
exp(-1/2/sigma.sq * sum((x - mu2)^2))
return(log(px))
}
# }
# NOT RUN {
explore.out <- hybrid.explore(f, X0, ub=ub, n=150, graph=TRUE)
sample.out <- hybrid.sample(explore.out, n=500, graph=TRUE)
opar <- par(mfrow=c(2,1))
plot(density(sample.out$SAMP[,1]), xlab="x1", ylab="f(x)")
plot(density(sample.out$SAMP[,2]), xlab="x2", ylab="f(x)")
par(opar)
# }
Run the code above in your browser using DataLab