Control of RW sampler

113 views
Skip to first unread message

Keith Lau

unread,
Apr 7, 2023, 1:19:15 PM4/7/23
to nimble-users
Hello,

I got some naive questions about the control of the RW sampler and wonder about the details.

First, when should we choose:
1. log==TRUE
2. reflective==TRUE
3. change adaptFactorExponent = 0.5 or 0.8 or other values?

Second, I noticed that the target acceptance rate is fixed to 0.44 (see https://github.com/cran/nimble/blob/master/R/MCMC_samplers.R). How can we change it to 0.234 to check the effect on the estimation results?

Thank you for the NIMBLE and the forum for discussion!

Keith

Daniel Turek

unread,
Apr 7, 2023, 2:46:55 PM4/7/23
to Keith Lau, nimble-users
Great questions, Keith.

1. log=TRUE is helpful when the parameter domain is strictly positive (like for variance / standard deviation parameters) and also potentially has non-trivial posterior density near to 0.  This serves to expand the unit interval [0,1] to the entire space of negative reals, and also remove the lower boundary, so sampling might work much better.  So, for example for standard deviation terms, where the posterior density might be close to 0.

2. reflective = TRUE when the parameter domain is bounded on an interval, for example a probability bounded in [0,1], with non-trivial posterior density near to one/both boundaries.  This makes the MH sampling "reflect" proposals off of the boundaries, so no proposal is "out of bounds".  So you might use this for a probability parameter, where the posterior is near to either 0 or 1.

3. Setting adaptFactorExponent to other values is experimental, we don't have much good guidance about what works well in different situations.  Higher values (anything positive is valid) will make the adaptation decay quickly, that is, the scale of proposals will quickly begin to change very little between adaptation cycles, and lower values (closer to 0) mean that adaptation of the proposal scale will attenuate very slowly, and continue to make (potentially large) changes for many adaptation cycles.  So high values will "stabilize" the adaptation of the proposal scale quickly, but perhaps it won't have sufficient time to adapt to a good value, while low values will make the adaptation span many MCMC iterations.  As I said, there's no good guidance on what will work better in different situations.

You're right, for all of the options, it appears the RW sampler target acceptance rate is hard-coded to be 0.44.  We could make this an option very easily, if that's useful.  Otherise, your best bet is to copy the RW sampler code, change this value (or make it into an option), define your custom sampler (maybe named "RW2", to be vague), and then add this new sampler to the MCMC configuration using addSampler.

Hope this helps,
Daniel




--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/d61d6e51-abf1-4b9e-b5ac-221612c417f0n%40googlegroups.com.
Message has been deleted
Message has been deleted

Daniel Turek

unread,
Apr 12, 2023, 11:05:54 AM4/12/23
to Keith Lau, nimble-users
Keith, in the function definition of your RW2 sampler, find the line that says:

ccList <- mcmc_determineCalcAndCopyNodes(model, target)

and try changing it to:

ccList <- nimble:::mcmc_determineCalcAndCopyNodes(model, target)

GIve that a try.

Daniel

On Tue, Apr 11, 2023 at 6:04 PM Keith Lau <genw...@gmail.com> wrote:
Thank you, Daniel. They are very informative in understanding how to use the settings.
For the acceptance rate, I followed your instruction and then ran into a problem. First, I copied sampler_RW function, named it as RW2, and modified it with "optimalAR <- 0.234". Next, I did a loop to set up conf$addSampler(paste("lambda[",k,",",i,"]",sep=""), type = "RW2"), where conf is from configureMCMC(). However, buildMCMC(conf) showed an error message:
Error in mcmc_determineCalcAndCopyNodes(model, target) :
  could not find function "mcmc_determineCalcAndCopyNodes"

I think I must miss some important steps. I looked up the manual but still not sure how to solve it.

Keith
Daniel Turek 在 2023年4月8日 星期六凌晨2:46:55 [UTC+8] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages