Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


hacking rjags, just a little

  • It would be useful at times to let the adaptation run through form some initial values, then prior to sampling to reset the parameters to some known state prior to collecting samples. I realize this is not sensible unless you know that your initial values are a good place to start sampling but sometimes you do and having the sampler return to that place on its own can be costly in terms of computer time. As far as I can tell, if you run through adaptation you get the 'rjags' object which is a list with ptr() a a function.

    Calling obj$ptr() gets you a pointer to the Console object. I could 1) modify rjags a little to give me a pointer to an SArray object (using Console::dumpState) prior to adaptation so that I can make a copy of the parameters; 2) keep a copy of the parameters; and 3)after adaptation do Console::setParameters to resest the parameters to the values I want.

    Is this about right? I expect I'll have to fiddle around with it but I wanted to check there were no big-picture problems I can't see (i.e.-if you reset parameters you re-trigger adaptation or something like that).

    It would also be useful to run through adaptation, replace the data (say with data from an outside imputation procedure), and then sample from there (again, with caveats) but as far as I can see there's no way of doing that without modifying the Console class in JAGS.

  • Martyn Plummer
    Martyn Plummer

    If you reset the values of some stochastic nodes then you need to ensure that their deterministic descendants are also updated. This is what is currently missing from the JAGS API, and is the fundamental reason why you can't reset parameter values after compilation.

    I think this will be easier to do with the JAGS 4.x API

    • Thanks for saving me some blundering around. I should add that the experience of trying to understand the JAGS code base has improved dramatically due to the time you've put in on documentation in the code.