Skip to content

Commit 79fa954

Browse files
calibrator without data
1 parent aaa5568 commit 79fa954

File tree

8 files changed

+56
-61
lines changed

8 files changed

+56
-61
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: macpan2
22
Title: Fast and Flexible Compartmental Modelling
3-
Version: 1.16.1
3+
Version: 1.16.2
44
Authors@R: c(
55
person("Steve Walker", email="[email protected]", role=c("cre", "aut")),
66
person("Weiguang Guan", role="aut"),

R/mp_cal_time.R

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#' time using a (1) \code{\link{Date}} vector, (2) \code{\link{character}}
1515
#' vector in YYYY-MM-DD format, or (3) \code{\link{integer}} vector that
1616
#' counts the number of days since some reference. Otherwise please choose
17-
#' 'steps' and convert your time column into integer values that represent
18-
#' the time step that you would like in the model.
17+
#' 'steps', the default, and convert your time column into integer values that
18+
#' represent the time step that you would like in the model.
1919
#' @param time_column Name of the column that will identify the time at which
2020
#' particular values were observed.
2121
#'
@@ -24,12 +24,21 @@
2424
#' @seealso [mp_sim_offset()]
2525
#'
2626
#' @export
27-
mp_sim_bounds = function(sim_start, sim_end, time_scale, time_column = "time") {
27+
mp_sim_bounds = function(sim_start, sim_end, time_scale = "steps", time_column = "time") {
2828
self = Base()
2929
self$sim_start = sim_start
3030
self$sim_end = sim_end
3131
self$time_scale = time_scale
3232
self$time_column = time_column
33+
self$extend = function(steps_to_extend) {
34+
new_obj = mp_sim_offset(
35+
self$sim_start_offset
36+
, self$sim_end_offset + steps_to_extend
37+
, self$time_scale
38+
, self$time_column
39+
)
40+
return(new_obj)
41+
}
3342
self$cal_time_steps = function(data, original_coercer = force) {
3443
column = data[[self$time_column]]
3544
check_valid_time_scales(self$time_scale)
@@ -63,12 +72,21 @@ mp_sim_bounds = function(sim_start, sim_end, time_scale, time_column = "time") {
6372
#' @seealso [mp_sim_bounds()]
6473
#'
6574
#' @export
66-
mp_sim_offset = function(sim_start_offset, sim_end_offset, time_scale, time_column = "time") {
75+
mp_sim_offset = function(sim_start_offset, sim_end_offset, time_scale = "steps", time_column = "time") {
6776
self = Base()
6877
self$sim_start_offset = as.integer(sim_start_offset)
6978
self$sim_end_offset = as.integer(sim_end_offset)
7079
self$time_scale = time_scale
7180
self$time_column = time_column
81+
self$extend = function(steps_to_extend) {
82+
new_obj = mp_sim_offset(
83+
self$sim_start_offset
84+
, self$sim_end_offset + steps_to_extend
85+
, self$time_scale
86+
, self$time_column
87+
)
88+
return(new_obj)
89+
}
7290
self$cal_time_steps = function(data, original_coercer = force) {
7391
column = data[[self$time_column]]
7492
check_valid_time_scales(self$time_scale)

R/mp_forecaster.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ mp_forecaster = function(calibrator, forecast_period_time_steps
7272
args$spec = spec
7373
if (!is.null(data)) args$data = data
7474
if (!is.null(outputs)) args$outputs = outputs
75-
args$time = cal$time_steps_obj$extended_time_arg(forecast_period_time_steps)
75+
if (is.null(args$time)) {
76+
args$time = calibrator$time_steps_obj$extended_time_arg(forecast_period_time_steps)
77+
} else {
78+
args$time = args$time$extend(forecast_period_time_steps)
79+
}
7680
do.call(mp_tmb_calibrator, args)
7781
}
7882

R/mp_tmb_calibrator.R

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -446,37 +446,6 @@ TMBCalDataStruc = function(data, time) {
446446
FALSE
447447
}
448448

449-
# self$time_steps = time$bound_steps()[2L]
450-
# data$time_ids = time$time_ids(data$time)
451-
# self$data_time_ids = data$time_ids
452-
# self$data_time_steps = max(data$time_ids)
453-
454-
# if (nrow(data) == 0L) {
455-
# time = Steps(1, 1)
456-
# } else {
457-
# if (is.null(time)) {
458-
# if (infer_time_step(data$time)) {
459-
# data$time = as.integer(data$time)
460-
# time = Steps(min(data$time), max(data$time))
461-
# } else {
462-
# ## TODO: I'm guessing this could fail cryptically
463-
# time = Daily(min(data$time), max(data$time), checker = NoError)
464-
# }
465-
# }
466-
# else {
467-
# time = assert_cls(time, "CalTime", match.call(), "?mp_cal_time")
468-
# time$update_data_bounds(data)
469-
# }
470-
# }
471-
# self$time_steps = time$bound_steps()[2L]
472-
# data$time_ids = time$time_ids(data$time)
473-
# self$data_time_ids = data$time_ids
474-
# if (nrow(data) == 0L) {
475-
# self$data_time_steps = 1L
476-
# } else {
477-
# self$data_time_steps = max(data$time_ids)
478-
# }
479-
480449
data = rename_synonyms(data
481450
, time = c(
482451
"time", "Time", "ID", "time_id", "id", "date", "Date"
@@ -502,7 +471,9 @@ TMBCalDataStruc = function(data, time) {
502471
original_coercer = force
503472
}
504473
if (nrow(data) == 0L) {
505-
time = mp_sim_bounds(1L, 1L, "steps")
474+
if (is.null(time)) {
475+
time = mp_sim_bounds(1L, 1L, "steps")
476+
}
506477
} else {
507478
if (is.null(time)) {
508479
if (infer_time_step(data$time)) {
@@ -590,9 +561,6 @@ CalTimeStepsAbstract = function() {
590561
}
591562
self$sim_vec = function() seq(from = self$sim_1st(), by = 1L, len = self$sim_len())
592563
self$dat_vec = function() seq(from = self$dat_1st(), by = 1L, len = self$dat_len())
593-
self$extended_time_arg = function(extension) {
594-
mp_sim_offset(0, as.integer(extension), "steps")
595-
}
596564
return_object(self, "CalTimeStepsAbstract")
597565
}
598566
CalTimeStepsInt = function(ext_sim_1st, ext_sim_end, ext_dat_1st, ext_dat_end, original_coercer = force) {
@@ -611,6 +579,9 @@ CalTimeStepsInt = function(ext_sim_1st, ext_sim_end, ext_dat_1st, ext_dat_end, o
611579
self$original_coercer(external)
612580
}
613581
self$external_to_internal = function(external) external - self$ext_sim_1st + self$sim_1st()
582+
self$extended_time_arg = function(extension) {
583+
mp_sim_offset(0, as.integer(extension), "steps")
584+
}
614585
return_object(self, "CalTimeStepsInt")
615586
}
616587
if (FALSE) {

R/tmb_model.R

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -656,16 +656,16 @@ value_column_calibrator_util = function(baseline, simulator) {
656656
, default = "default"
657657
, optimized = "current"
658658
)
659-
opt_attempted = simulator$optimization_history$opt_attempted()
660-
if ((value_column_name == "current") & !opt_attempted) {
661-
mp_wrap(
662-
"The model object has not been optimized, and so the default"
663-
, "(non-optimized) parameter set will be used as the baseline."
664-
, "Please either explicitly choose"
665-
, "to use the default set of parameters as the baseline, or optimize"
666-
, "the model object using mp_optimize(model, ...)."
667-
) |> warning()
668-
}
659+
# opt_attempted = simulator$optimization_history$opt_attempted()
660+
# if ((value_column_name == "current") & !opt_attempted) {
661+
# mp_wrap(
662+
# "The model object has not been optimized, and so the default"
663+
# , "(non-optimized) parameter set will be used as the baseline."
664+
# , "Please either explicitly choose"
665+
# , "to use the default set of parameters as the baseline, or optimize"
666+
# , "the model object using mp_optimize(model, ...)."
667+
# ) |> warning()
668+
# }
669669
return(value_column_name)
670670
}
671671

@@ -689,12 +689,14 @@ mp_trajectory_par.TMBCalibrator = function(model, parameter_updates = list()
689689
, baseline = c("recommended", "default", "optimized")
690690
) {
691691
baseline = match.arg(baseline)
692-
model = model$simulator
693-
value_column_name = value_column_calibrator_util(baseline, model)
694-
trajectory_par_util(model
692+
simulator = model$simulator
693+
value_column_name = value_column_calibrator_util(baseline, simulator)
694+
traj = trajectory_par_util(simulator
695695
, parameter_updates, value_column_name
696696
, include_initial, include_final
697697
)
698+
traj$time = model$time_steps_obj$internal_to_external(traj$time)
699+
return(traj)
698700
}
699701

700702
#' @param conf.int Should confidence intervals be produced?

man/mp_sim_bounds.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mp_sim_offset.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/real_data.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ sf_sir = mp_tmb_insert(sf_sir
122122
123123
## at the end (i.e. Infinity) of the expressions evaluated
124124
## 'during' each iteration of the simulation loop ...
125-
, at = Inf
125+
, at = Inf
126126
, phase = "during"
127127
128128
## add a new default value for the reporting probability

0 commit comments

Comments
 (0)