Skip to content

Commit

Permalink
Tweak output and fix minor bugs from fimsfit
Browse files Browse the repository at this point in the history
  • Loading branch information
Cole-Monnahan-NOAA committed Sep 3, 2024
1 parent dcf58ef commit fd345de
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions R/fimsfit.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ print.fimsfit <- function(fit, ...){
} else if(rt>60){
rt <- rt/60; ru <- 'minutes'
}

cat("Total run time was", round(rt,2), ru, '\n')
cat("Number of parameters:", paste(names(fit$opt$num_pars),
fit$opt$num_pars, sep='='),"\n")
Expand Down Expand Up @@ -100,19 +101,19 @@ if(is.null(control))
if(!verbose) control$trace <- 0
## optimize and compare
t0 <- Sys.time()
message("Starting optimization...")
if(verbose) message("Starting optimization...")
opt0 <- opt <-
with(obj, nlminb(start = par, objective = fn, gradient = gr, control=control))
maxgrad0 <- maxgrad <- max(abs(obj$gr(opt$par)))
if(loopnum>0){
message("Restarting optimizer ", loopnum, " times silently to improve gradient")
if(verbose) message("Restarting optimizer ", loopnum, " times silently to improve gradient")
for(ii in 2:loopnum){
control$trace <- 0
opt <- with(obj, nlminb(start = opt$par, objective = fn,
gradient = gr, control=control))
maxgrad <- max(abs(obj$gr(opt$par)))
}
message("Maximum gradient went from ", sprintf("%.3g", maxgrad0), " to ",
if(verbose) message("Maximum gradient went from ", sprintf("%.3g", maxgrad0), " to ",
sprintf("%.3g",maxgrad), " after ", loopnum," steps.")
}
n_total <- length(obj$env$last.par.best)
Expand All @@ -130,17 +131,16 @@ rep <- c(version=input$version, obj$report())
sdrep <- std <- NULL
time_sdreport <- NA
if(getsd){
t2 <- Sys.time()
sdrep <- sdreport(obj)
std <- summary(sdrep)
std <- data.frame(dimnames(std)[[1]], std)
names(std) <- c('name', 'est', 'se')
std$lwr <- std$est - 1.96*std$se
std$upr <- std$est + 1.96*std$se
row.names(std) <- NULL
# std <- group_by(std, name) %>%
# mutate(year=1969+1:n(), lwr=est-1.96*se,
# upr=est+1.96*se, version=input$version) %>%
# ungroup
if(verbose) message("Finished sdreport")
time_sdreport <- Sys.time() - t1
time_sdreport <- Sys.time() - t2
}
parList <- obj$env$parList()
parnames <- names(obj$par)
Expand Down

0 comments on commit fd345de

Please sign in to comment.