Skip to content

Commit

Permalink
Resolve some warnings and bug fixes on iter
Browse files Browse the repository at this point in the history
  • Loading branch information
Cole-Monnahan-NOAA committed May 31, 2024
1 parent 1a28701 commit d6b880c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions R/sparse.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
sample_sparse_tmb <- function(obj, iter, warmup, cores, chains,
control=NULL, seed=NULL){
iter <- iter-warmup
obj$env$beSilent()
sdr <- sdreport(obj, getJointPrecision=TRUE)
Q <- sdr$jointPrecision
Qinv <- solve(Q)
Expand Down Expand Up @@ -95,7 +96,7 @@ as.tmbfit <- function(x, mle, invf){
mon$Rhat <- mon$rhat
## prepare objects to use the pairs_admb function
post <- get_post(x, invf, parnames=parnames, TRUE)
sp <- x@diagnostics
sp <- as.data.frame(x@diagnostics)
spl <- list()
for(chain in 1:max(sp$.chain)){
spl[[chain]] <- as.matrix(sp[sp$.chain==chain,1:6])
Expand All @@ -104,7 +105,7 @@ as.tmbfit <- function(x, mle, invf){
monitor=mon, model='test',
max_treedepth=x@metadata$max_depth,
warmup=as.numeric(x@metadata$num_warmup),
iter=as.numeric(x@metadata$num_samples),
## iter=as.numeric(x@metadata$num_samples)+as.numeric(x@metadata$num_warmup),
algorithm='NUTS')
adfit(x)
}
10 changes: 7 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ check_identifiable <- function(model, path=getwd()){
## matrix operations.
x.cur <- (1/chd) * y.cur
} else if(is(M,"Matrix")){
warning( "Use of Q is highly experimental still" )
## warning( "Use of Q is highly experimental still" )
stopifnot(require(Matrix))
# M is actually Q, i.e., the inverse-mass
# Antidiagonal matrix JJ = I
Expand Down Expand Up @@ -756,8 +756,12 @@ extract_sampler_params <- function(fit, inc_warmup=FALSE){
ind <- -(1:fit$warmup)
its <- (1:nrow(x[[1]]))[ind]
}
y <- do.call(rbind, lapply(1:length(x), function(i)
cbind(chain=i, iteration=its, x[[i]][ind,])))
y <- do.call(rbind, lapply(1:length(x), function(i){
if(length(its) != NROW(x[[i]][ind,]))
warning("Length mismatch in extract_sampler_params: iterations=", length(its),
" and draws=", NROW(x[[i]][ind,]))
cbind(chain=i, iteration=its, x[[i]][ind,])
}))
return(invisible(as.data.frame(y)))
}

Expand Down

0 comments on commit d6b880c

Please sign in to comment.