Learn R Programming

EMC (version 1.0)

placeTempers: Place the intermediate temperatures between the temperature limits

Description

Multiple MCMC chains based algorithms (e.g., parallel tempering, evolutionary Monte Carlo) need a temperature ladder. This function places the intermediate temperatures between the minimum and the maximum temperature for the ladder.

Usage

placeTempers(nIters,                           
             acceptRatioLimits,                      
             ladderLenMax,                           
             startingVals,                           
             logTarDensFunc,                         
             MHPropNewFunc,                          
             logMHPropDensFunc = NULL,               
             temperLadder      = NULL,               
             temperLimits      = NULL,               
             ladderLen         = 15,                 
             scheme            = 'exponential',      
             schemeParam       = 1.5,                
             guideMe           = TRUE,               
             levelsSaveSampFor = NULL,               
             saveFitness       = FALSE,              
             verboseLevel      = 0,
             ...)

Arguments

nIters
integer $>$ 0.
acceptRatioLimits
double vector of two probabilities.
ladderLenMax
integer $>$ 0.
startingVals
double matrix of dimension temperLadderLen $\times$ sampDim or vector of length sampDim, in which case the same starting values are used for every temperature level.
logTarDensFunc
function of two arguments (draw, ...) that returns the target density evaluated in the log scale.
MHPropNewFunc
function of four arguments (temperature, block, currentDraw, ...) that returns new Metropolis-Hastings proposals. See details below on the argument block.
logMHPropDensFunc
function of five arguments (temperature, block, currentDraw, proposalDraw, ...) that returns the proposal density evaluated in the log scale. See details below on the argument block.
temperLadder
double vector with all positive entries, in decreasing order.
temperLimits
double vector with two positive entries.
ladderLen
integer $>$ 0.
scheme
character.
schemeParam
double $>$ 0.
guideMe
logical.
levelsSaveSampFor
integer vector with positive entries.
saveFitness
logical.
verboseLevel
integer, a value $\ge$ 2 produces a lot of output.
...
optional arguments to be passed to logTarDensFunc, MHPropNewFunc and logMHPropDensFunc.

Value

  • This function returns a list with the following components:
  • finalLadderthe final temperature ladder found by placing the intermediate temperatures to be used in parallelTempering or evolMonteCarlo.
  • temperLadderthe temperature ladder used for the underlying MCMC run.
  • acceptRatiosEstthe estimated acceptance ratios for the random exchange move for the consecutive temperature levels of temperLadder.
  • CVSqWeightsthis is the square of the coefficient of variation of the weights of the importance sampling estimators used to estimate the acceptance ratios, namely, estAcceptRatios.
  • temperLimitsthe sorted temperLimits argument.
  • acceptRatioLimitsthe sorted acceptRatioLimits argument.
  • nItersthe post burn-in nIters.
  • levelsSaveSampForthe levelsSaveSampFor argument.
  • drawsarray of dimension nIters $\times$ sampDim $\times$ levelsSaveSampForLen, if saveFitness = FALSE. If saveFitness = TRUE, then the returned array is of dimension nIters $\times$ (sampDim + 1) $\times$ levelsSaveSampForLen; i.e., each of the levelsSaveSampForLen matrices contain the fitness values in their last column.
  • startingValsthe startingVals argument.
  • timethe time taken by the run.

Details

This function is based on the temperature placement method introduced in section 4.2 of Goswami and Liu (2007).

[object Object],[object Object],[object Object],[object Object],[object Object],rl{ scheme schemeParam ======== ============= linear NA log NA geometric NA mult-power NA add-power $\ge$ 0 reciprocal NA exponential $\ge$ 0 tangent $\ge$ 0 }

We recommended using scheme = 'exponential' and schemeParam in [0.3, 0.5].,[object Object],[object Object]

References

Gopi Goswami and Jun S. Liu (2007). On learning strategies for evolutionary Monte Carlo. Statistics and Computing 17:1:23-38.

See Also

findMaxTemper, parallelTempering, evolMonteCarlo

Examples

Run this code
## The V-shaped distribution
VShapedFuncGenerator <-
    function (seed = 13579)
{
    set.seed(seed)    
    dd     <- 2
    ARDisp <-
        function (rho)
        {
            tmp <- rep(1, dd)
            diag((1 - rho) * tmp) + rho * tmp %*% t(tmp)
        }

    nMixComps  <- 2
    logWeights <- log(rep(1 / nMixComps, nMixComps))
    meanMat    <- matrix(c(1, 1, 15, 1), nMixComps, byrow = TRUE)
    dispParam  <- c(-0.95, 0.95)
    dispArr    <- array(dim = c(2, 2, nMixComps))
    for (ii in seq_len(nMixComps)) {
        dispArr[ , , ii] <- ARDisp(dispParam[ii])
    }
    logTarDensFunc <-
        function (draw, ...)
        {
            ld <- sapply(seq_len(nMixComps), FUN =
                         function (ii)
                     {
                         dmvnorm(draw, meanMat[ii, ], dispArr[ , , ii], log = TRUE)
                     })
            ww <- logWeights + ld
            mm <- max(ww)
            mm + log(sum(exp(ww - mm)))
        }
    
    MHProposalSD  <- c(1.0, 1.0)
    MHPropNewFunc <-
        function (temperature, block, currentDraw, ...)
        {
            proposalDraw        <- currentDraw
            proposalDraw[block] <- rnorm(1, currentDraw[block],
                                         sqrt(temperature) * MHProposalSD[block])
            proposalDraw
        }

    list(logTarDensFunc = logTarDensFunc,
         MHPropNewFunc  = MHPropNewFunc)
}


placeTempersObj <-
    with(VShapedFuncGenerator( ),
         placeTempers(nIters            = 10000,
                      acceptRatioLimits = c(0.5, 0.6),
                      ladderLenMax      = 50,
                      startingVals      = c(0, 0),
                      logTarDensFunc    = logTarDensFunc,
                      MHPropNewFunc     = MHPropNewFunc,
                      temperLimits      = c(1, 5),
                      ladderLen         = 10,
                      levelsSaveSampFor = seq_len(10),
                      verboseLevel      = 1))
print(placeTempersObj)
print(names(placeTempersObj))
with(placeTempersObj,
 {
     par(mfcol = c(3, 3))
     for (ii in seq_along(levelsSaveSampFor)) {
         main <- paste('temper:', round(temperLadder[levelsSaveSampFor[ii]], 3))
         plot(draws[ , , ii],
              xlim = c(-4, 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))))   
     }
 })

Run the code above in your browser using DataLab