EpiModel / EpiModel-Gallery

Gallery of Network-Based Epidemic Model Templates for EpiModel
http://epimodel.org
MIT License
52 stars 31 forks source link

Custom initialization modules #22

Closed andsv2 closed 2 years ago

andsv2 commented 4 years ago

With the update to the Gallery Examples to be inline with EpiModel2.0, I noticed that a lot of the bespoke modules (particularly infection modules) placed initialization of attributes within the actual epidemic modules. For example, in the CompetingStrains gallery example, strain attribute is initialized in the recovery.FUN = recov.2strains:

recov.2strains <- function(dat, at) {
  ##  ----------------------- ##
  if (at == 2) {
    nActive <- length(active)
    strain <- rep(NA, nActive)
    strain[idsInf] <- rbinom(nElig, 1, pct.st2) + 1  # Strains are labeled 1 and 2
    dat <- set_attr(dat, "strain", strain)
  ## ------------------------ ##
  }

This is not neccessarrily an issue in this case, however, because of the new behavior of the control.net parameter type, other more commonly used attributes - such as infTime - also need to be moved into these modules.

Would it make more sense to have a separate init.FUN = init_model to handle this initialization step to both make the code cleaner and more flexible (module.order must be explicitly stated which may not match the intended epidemic progression of the example) as well as makingit clear to the end user how their own code should be set up?

smjenness commented 4 years ago

Thanks @andsv2 . I think this issue may be related to and solved by this suggestion: https://github.com/statnet/EpiModel/issues/385

I'd like to ask @adrienleguillou to work with you on completing and testing this after EpiModel 2.0 is released. It should be backwards compatible with EpiModel 2.0, with netsim either accepting {est, param, init, control} or {initialized dat object}. Please continue further discussion about that over on the EpiModel issue...

andsv2 commented 4 years ago

Closing for now until post EpiModel2 work.

AdrienLeGuillou commented 4 years ago

Maybe leave it open with a "post 2.0" label? So we don't forget about it