chrism0dwk / covid19uk

MIT License
11 stars 10 forks source link

Porting the model in R #6

Closed claudiofronterre closed 4 years ago

claudiofronterre commented 4 years ago

I am using the reticulate package that allows you call Python from R. This is how the first part of covid_ode.py looks like in R:

library(reticulate)
covid <- import("covid")
config <- yaml::read_yaml("ode_config.yaml")

# Load age mixing 
K_tt <- readRDS(config$data$age_mixing_matrix_term)

# Load age mixing holiday
K_hh <- readRDS(config$data$age_mixing_matrix_hol)

# Load mobility matrix 
Tmat <- readRDS(config$data$mobility_matrix)
diag(Tmat) <- 0 

N <- readRDS(config$data$population_size)

param <- config$parameter
settings <- covid$util$sanitise_settings(config$settings)

model <- covid$model$CovidUKODE(K_tt, K_hh, Tmat, N, 
                                settings$start, settings$end, settings$holiday,
                                settings$bg_max_time, 1)

Note that it won't run because there are no start and end settings in the ode_config.yaml.

A function like mcmc.py can be run from R as simply as:

source_python("mcmc.py")

It would be useful to have a chat to know what arguments would you like to have in a R wrapper for each of the main functions.

chrism0dwk commented 4 years ago

@claudiofronterre fast moving model-building, I'm afraid! The interface to CovidUKODE has changed due to increasing bits of data. Changes merged into master in dcc463bd.

       """Represents a CovidUK ODE model
        :param M_tt: a MxM matrix of age group mixing in term time
        :param M_hh: a MxM matrix of age group mixing in holiday time
        :param W: Commuting volume
        :param C: a n_ladsxn_lads matrix of inter-LAD commuting
        :param N: a vector of population sizes in each LAD
        :param date_range: a time range [start, end)
        :param holidays: a list of length-2 tuples containing dates of holidays
        :param lockdown: a length-2 tuple of start and end of lockdown measures
        :param time_step: a time step to use in the discrete time simulation
        """

Be aware also that the CovidUKODE model now inherits from CovidUK (there's a stochastic version of the model in the brewing).