Learn R Programming

nimble (version 1.2.1)

simNodes: Basic nimbleFunctions for calculate, simulate, and getLogProb with a set of nodes

Description

simulate, calculate, or get existing log probabilities for the current values in a NIMBLE model

Usage

simNodes(model, nodes)

calcNodes(model, nodes)

getLogProbNodes(model, nodes)

Arguments

model

A NIMBLE model

nodes

A set of nodes. If none are provided, default is all model$getNodeNames()

Author

Perry de Valpine

Details

These are basic nimbleFunctions that take a model and set of nodes and return a function that will call calculate, simulate, or getLogProb on those nodes. Each is equivalent to a direct call from R, but in nimbleFunction form they can be be compiled. For example, myCalc <- calcNodes(model, nodes); ans <- myCalc() is equivalent to ans <- model$calculate(nodes), but one can also do CmyCalc <- compileNimble(myCalc) to get a faster version. Note that this will often be much faster than using `calculate` from R with a compiled model, such as compiled_model$calculate(nodes) because of overhead in running `calculate` from R.

In nimbleFunctions, one would generally use model$calculate(nodes) in the run-time code (and similarly for `simulate` and `getLogProb`).