Description Usage Arguments Details Value Note Author(s) References See Also Examples
Given a target density function and a symmetric proposal generating function, this function produces samples from the target using the random walk Metropolis algorithm.
Below sampDim refers to the dimension of the sample space.
1 2 3 4 5 6 7 8 9 10 | randomWalkMetropolis(nIters,
startingVal,
logTarDensFunc,
propNewFunc,
MHBlocks = NULL,
MHBlockNTimes = NULL,
nThin = 1,
saveFitness = FALSE,
verboseLevel = 0,
...)
|
nIters |
|
startingVal |
|
logTarDensFunc |
|
propNewFunc |
|
MHBlocks |
|
MHBlockNTimes |
|
nThin |
|
saveFitness |
|
verboseLevel |
|
... |
optional arguments to be passed to |
propNewFuncThe propNewFunc is called multiple
times by varying the block argument over
1:length(MHBlocks), so this function should know how to
generate a proposal from the currentDraw 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)
saveFitnessThe term fitness refers to the
negative of the logTarDensFunc values. 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. |
startingVal |
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:
MHBlocks
| as.list(1:sampDim).
|
MHBlockNTimes
| rep(1, length(MHBlocks)).
|
Gopi Goswami goswami@stat.harvard.edu
Jun S. Liu (2001). Monte Carlo strategies for scientific computing. Springer.
MetropolisHastings,
parallelTempering, evolMonteCarlo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | ## Not run:
samplerObj <-
with(CigarShapedFuncGenerator1(-13579),
randomWalkMetropolis(nIters = 5000,
startingVal = c(0, 0),
logTarDensFunc = logTarDensFunc,
propNewFunc = propNewFunc,
verboseLevel = 1))
print(samplerObj)
print(names(samplerObj))
with(samplerObj,
{
print(detailedAcceptRatios)
print(dim(draws))
plot(draws,
xlim = c(-3, 5),
ylim = c(-3, 4),
pch = '.',
ask = FALSE,
main = as.expression(paste('# draws:', nIters)),
xlab = as.expression(substitute(x[xii], list(xii = 1))),
ylab = as.expression(substitute(x[xii], list(xii = 2))))
})
samplerObj <-
with(threeDimNormalFuncGenerator(-13579),
{
randomWalkMetropolis(nIters = 5000,
startingVal = c(0, 0, 0),
logTarDensFunc = logTarDensFunc,
propNewFunc = propNewFunc,
MHBlocks = list(c(1, 2), 3),
verboseLevel = 1)
})
print(samplerObj)
print(names(samplerObj))
with(samplerObj,
{
print(detailedAcceptRatios)
print(dim(draws))
pairs(draws,
pch = '.',
ask = FALSE,
main = as.expression(paste('# draws:', nIters)),
labels = c(as.expression(substitute(x[xii], list(xii = 1))),
as.expression(substitute(x[xii], list(xii = 2))),
as.expression(substitute(x[xii], list(xii = 3)))))
})
## End(Not run)
|
Loading required package: mvtnorm
Loading required package: MASS
##
## Evolutionary Monte Carlo Package (EMC)
##
## Functionality: random walk Metropolis, general Metropolis-Hastings
## parallel tempering, target oriented EMC (TOEMC), temperature ladder
## construction and placement
##
## Use: "help(package = EMC)" at the R prompt for more info
##
## Copyright (C) 2006-2019 Gopi Goswami
##
## Created by: Gopi Goswami <goswami@stat.harvard.edu>
## Maintained by: Gopi Goswami <grgoswami@gmail.com>
##
BEGIN: EMC
..........
[Time to finish (est): 3 secs, this iter: 100]....................
[Time to finish (est): 2 secs, this iter: 600]....................
[Time to finish (est): 1 secs, this iter: 1100]....................
[Time to finish (est): 1 secs, this iter: 1600]....................
[Time to finish (est): 1 secs, this iter: 2100]....................
[Time to finish (est): 1 secs, this iter: 2600]....................
[Time to finish (est): 1 secs, this iter: 3100]....................
[Time to finish (est): 1 secs, this iter: 3600]....................
[Time to finish (est): 1 secs, this iter: 4100]....................
[Time to finish (est): 1 secs, this iter: 4600]................
[Total time: 1 secs (usr), 0 secs (sys), this iter: 5000]
E N D: EMC
The overall acceptance rate summary:
ratio accepted proposed
overall 0.2719 2719 10000
[1] "draws" "acceptRatios" "nIters"
[4] "nThin" "nSave" "detailedAcceptRatios"
[7] "time" "startingVal"
argminBlock min argmaxBlock max
acceptRatios 2 0.189 1 0.355
[1] 5000 2
BEGIN: EMC
..........
[Time to finish (est): 2 secs, this iter: 100]....................
[Time to finish (est): 2 secs, this iter: 600]....................
[Time to finish (est): 2 secs, this iter: 1100]....................
[Time to finish (est): 2 secs, this iter: 1600]....................
[Time to finish (est): 1 secs, this iter: 2100]....................
[Time to finish (est): 1 secs, this iter: 2600]....................
[Time to finish (est): 1 secs, this iter: 3100]....................
[Time to finish (est): 1 secs, this iter: 3600]....................
[Time to finish (est): 1 secs, this iter: 4100]....................
[Time to finish (est): 1 secs, this iter: 4600]................
[Total time: 2 secs (usr), 0 secs (sys), this iter: 5000]
E N D: EMC
The overall acceptance rate summary:
ratio accepted proposed
overall 0.3279 3279 10000
[1] "draws" "acceptRatios" "nIters"
[4] "nThin" "nSave" "detailedAcceptRatios"
[7] "time" "startingVal"
argminBlock min argmaxBlock max
acceptRatios 1 0.167 2 0.489
[1] 5000 3
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.