GoodmanWeare.rem {rgw}R Documentation

Goodman-Weare Affine-Invariant Sampling

Description

Produces a Monte-Carlo Markov ensemble using the affine-invariant method of Goodman & Weare, saving progress periodically.

Usage

GoodmanWeare.rem(post, lnpost, thin=1, mention.every=NA,
 save.every=NA, save.file=NA, show.every=NA,
 show.params=1:dim(post)[1], show.walkers=min(dim(post)[2],8),
 show.pch1=1, show.pch2='.', show.pch.switch=500,
 return.lnpost=FALSE, ...)

Arguments

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.

Value

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.

Note

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.

Author(s)

Adam Mantz

References

See also help for rgw::GoodmanWeare.

Examples

# 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,])

[Package rgw version 0.3.0 Index]