| parallelTempering {EMC} | R Documentation |
Given a multi-modal and multi-dimensional target density function, a (possibly asymmetric) proposal distribution and a temperature ladder, this function produces samples from the target using the parallel tempering algorithm.
Below sampDim refers to the dimension of the sample space,
temperLadderLen refers to the length of the temperature ladder,
and levelsSaveSampForLen refers to the length of the
levelsSaveSampFor.
parallelTempering(nIters,
temperLadder,
startingVals,
logTarDensFunc,
MHPropNewFunc,
logMHPropDensFunc = NULL,
MHBlocks = NULL,
MHBlockNTimes = NULL,
moveProbsList = NULL,
moveNTimesList = NULL,
levelsSaveSampFor = NULL,
nThin = 1,
saveFitness = FALSE,
verboseLevel = 0,
...)
nIters |
|
temperLadder |
|
startingVals |
|
logTarDensFunc |
|
MHPropNewFunc |
|
logMHPropDensFunc |
|
MHBlocks |
|
MHBlockNTimes |
|
moveProbsList |
named |
moveNTimesList |
named |
levelsSaveSampFor |
|
nThin |
|
saveFitness |
|
verboseLevel |
|
... |
optional arguments to be passed to |
MHPropNewFunc and logMHPropDensFuncThe
MHPropNewFunc and the logMHPropDensFunc are called
multiple times by varying the block argument over
1:length(MHBlocks), so these functions should know how to
generate a proposal from the currentDraw or to evaluate the
proposal density depending on which block was passed as the
argument. See the example section for sample code.
MHBlocks and MHBlockNTimesBlocking is an
important and useful tool in MCMC that helps speed up sampling and
hence mixing. Example: Let sampDim = 6. Let we want to
sample dimensions 1, 2, 4 as one block, dimensions 3 and 5 as
another and treat dimension 6 as the third block. Suppose we want
to sample the three blocks mentioned above 1, 5 and 10 times in
each iteration, respectively. Then we could set MHBlocks =
list(c(1, 2, 4), c(3, 5), 6) and MHBlockNTimes = c(1, 5,
10)
.
The parallel tempering (PT; Liang and Wong, 2001) algorithm is composed of the following moves:
| MH | Metropolis-Hastings or mutation |
| RE | (random) exchange |
The current function could be used to run the PT algorithm by specifying what moves to employ using the following variables.
moveProbsList and moveNTimesListThe allowed
names for components of moveProbsList and
moveNTimesList come from the abbreviated names of the
moves above. For example, the following specifications are
valid:
moveProbsList = list(MH = 0.4,
RE = 0.6)
moveNTimesList = list(MH = 1,
RE = temperLadderLen)
levelsSaveSampForBy default, samples are saved and
returned for temperature level temperLadderLen. The
levelsSaveSampFor could be used to save samples from other
temperature levels as well (e.g., levelsSaveSampFor =
1:temperLadderLen saves samples from all levels).
saveFitnessThe term fitness refers to the function H(x), where the target density of interest is given by:
g(x) \propto \exp[ -H(x) / τ_{min} ]
H(x) is also known as the energy function. By default,
the fitness values are not saved, but one can do so by setting
saveFitness = TRUE.
Below nSave refers to ceil(nIters / nThin). This
function returns a list with the following components:
draws |
|
acceptRatios |
|
detailedAcceptRatios |
|
nIters |
the |
nThin |
the |
nSave |
as defined above. |
temperLadder |
the |
startingVals |
the |
moveProbsList |
the |
moveNTimesList |
the |
levelsSaveSampFor |
the |
time |
the time taken by the run. |
The effect of leaving the default value NULL for some of the
arguments above are as follows:
logMHPropDensFunc
| the proposal density MHPropNewFunc is deemed symmetric.
|
MHBlocks
| as.list(1:sampDim).
|
MHBlockNTimes
| rep(1, length(MHBlocks)).
|
moveProbsList
| list(MH = 0.4, RC = 0.3, SC = 0.3).
|
moveNTimesList
| list(MH = 1, RC = mm, SC = mm, RE = nn), where
|
mm <- floor(nn / 2) and nn <- temperLadderLen.
|
|
levelsSaveSampFor
| temperLadderLen.
|
Gopi Goswami goswami@stat.harvard.edu
Faming Liang and Wing H.Wong (2001). Real-Parameter Evolutionary Monte Carlo with Applications to Bayesian Mixture Models. Journal of the American Statistical Association 96:653-666.
## Not run:
samplerObj <-
with(VShapedFuncGenerator(-13579),
parallelTempering(nIters = 2000,
temperLadder = c(15, 6, 2, 1),
startingVals = c(0, 0),
logTarDensFunc = logTarDensFunc,
MHPropNewFunc = MHPropNewFunc,
levelsSaveSampFor = seq_len(4),
verboseLevel = 1))
print(samplerObj)
print(names(samplerObj))
with(samplerObj,
{
print(detailedAcceptRatios)
print(dim(draws))
par(mfcol = c(2, 2))
for (ii in seq_along(levelsSaveSampFor)) {
main <- paste('temper:', round(temperLadder[levelsSaveSampFor[ii]], 3))
plot(draws[ , , ii],
xlim = c(-5, 20),
ylim = c(-8, 8),
pch = '.',
ask = FALSE,
main = as.expression(main),
xlab = as.expression(substitute(x[xii], list(xii = 1))),
ylab = as.expression(substitute(x[xii], list(xii = 2))))
}
})
## End(Not run)