Skip to content

Commit 0d068f5

Browse files
authoredAug 12, 2021
R meta model (beta) (#218)
First cut of metaamodel in R First cut of MetaModel implemented in R. Separate instances of OpenABM are run for each of n_regions in up to n_nodes separate R sessions (using R package parallel). New infections are seeded in each region based upon the migration_matrix and the number of new infections in each region. Migration seed infections occur at a delayed time (default 5 days) after the new infections occur in the linked region (note this delay is also the frequency at which the parallel processes must talk to each other). Most key model features (updating params, seeding new variants, results ) can be set globally or at a sub-model level. The MetaModel also includes a plot() method for generating movies of spread of infections (using plotly). 2 example MetaModel are added as examples: a rectangle with nearest neighbour migration and a model of England (at UTLA level) using mobile telephone data to estimate migration. * In Model move main part of one_time_step() to a private function and return the precalculated value Fix tests * Add time and one_time_step_results to MetaModel * Extend run() to return the total number infected of the run period in MetaModel * Add case migration between regions * First cut of update_running_params in MetaModel * migration_infect_run -> combine_run * Add add_new_strain to MetaModel * Make migration_infect strain aware * Make migration_infect strain aware * Add total_infected to the Strain object * Return new infections by strain from run in MetaModel * Expose set_cross_immuniy_matrix on the MetaModel * Add total_infected by strain to Model Add strain objects as well since used repeatedly * Add total_infected to MetaModel * Add set_network_transmission_multiplie to MetaModel * First cut of a MetaModel for England Add processed data, intitialisation and plotting * First cut of a MetaModel for England Add processed data, intitialisation and plotting * trans_matrix -> migration_matrix * Add migration data on initialisation * Drop loop over seeding infection to C Add data storage for migration model to MetaModel * In MetaModel re-route run() through combine_run() to unify code paths * Return total_infected for each time step when stepping Keep running totals on the MetaModel object for direct accees in migration calculations * Add migrating infections to run in MetaModel Migration infections are with a lag of migration_delay and are according to the migration_matrix * Use random rounding when calculating seed cases for migration Fix plot on MetaModel to work if no map data is given * Use random rounding when calculating seed cases for migration Fix plot on MetaModel to work if no map data is given * In MetaModel$plot add option of total or new infected * Add MetaModels for England and a rectangle * First cut of metaamodel in R * In Model move main part of one_time_step() to a private function and return the precalculated value Fix tests * Add time and one_time_step_results to MetaModel * Extend run() to return the total number infected of the run period in MetaModel * Add case migration between regions * First cut of update_running_params in MetaModel * migration_infect_run -> combine_run * Add add_new_strain to MetaModel * Make migration_infect strain aware * Make migration_infect strain aware * Add total_infected to the Strain object * Return new infections by strain from run in MetaModel * Expose set_cross_immuniy_matrix on the MetaModel * Add total_infected by strain to Model Add strain objects as well since used repeatedly * Add total_infected to MetaModel * Add set_network_transmission_multiplie to MetaModel * First cut of a MetaModel for England Add processed data, intitialisation and plotting * First cut of a MetaModel for England Add processed data, intitialisation and plotting * trans_matrix -> migration_matrix * Add migration data on initialisation * Drop loop over seeding infection to C Add data storage for migration model to MetaModel * In MetaModel re-route run() through combine_run() to unify code paths * Return total_infected for each time step when stepping Keep running totals on the MetaModel object for direct accees in migration calculations * Add migrating infections to run in MetaModel Migration infections are with a lag of migration_delay and are according to the migration_matrix * Use random rounding when calculating seed cases for migration Fix plot on MetaModel to work if no map data is given * Use random rounding when calculating seed cases for migration Fix plot on MetaModel to work if no map data is given * In MetaModel$plot add option of total or new infected * Add MetaModels for England and a rectangle
1 parent a316c7f commit 0d068f5

18 files changed

+69414
-91
lines changed
 

‎.Rbuildignore

+1
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ tags$
5555
^documentation$
5656
^src\/Makefile$
5757
^src\/main\.c$
58+
^R\MetaModelUtils\*

‎DESCRIPTION

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ Description:
5151
configuration of digital contract-tracing mobile phone apps.
5252
Robert Hinch, William J M Probert, et al. (2020) <doi:10.1101/2020.09.16.20195925>.
5353
Depends: R6
54-
Imports: methods, xptr
54+
Imports: methods, xptr, parallel, data.table, plotly, stringr
5555
Collate:
5656
OpenABMCovid19.R
5757
util.R
5858
Parameters.R
5959
Network.R
6060
Model.R
61+
MetaModel.R
6162
Simulation.R
6263
Strain.R
6364
VaccineSchedule.R

‎NAMESPACE

+21
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ importFrom("methods", "setClass")
66
importFrom("methods", "slot")
77
importFrom("R6", "R6Class")
88
importFrom("xptr", "is_null_xptr")
9+
importFrom("parallel", "makeCluster")
10+
importFrom("parallel", "stopCluster")
11+
importFrom("parallel", "clusterApply")
12+
importFrom("parallel", "detectCores")
13+
import("data.table")
14+
importFrom( "plotly", "plot_ly" )
15+
importFrom( "plotly", "layout" )
16+
importFrom( "plotly", "animation_opts" )
17+
importFrom( "plotly", "colorbar" )
18+
importFrom( "plotly", "%>%" )
19+
importFrom( "stringr", "str_replace_all")
920

1021
# R6 Classes
1122
export("Parameters")
@@ -18,6 +29,7 @@ export("Strain")
1829
export("COVID19IBM")
1930
export("VaccineSchedule")
2031
export("Vaccine")
32+
export("MetaModel")
2133

2234
# wrapper function for R6 calsses
2335
export("Parameters.new")
@@ -32,11 +44,20 @@ export("Model.get_param")
3244
export("Model.update_running_params")
3345
export("Model.get_transmissions")
3446

47+
# MetaModel
48+
export( "MetaModel.rectangle")
49+
export( "MetaModel.England")
50+
3551
# Enums
3652
export("AgeGroupEnum")
3753
export("SAFE_UPDATE_PARAMS")
3854
export("NETWORK_CONSTRUCTIONS")
3955
export("VACCINE_TYPES")
4056
export("VACCINE_STATUS")
4157

58+
# constants
59+
export("plot.value.total_infected")
60+
export("plot.value.new_infected")
61+
export("plot.values")
62+
4263
useDynLib(OpenABMCovid19, .registration = TRUE)

0 commit comments

Comments
 (0)