code <- nimbleCode({
for(i in 1:5)
x[i] ~ dnorm(0,1)
})
myModel <- nimbleModel(code)
myMV <- modelValues(myModel)
Rsim <- simNodesMV(myModel, myMV)
Rcalc <- calcNodesMV(myModel, myMV)
Rglp <- getLogProbNodesMV(myModel, myMV)
if (FALSE) {
cModel <- compileNimble(myModel)
Csim <- compileNimble(Rsim, project = myModel)
Ccalc <- compileNimble(Rcalc, project = myModel)
Cglp <- compileNimble(Rglp, project = myModel)
Csim$run(10)
Ccalc$run(saveLP = TRUE)
Cglp$run() #Gives identical answers to Ccalc because logProbs were saved
Csim$run(10)
Ccalc$run(saveLP = FALSE)
Cglp$run() #Gives wrong answers because logProbs were not saved
result <- as.matrix(Csim$mv)
}
Run the code above in your browser using DataLab