canmod / macpan2helpers

GNU General Public License v3.0
0 stars 0 forks source link

help with `mk_calibrate`? #5

Closed bbolker closed 1 year ago

bbolker commented 1 year ago

The current version of mk_calibrate isn't quite working yet.

library(macpan2helpers)
example("mk_calibrate")

will show the problems. This is the code:

library(macpan2helpers)
setup_sim <- function() {
   m <- Compartmental(system.file("starter_models", "sir", package = "macpan2"))
   sim <- m$simulators$tmb(
     time_steps = 100,
     state = c(S = 99, I = 1, R = 0),
     flow = c(foi = NA, gamma = 0.1),
     beta = 0.2,
     N = empty_matrix
   )
}
sim <- setup_sim()
mk_calibrate(sim,
   data = list(I_obs = rep(0, 100)),
   params = list(beta = 0.2, I_sd = 1),
   transforms = list(beta = "log", I_sd = "log"),
   exprs = list(log_lik ~ dnorm(I_obs, I, I_sd)),
   debug = TRUE
)

The debugging output:

add log_lik matrix (empty)
add data matrix: I_obs
add param (scalar placeholder value):  I_sd 
process expression:  log_lik ~ dnorm(I_obs, I, I_sd) 
add (empty matrix):  I_sim 
add  I_sim ~ I 
add  log_lik ~ dnorm(I_obs, rbind_time(I_sim), I_sd) 
param_frame:
       mat row col default
1 log_beta   0   0     0.2
2 log_I_sd   0   0     1.0
adding transformations
add transformation:  Log   beta 
add transformation:  Log   I_sd 
set obj_fn to -sum(log_lik)

As far as I can tell this is doing the same steps as the calibration vignette, but sim$report(c(1,1)) gives

sim$report(c(0,0))
MACPAN ERROR #20: Can only rbind_time (or rbind_lag) initialized matrices with saved history
<repeated 4 more times>
Error in self$.runner(..., .phases = .phases, .method = "report") : 
Error thrown by the TMB engine at the following expression:
log_lik ~ dnorm(I_obs, rbind_time(I_sim), I_sd)

Any ideas?

stevencarlislewalker commented 1 year ago

Does this address your issues @bbolker?