SourceForge has been redesigned. Learn more.

Is JAGS smart enough to not parse constant nodes multiple times?

  • VelocideX

    VelocideX - 2014-05-05

    Suppose I have

    for (i in 1:n){
        for (j in 1:n){
            a[i,j] <- some number (e.g. based on data) that never changes
    b[1:n,1:n] <- inverse(a[1:n,1:n])

    If n is large then there will be a huge penalty per iteration because of the matrix inversion. Is JAGS smart enough to realise that b only needs to be calculated once and then never again at subsequent iterations? If not, then b should be calculated in R and passed as data to JAGS. However, for some things it is convenient to calculate this in JAGS.

    I suppose this is what the data block is for (rather than the model block). It would still be good to know what the behaviour of JAGS is in the model block.


  • Martyn Plummer

    Martyn Plummer - 2014-05-06

    Yes. The node b is calculated once when the model is initialized, but not in subsequent iterations. This is true of any node that only has observed parents.


Log in to post a comment.