Description Usage Arguments Value Note Author(s) References Examples
Produces a Monte-Carlo Markov ensemble using the affine-invariant method of Goodman & Weare, saving progress periodically.
1 2 3 4 5 |
post |
an Nparam*Nwalkers*Nsteps array. post[,,1] should hold the initial state of the sampler (see help for GoodmanWeare). Checkpoints and the return value will have the same shape, with subsequent layers post[,,i] holding the ensemble state at later iterations. |
lnpost |
function taking a vector of parameter values as input, and returning the log-posterior density. |
thin |
thinning factor for saving the results. |
mention.every |
print a message to the console every time this many iterations are completed. |
save.every |
save the accumulated Markov ensemble to disk every time this many iterations are completed. |
save.file |
filename for saving progress. |
show.every |
plot parameter traces so far to the active graphics device periodically. |
show.params |
(sub)set of parameter traces to plot (default is to show all). |
show.walkers |
which walkers to plot traces of (default is first 8). |
show.pch1 |
plot symbol to use for short chains. |
show.pch2 |
plot symbol to use for long chains. |
show.pch.switch |
chain length that distinguishes "short" and "long" chains for plotting purposes. |
return.lnpost |
whether to return log-posterior values for each sample; see Value. |
... |
additional named arguments to pass to GoodmanWeare or lnpost. |
If return.lnpost==FALSE, an array of the same dimensionality as post, storing the position of the walkers in post[,,i] every thin iterations. Otherwise, a list containing that array as $post, as well as an Nwalkers*Nsteps array storing the corresponding log-posterior values as $lnP. The log-posterior values $lnP[,1], corresponding with the starting ensemble positions $post[,,1], will always be NA.
By default, the code will attempt to run in parallel (see the ‘parallel’ package). To prevent this, pass mc.cores=1.
If traces are being plotted (show.every not NA), par(mfrow=c(length(show.params), 1)) is called on the current graphics device.
Adam Mantz
See also help for rgw::GoodmanWeare.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # In this example, we'll sample from a simple 2D Gaussian.
# (This is the same example as used in GoodmanWeare.)
# Define the log-posterior function
lnP = function(x) sum( dnorm(x, c(0,1), c(pi, exp(0.5)), log=TRUE) )
# Initialize an ensemble of 100 walkers. We'll take 100 steps, saving the
# ensemble after each.
nwalk = 100
post = array(NA, dim=c(2, nwalk, 101))
post[1,,1] = rnorm(nwalk, 0, 0.1)
post[2,,1] = rnorm(nwalk, 1, 0.1)
# Run
post = GoodmanWeare.rem(post, lnP, mc.cores=1)
# Plot the final ensemble
plot(post[1,,101], post[2,,101])
# Look at the trace of each parameter for one of the walkers.
plot(post[1,1,])
plot(post[2,1,])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.