Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fitting model with TMBhelper::fit_mod() and with random effects not working #51

Open
jysullivan opened this issue Jun 4, 2020 · 0 comments

Comments

@jysullivan
Copy link
Member

Debugging TMBhelper's fit_mod() function, which currently doesn't work. Also can't figure getting NAN function eval for random effects even though one can estimate sigmaR when rec_devs/rinit_devs are treated as fixed effects. Tried to fix this before I left but didn't have time to finish it. Please reach out to ummjane@gmail.com for help with this feature. Here's some code to get started.

# # Using TMBhelper's fit_tmb():
# TMB::compile("mod.cpp")
# dyn.load(TMB::dynlib("mod"))
# 
# # work out the map for this phase if phases for parameters is less than the
# # current phase then map will contain a factor filled with NAs
# map_use <- list()
# map_use$dummy <- fill_vals(parameters$dummy, NA)
# 
# # if not using random effects, assign log_sigma_r an NA in the map so it's not estimated
# if (data$random_rec == FALSE) {
#   map_use$log_sigma_r <- fill_vals(parameters$log_sigma_r, NA)
# }
# 
# # if natural mortality is fixed, assign log_M an NA in the map so its not
# # estimated
# if (data$M_type == 0) {
#   map_use$log_M <- fill_vals(parameters$log_M, NA)
# }
# 
# # if not using the Dirichlet-multinonial, assign log_fsh_theta and
# # log_srv_theta NAs in the map so they're not estimated
# if (data$comp_type != 1) {
#   map_use$log_fsh_theta <- fill_vals(parameters$log_fsh_theta, NA)
#   map_use$log_srv_theta <- fill_vals(parameters$log_srv_theta, NA)
# }
# 
# # Temporary debug trying to figure out why I'm getting NA/NaN function
# # evaluation
# if (tmp_debug == TRUE) {
#   # map_use$log_spr_Fxx <- fill_vals(parameters$log_spr_Fxx, NA)
#   map_use$log_fsh_slx_pars <- fill_vals(parameters$log_fsh_slx_pars, NA)
#   map_use$log_srv_slx_pars <- fill_vals(parameters$log_srv_slx_pars, NA)
#   # map_use$fsh_logq <- fill_vals(parameters$fsh_logq, NA)
# }
# # 
# # Build upper and lower parameter bounds and remove any that are not
# # estimated (should be the inverse of the map_use)
# bounds <- build_bounds(param_list = parameters)
# bounds$upper <- bounds$upper[!names(bounds$upper) %in% names(map_use)]
# bounds$lower <- bounds$lower[!names(bounds$lower) %in% names(map_use)]
# 
# # Remove inactive parameters from bounds and vectorize
# lower <- unlist(bounds$lower)
# upper <- unlist(bounds$upper)
# 
# # if (data$random_rec == TRUE) {
# #   lower <- lower[-which(grepl(random_vars[1], names(lower)))]
# #   lower <- lower[-which(grepl(random_vars[2], names(lower)))]
# #   upper <- upper[-which(grepl(random_vars[1], names(upper)))]
# #   upper <- upper[-which(grepl(random_vars[2], names(upper)))]
# # }
# # 
# obj <- TMB::MakeADFun(data, parameters, random = NULL,#random_vars, 
#                       DLL = "mod", map = map_use)
# 
# TMBhelper::fit_tmb(obj = obj, fn=obj$fn, gr=obj$gr, startpar=NULL, lower=lower, upper=upper,
#                    getsd=TRUE, control=list(eval.max=1e4, iter.max=1e4, trace=0), bias.correct=FALSE,
#                    bias.correct.control=list(sd=FALSE, split=NULL, nsplit=NULL, vars_to_correct=NULL),
#                    savedir=NULL, loopnum=1, newtonsteps=0, n=Inf, getReportCovariance=FALSE, 
#                    getJointPrecision=FALSE,
#                    getHessian=FALSE, quiet=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant