Skip to content

Commit

Permalink
Add generation of objfull (without Laplace approximation) to naomi-si…
Browse files Browse the repository at this point in the history
…mple_fit. Useful for #41
  • Loading branch information
athowes committed May 9, 2023
1 parent 3768b50 commit 2e01a1b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/naomi-simple_fit/functions.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' A local version of naomi::make_tmb_obj, edited to work with DLL = "naomi_simple"
local_make_tmb_obj <- function(data, par, calc_outputs = 0L, inner_verbose, progress = NULL, map = NULL, DLL = "naomi_simple") {
local_make_tmb_obj <- function(data, par, calc_outputs = 0L, inner_verbose, progress = NULL, map = NULL, DLL = "naomi_simple", laplace = TRUE) {
# Begin expose naomi:::make_tmb_obj
# https://github.com/mrc-ide/naomi/blob/e9de40f12cf2e652f78966bb351fa5718ecd7867/R/tmb-model.R#L496
data$calc_outputs <- as.integer(calc_outputs)
Expand Down Expand Up @@ -29,6 +29,10 @@ local_make_tmb_obj <- function(data, par, calc_outputs = 0L, inner_verbose, prog
integrate_out <- "x_minus_i"
}

if(!laplace) {
integrate_out <- NULL
}

obj <- TMB::MakeADFun(
data = data,
parameters = par,
Expand Down
4 changes: 4 additions & 0 deletions src/naomi-simple_fit/orderly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ artefacts:
description: Inference output
filenames:
- out.rds
- data:
description: Full objective function (without Laplace approximation)
filenames:
- objfull.rds

parameters:
#' Run inference with TMB? TRUE or FALSE
Expand Down
5 changes: 5 additions & 0 deletions src/naomi-simple_fit/script.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ tmb_inputs_simple <- local_exclude_inputs(tmb_inputs)
#' The number of hyperparameters is 24 (as compared with 31 for the full model)
n_hyper <- 24

#' Create version of the objective function with no Laplace approximation
#' This will be used in later reports, such as to do PSIS
objfull <- local_make_tmb_obj(tmb_inputs$data, tmb_inputs$par_init, calc_outputs = FALSE, inner_verbose = FALSE, DLL = "naomi_simple", laplace = FALSE)
saveRDS(objfull, file = "objfull.rds")

if(tmb) {
start <- Sys.time()

Expand Down

0 comments on commit 2e01a1b

Please sign in to comment.