Skip to content

dynamic indexing BUGS processing

Christopher Paciorek edited this page Jun 1, 2017 · 6 revisions

Steps in BUGS declaration and graph processing for dynamic indexing

currently we do not explicitly handle mu[i,k[i], j[i], 3] though much of the processing may work for that case

we also do not handle: mu[1:3, k[i]]

We do handle: mu[i,k[i],3], which will be used here as a running example.

  1. genSymbolicParentNodes: convert y[i] ~ dnorm(mu[i,k[i],3], 1) to y[i] ~ dnorm(mu[i,NA,3], 1) and have .USED_IN_INDEX(k[i]) as symbolicParentNode

  2. genUnknownIndexDeclarations (do this after genSymbolicParentNodes because we need the NAs in the symbolicParentNodes, but no later so we can rely on various processing of the declarations that will be created at this step using existing machinery):

  • create additional declInfo elements for unknownIndex variables: .mu_UNKNOWN_INDEX[i,NA,3] <- mu[i,NA,3]
  • cannot insert full extent of dynamic index because don't know variable sizes yet
  • this step facilities relying on existing machinery to determine vertices
  1. addDynamicIndexVars (after genVarInfo3):
  • this creates a variable '.mu_UNKNOWN_INDEX' in varInfo that mimics the 'mu' variable; this will be used for looking up the full extent of the variable to replace NA index
  • this also creates a vector of names of variables that represent unknown indices: 'unknownIndexNames'
  1. findDynamicIndexParticipants (after addDynamicIndexVars because it uses varInfo)
  • (not yet implemented) this will walk through declarations and find variables used in dynamic index expressions (i.e., k[i] nodes in our running example here)
  • currently this function puts the full extent of the unknown index into the lifted declaration, in particular into parentExpr, symbolicParentNodes, targetExpr, parentIndexNamePieces - i.e., we get .mu_UNKNOWN_INDEX[i,1:4,3] and mu[i,1:4,3]. This allows current machinery to determine that .mu_UNKNOWN_INDEX[i,1:4,3] is a child of whatever mu[i,...,3] vertices are created
  • this also strips out the ".USED_IN_INDEX()" wrapping though this stripping may be moved as it needs to be done after the (not yet implemented) step in which we determine the variables/vertices used in dynamic index expressions
  1. genExpandedNodeAndParentNames3
  • step 4 (split vertices): split mu[i,NA,3] into all possible fractured vertices: mu[i,1,3],mu[i,2,3],mu[i,3,3],mu[i,4,3]

  • step 7d: now that vars_2_vertexOrigID are created, set vars_2_nodeOrigID for unknownIndex variables back to NAs since in some sense they are RHS only and not nodeFunctions

  • new step preceding step 8: replace symbolicParentNodes and parentIndexNamePieces that contain unknown indices with the unknownIndex variable, e.g., y[i] ~ dnorm(mu[i,NA,3],1) becomes y[i] ~ dnorm(.mu_UNKNOWN_INDEX[i,1:4,3],1) in terms of symbolicParentNodes and parentIndexNamePieces; this allows current machinery to determine children of .mu_UNKNOWN_INDEX

FIXME: need to check some elements of maps to make sure the UNKNOWN_INDEX variables/vertices are properly done

  1. stripUnknownIndexInfo (after genExpandedNodeAndParentNames3): strip out introduced stuff that shouldn't go into the model currently this just removes the lifted declarations: .mu_UNKNOWN_INDEX[i,1:4,3] <- mu[i,1:4,3]
Clone this wiki locally