Skip to content

Commit

Permalink
some cleanup stuff related to 0.10.0 efforts
Browse files Browse the repository at this point in the history
  • Loading branch information
paciorek committed Aug 22, 2020
1 parent 794a1fd commit a445306
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 29 deletions.
Binary file modified UserManual/NimbleUserManual.pdf
Binary file not shown.
3 changes: 2 additions & 1 deletion packages/nimble/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export(nimSwitch)
export(nimbleCode)
export(nimbleExternalCall)
export(nimbleFunction)
export(nimbleFunctionList)
export(nimbleFunctionVirtual)
export(nimbleList)
export(nimbleMCMC)
Expand Down Expand Up @@ -250,4 +251,4 @@ exportClasses(nimbleFunctionBase)
exportClasses(nimbleFunctionList)
exportClasses(nimbleType)
exportClasses(samplerAssignmentRules)
exportClasses(singleVarAccessClass)
exportClasses(singleVarAccessClass)
29 changes: 2 additions & 27 deletions packages/nimble/R/BNP_samplers.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,6 @@ getNsave <- nimbleFunction(
methods = list( reset = function () {} )
)

getParentNodes <- function(nodes, model, returnType = 'names', stochOnly = FALSE) {
## adapted from BUGS_modelDef creation of edgesFrom2To
getParentNodesCore <- function(nodes, model, returnType = 'names', stochOnly = FALSE) {
nodeIDs <- model$expandNodeNames(nodes, returnType = "ids")
fromIDs <- sort(unique(unlist(edgesTo2From[nodeIDs])))
fromNodes <- maps$graphID_2_nodeName[fromIDs]
if(!length(fromNodes))
return(character(0))
fromNodesDet <- fromNodes[model$modelDef$maps$types[fromIDs] == 'determ']
## Recurse through parents of deterministic nodes.
fromNodes <- c(if(stochOnly) fromNodes[model$modelDef$maps$types[fromIDs] == 'stoch'] else fromNodes,
if(length(fromNodesDet)) getParentNodesCore(fromNodesDet, model, returnType, stochOnly) else character(0))
fromNodes
}

maps <- model$modelDef$maps
maxNodeID <- length(maps$vertexID_2_nodeID) ## should be same as length(maps$nodeNames)
## Only determine edgesTo2From once and then obtain in getParentNodesCore via scoping.
edgesLevels <- if(maxNodeID > 0) 1:maxNodeID else numeric(0)
fedgesTo <- factor(maps$edgesTo, levels = edgesLevels) ## setting levels ensures blanks inserted into the splits correctly
edgesTo2From <- split(maps$edgesFrom, fedgesTo)

getParentNodesCore(nodes, model, returnType, stochOnly)
}

##-----------------------------------------
## Wrapper function for sampleDPmeasure
##-----------------------------------------
Expand All @@ -83,7 +58,7 @@ getParentNodes <- function(nodes, model, returnType = 'names', stochOnly = FALSE
#'
#' The \code{epsilon} argument is optional and used to determine the truncation level of the random measure. \code{epsilon} is the tail probability of the random measure, which together with posterior samples of the concentration parameter, determines the truncation level. The default value is 1e-4.
#'
#' The output is a list of matrices. Each matrix represents a sample from the random measure. In order to reduce the output's dimensionality, the weigths of identical atoms are added up. The stick-breaking weights are named \code{weights} and the atoms are named based on the cluster variables in the model.
#' The output is a list of matrices. Each matrix represents a sample from the random measure. In order to reduce the output's dimensionality, the weights of identical atoms are added up. The stick-breaking weights are named \code{weights} and the atoms are named based on the cluster variables in the model.
#'
#' For more details about sampling the random measure and determining its truncation level, see Section 3 in Gelfand, A.E. and Kottas, A. 2002.
#'
Expand All @@ -92,7 +67,7 @@ getParentNodes <- function(nodes, model, returnType = 'names', stochOnly = FALSE
#'
#' Sethuraman, J. (1994). A constructive definition of Dirichlet priors. \emph{Statistica Sinica}, 639-650.
#'
#' Gelfand, A.E. and Kottas, A. (2002). A computational approach for full nonparametric Bayesian inference under Dirichlet process mixture models. \emph{ournal of Computational and Graphical Statistics}, 11(2), 289-305.
#' Gelfand, A.E. and Kottas, A. (2002). A computational approach for full nonparametric Bayesian inference under Dirichlet process mixture models. \emph{Journal of Computational and Graphical Statistics}, 11(2), 289-305.
#' @examples
#' \dontrun{
#' conf <- configureMCMC(model)
Expand Down
2 changes: 1 addition & 1 deletion packages/nimble/R/distributions_processInputList.R
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ prepareDistributionInput <- function(densityName, userEnv) {
cdfName <- sub('^d', 'p', densityName)
quantileName <- sub('^d', 'q', densityName)
out$pqAvail <- exists(cdfName, where = userEnv) && exists(quantileName, where = userEnv) && is.rcf(get(cdfName, pos = userEnv)) &&
is.rcf(get(quantileName, pos = UserEnv))
is.rcf(get(quantileName, pos = userEnv))

# check consistent types
if(out$pqAvail) {
Expand Down

0 comments on commit a445306

Please sign in to comment.