simNodesMV: Basic nimbleFunctions for using a NIMBLE model with sets of...

Description Usage Arguments Details Value Run time arguments Author(s) Examples

Description

simulate, calculate, or get the existing log probabilities for values in a modelValues object using a NIMBLE model

Usage

1
simNodesMV(model, mv, nodes)

Arguments

model

A nimble model.

nodes

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

mv

A modelValues object in which multiple sets of model variables and their corresponding logProb values are or will be saved. mv must include the nodes provided

expandNames

TRUE or FALSE: whether to expand node names provided. defaults to TRUE.

sortNodes

TRUE or FALSE: whether to sort node names provided (after expansion) according to the order of the model. defaults to TRUE. by node argument, along with each corresponding 'logProb_(nodeName)'.

Details

simNodesMV simulates values in the given nodes and saves them in mv. calcNodesMV calculates these nodes for each row of mv and returns a vector of the total log probabilities (densities) for each row. getLogProbNodesMV is like calcNodesMV without actually doing the calculations.

Each of these will expand variables or index blocks and topologically sort them so that each node's parent nodes are processed before itself.

getLogProbMV should be used carefully. It is generally for situations where the logProb values are guaranteed to have already been calculated, and all that is needed is to query them. The risk is that a program may have changed the values in the nodes, in which case getLogProbMV would collect logProb values that are out of date with the node values.

Value

from simNodesMV: NULL. from calcNodesMV and getLogProbMV: a vector of the sum of log probabilities (densities) from any stochastic nodes in nodes.

Run time arguments

Author(s)

Clifford Anderson-Bergman

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
code <- nimbleCode({
	for(i in 1:5)
	x[i] ~ dnorm(0,1)
})

myModel <- nimbleModel(code)
myMV <- modelValues(myModel)
cModel <- compileNimble(myModel)

Rsim <- simNodesMV(myModel, myMV)
Rcalc <- calcNodesMV(myModel, myMV)
Rglp <- getLogProbNodesMV(myModel, myMV)
Csim <- compileNimble(Rsim, project = myModel)
Ccalc <- compileNimble(Rcalc, project = myModel)
Cglp <- compileNimble(Rglp, project = myModel)
Csim(10)
Ccalc(saveLP = TRUE)
Cglp()	#Gives identical answers to Ccalc because logProbs were saved
Csim(10)
Ccalc(saveLP = FALSE)
Cglp()	#Gives wrong answers because logProbs were not saved

thirdwing/nimble documentation built on May 31, 2019, 10:41 a.m.