MCMC.parallel {adaptMCMC} | R Documentation |
A wrapper function to generate several independent Markov chains by stetting up cluster on a multi-core machine. The function is based on the parallel package.
MCMC.parallel(p, n, init, n.chain = 4, n.cpu, packages = NULL, dyn.libs=NULL, scale = rep(1, length(init)), adapt = !is.null(acc.rate), acc.rate = NULL, gamma = 2/3, list = TRUE, ...)
p |
function that returns a value proportional to the log probability
density to sample from. Alternatively the function can return a list
with at least one element named |
n |
number of samples. |
init |
vector with initial values. |
n.chain |
number of independent chains. |
n.cpu |
number of CPUs that should be used in parallel. |
packages |
vector with name of packages to load into each instance. (Typically,
all packages on which |
dyn.libs |
vector with name of dynamic link libraries (shared objects) to load into each instance. The libraries must be located in the working directory. |
scale |
vector with the variances or covariance matrix of the jump distribution. |
adapt |
if |
acc.rate |
desired acceptance rate (ignored if |
gamma |
controls the speed of adaption. Should be between 0.5 and 1. A lower gamma leads to faster adaption. |
list |
logical. If |
... |
further arguments passed to |
This function is just a wrapper to use MCMC
in parallel. It is
based on parallel. Obviously, the application of this function
makes only sense on a multi-core machine.
A list with a list or matrix for each chain. See MCMC
for details.
Andreas Scheidegger, andreas.scheidegger@eawag.ch or scheidegger.a@gmail.com
## ---------------------- ## Banana shaped distribution ## log-pdf to sample from p.log <- function(x) { B <- 0.03 # controls 'bananacity' -x[1]^2/200 - 1/2*(x[2]+B*x[1]^2-100*B)^2 } ## ---------------------- ## generate samples ## compute 4 independent chains on 2 CPU's (if available) in parallel samp <- MCMC.parallel(p.log, n=200, init=c(x1=0, x2=1), n.chain=4, n.cpu=2, scale=c(1, 0.1), adapt=TRUE, acc.rate=0.234) str(samp)