R/odin.R

Defines functions odin_model_stoch odin_model_determ

## Automatically generated by odin 1.3.6 - do not edit
odin_model_determ_ <- R6::R6Class(
  "odin_model",
  cloneable = FALSE,

  private = list(
    ptr = NULL,
    use_dde = NULL,

    odin = NULL,
    variable_order = NULL,
    output_order = NULL,
    n_out = NULL,
    ynames = NULL,
    interpolate_t = NULL,
    cfuns = list(
      rhs_dde = "odin_model_determ_rhs_dde"),
    dll = "ZikaModel",
    user = c("age_per", "agec", "amplitudes_phases", "Beta_hm_1",
             "Beta_mh_1", "BG_FOI", "deathrt", "Delta_season", "DeltaBase",
             "DT", "eip_mean", "eip_season", "Epsilon", "incub", "inf_per",
             "init_I1", "init_R1", "init_S", "Kappa", "Kc_season", "Mwt_cv",
             "Mwt_mean", "N_eq", "na", "Nb", "nn", "NP", "nu", "Omega",
             "phi1", "pi", "propMwtControl", "propTransGlobal",
             "propTransNN", "rho1", "Rm", "Sigma", "TimeMwtControlOff",
             "TimeMwtControlOn", "vacc_child_age", "vacc_child_coverage",
             "vacc_child_starttime", "vacc_child_stoptime", "vacc_cu_age",
             "vacc_cu_coverage", "vacc_cu_rndtime", "Wb_cyto", "Wb_fF",
             "Wb_fM", "Wb_introduration", "Wb_introlevel", "Wb_introtime",
             "Wb_mat", "Wb_relinf1", "Wb_relsusc1", "YL"),

    ## This is never called, but is used to ensure that R finds our
    ## symbols that we will use from the package; without this they
    ## cannot be found by dynamic lookup now that we use the package
    ## FFI registration system.
    registration = function() {
      if (FALSE) {
        .C("odin_model_determ_rhs_dde", package = "ZikaModel")
      }
    },

    ## This only does something in delay models
    set_initial = function(step, y, use_dde) {
      .Call("odin_model_determ_set_initial", private$ptr, step, y, use_dde,
            PACKAGE= "ZikaModel")
    },

    update_metadata = function() {
      meta <- .Call("odin_model_determ_metadata", private$ptr,
                    PACKAGE = "ZikaModel")
      private$variable_order <- meta$variable_order
      private$output_order <- meta$output_order
      private$n_out <- meta$n_out
      private$ynames <- private$odin$make_names(
        private$variable_order, private$output_order, TRUE)
      private$interpolate_t <- meta$interpolate_t
    }
  ),

  public = list(
    initialize = function(..., user = list(...), use_dde = FALSE,
                          unused_user_action = NULL) {
      private$odin <- asNamespace("odin")
      private$ptr <- .Call("odin_model_determ_create", user, PACKAGE = "ZikaModel")
      self$set_user(user = user, unused_user_action = unused_user_action)
      private$use_dde <- use_dde
      private$update_metadata()
    },

    ir = function() {
      path_ir <- system.file("odin/odin_model_determ.json", mustWork = TRUE,
                             package = "ZikaModel")
      json <- readLines(path_ir)
      class(json) <- "json"
      json
    },

    ## Do we need to have the user-settable args here? It would be
    ## nice, but that's not super straightforward to do.
    set_user = function(..., user = list(...), unused_user_action = NULL) {
      private$odin$support_check_user(user, private$user, unused_user_action)
      .Call("odin_model_determ_set_user", private$ptr, user, PACKAGE = "ZikaModel")
      private$update_metadata()
    },

    ## This might be time sensitive and, so we can avoid computing
    ## it. I wonder if that's an optimisation we should drop for now
    ## as it does not seem generally useful. This would bring us
    ## closer to the js version which requires that we always pass the
    ## time in.
    initial = function(step) {
      .Call("odin_model_determ_initial_conditions", private$ptr, step, PACKAGE = "ZikaModel")
    },

    rhs = function(step, y) {
      .Call("odin_model_determ_rhs_r", private$ptr, step, y, PACKAGE = "ZikaModel")
    },

    update = function(step, y) {
      self$rhs(step, y)
    },

    contents = function() {
      .Call("odin_model_determ_contents", private$ptr, PACKAGE = "ZikaModel")
    },

    transform_variables = function(y) {
      private$odin$support_transform_variables(y, private)
    },

    engine = function() {
      "c"
    },

    run = function(step, y = NULL, ..., use_names = TRUE) {
      private$odin$wrapper_run_discrete(
        self, private, step, y, ..., use_names = use_names)
    }
  ))


odin_model_determ <- function(..., user = list(...), use_dde = FALSE,
                     unused_user_action = NULL) {
  asNamespace("odin")$deprecated_constructor_call("odin_model_determ")
  odin_model_determ_$new(user = user, use_dde = use_dde,
                unused_user_action = unused_user_action)
}
class(odin_model_determ) <- "odin_generator"
attr(odin_model_determ, "generator") <- odin_model_determ_
odin_model_stoch_ <- R6::R6Class(
  "odin_model",
  cloneable = FALSE,

  private = list(
    ptr = NULL,
    use_dde = NULL,

    odin = NULL,
    variable_order = NULL,
    output_order = NULL,
    n_out = NULL,
    ynames = NULL,
    interpolate_t = NULL,
    cfuns = list(
      rhs_dde = "odin_model_stoch_rhs_dde"),
    dll = "ZikaModel",
    user = c("age_per", "agec", "Beta_hm_1", "Beta_mh_1", "BG_FOI",
             "deathrt", "Delta_season", "DeltaBase", "DT", "eip_mean",
             "eip_season", "Epsilon", "incub", "inf_per", "init_I1",
             "init_R1", "init_S", "Kappa", "Kc_season", "Mwt", "Mwt_mean",
             "N_eq", "na", "Nb", "nn", "NP", "nu", "Omega", "phi1", "pi",
             "propMwtControl", "propTransGlobal", "propTransNN", "rho1",
             "Rm", "season_amp", "season_phase", "Sigma",
             "TimeMwtControlOff", "TimeMwtControlOn", "Wb_cyto", "Wb_fF",
             "Wb_mat", "Wb_relinf1", "YL"),

    ## This is never called, but is used to ensure that R finds our
    ## symbols that we will use from the package; without this they
    ## cannot be found by dynamic lookup now that we use the package
    ## FFI registration system.
    registration = function() {
      if (FALSE) {
        .C("odin_model_stoch_rhs_dde", package = "ZikaModel")
      }
    },

    ## This only does something in delay models
    set_initial = function(step, y, use_dde) {
      .Call("odin_model_stoch_set_initial", private$ptr, step, y, use_dde,
            PACKAGE= "ZikaModel")
    },

    update_metadata = function() {
      meta <- .Call("odin_model_stoch_metadata", private$ptr,
                    PACKAGE = "ZikaModel")
      private$variable_order <- meta$variable_order
      private$output_order <- meta$output_order
      private$n_out <- meta$n_out
      private$ynames <- private$odin$make_names(
        private$variable_order, private$output_order, TRUE)
      private$interpolate_t <- meta$interpolate_t
    }
  ),

  public = list(
    initialize = function(..., user = list(...), use_dde = FALSE,
                          unused_user_action = NULL) {
      private$odin <- asNamespace("odin")
      private$ptr <- .Call("odin_model_stoch_create", user, PACKAGE = "ZikaModel")
      self$set_user(user = user, unused_user_action = unused_user_action)
      private$use_dde <- use_dde
      private$update_metadata()
    },

    ir = function() {
      path_ir <- system.file("odin/odin_model_stoch.json", mustWork = TRUE,
                             package = "ZikaModel")
      json <- readLines(path_ir)
      class(json) <- "json"
      json
    },

    ## Do we need to have the user-settable args here? It would be
    ## nice, but that's not super straightforward to do.
    set_user = function(..., user = list(...), unused_user_action = NULL) {
      private$odin$support_check_user(user, private$user, unused_user_action)
      .Call("odin_model_stoch_set_user", private$ptr, user, PACKAGE = "ZikaModel")
      private$update_metadata()
    },

    ## This might be time sensitive and, so we can avoid computing
    ## it. I wonder if that's an optimisation we should drop for now
    ## as it does not seem generally useful. This would bring us
    ## closer to the js version which requires that we always pass the
    ## time in.
    initial = function(step) {
      .Call("odin_model_stoch_initial_conditions", private$ptr, step, PACKAGE = "ZikaModel")
    },

    rhs = function(step, y) {
      .Call("odin_model_stoch_rhs_r", private$ptr, step, y, PACKAGE = "ZikaModel")
    },

    update = function(step, y) {
      self$rhs(step, y)
    },

    contents = function() {
      .Call("odin_model_stoch_contents", private$ptr, PACKAGE = "ZikaModel")
    },

    transform_variables = function(y) {
      private$odin$support_transform_variables(y, private)
    },

    engine = function() {
      "c"
    },

    run = function(step, y = NULL, ..., use_names = TRUE) {
      private$odin$wrapper_run_discrete(
        self, private, step, y, ..., use_names = use_names)
    }
  ))


odin_model_stoch <- function(..., user = list(...), use_dde = FALSE,
                     unused_user_action = NULL) {
  asNamespace("odin")$deprecated_constructor_call("odin_model_stoch")
  odin_model_stoch_$new(user = user, use_dde = use_dde,
                unused_user_action = unused_user_action)
}
class(odin_model_stoch) <- "odin_generator"
attr(odin_model_stoch, "generator") <- odin_model_stoch_
mrc-ide/ZikaModel documentation built on Sept. 14, 2022, 8:51 a.m.