Question about the code of runMCMC

70 views
Skip to first unread message

frederic....@gmail.com

unread,
Feb 16, 2024, 2:59:08 AM2/16/24
to nimble-users
Dear all,
in an attempt to make model preparation shorter within calls to Nimble through the runMCMCbtadjust package (https://cran.r-project.org/web/packages/runMCMCbtadjust/index.html), much as is done with the command runMCMC in Nimble that needs to prepare the model only once, I have gone through the runMCMC code and understaood (correctly), that the same compiled model was used iteratively, with the command $run, with successive initializations of the different chains and with the default reset=TRUE parameter in the following code:

mcmc$run(niter, nburnin = nburnin, thin = thinToUseVec[1],
            thin2 = thinToUseVec[2], progressBar = progressBar,
            resetWAIC = ifelse(i == 1, TRUE, FALSE), chain = i)


I however had the question of what does the argument chain=i does here: as I understand it, $run only runs one chain at a time: so I don't understand what this argument means.

All the best,

Frédéric

Daniel Turek

unread,
Feb 16, 2024, 6:20:05 AM2/16/24
to frederic....@gmail.com, nimble-users
Frédéric, this is a good question, and I'm glad to hear you're still working on the runMCMCbtadjust package.

Nice investigation into runMCMC.  Yes, the chain number is passed to the core MCMC run method (mcmc$run) on each chain.  This is a very recent change to the MCMC system.  Accompanything this change, all MCMC samplers were also given the ability (although not the requirement) to execute their own "before_chain" and "after_chain" methods, prior to, and immediately following each MCMC chain.  Not all - in fact very few - MCMC samplers make use of these methods.  And furthermore, the number of MCMC iterations, and the chain number, and the burnin interval are all passed along as arguments to each before_chain method, in case the samplers could make use of this information (thus providing some description of the overarching MCMC run).  At present, I believe the only place this "chain number" information is used, is in the before_chain methods of the HMC samplers provided in the nimbleHMC package.  In those, if (and only if) chain==1, the other contextual information (niter, and nburnin) are used to dynamically set the HMC warmup period, which is thereafter used for all MCMC chains.  So, in a modest paragraph, that's the reason the chain number is passed to mcmc$run, and where it goes from there.

Keep in touch with any other questions, cheers,
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/42613f27-dc78-4e46-8685-6501db5f6e09n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages