Model Classes

Base CM Model Class

base_model.py

This file contains contains:
- utility functions used often with models
- BaseCMModel class, which other classes inherit from
class epimodel.pymc3_models.base_model.BaseCMModel(*args, **kwargs)

Bases: pymc3.model.Model

BaseCMModel Class.

Other NPI models inherit from this class

build_npi_prior(prior_type, prior_scale=None)

Build NPI Effectiveness Prior.

There are four options: Normal - alpha_i is normally distributed with given scale. Half Normal - alpha_i is half normally distributed with given scale (i.e., restricted to positive effect) Flaxman/ICL prior - As used in Flaxman et al. Skewed - asymmetric laplace prior.

Parameters
  • prior_type – Choose one of normal, half-normal, icl or skewed.

  • prior_scale – Prior scale. Relevant for normal, half-normal and skewed distributions.

property nCMs
Returns

number of countermeasures

property nDs
Returns

number of days

property nRs
Returns

number of regions / countries

plot_effect()

If model.trace has been set, plot the NPI effectiveness estimates.

epimodel.pymc3_models.base_model.add_cms_to_plot(ax, ActiveCMs, country_indx, min_x, max_x, days, plot_style)

Plotter helper.

This takes a plot and adds NPI logos on them.

Parameters
  • ax – axis to draw

  • ActiveCMs – Standard ActiveCMs numpy array

  • country_indx – Country to pull CM data from

  • min_x – x limit - left

  • max_x – x limit - right

  • days – days to plot

  • plot_style – NPI Plot style

epimodel.pymc3_models.base_model.produce_CIs(array)

Produce 95%, 50% Confidence intervals from a Numpy array, taking CIs using the 0th axis.

Parameters

array – Numpy array from which to compute CIs.

Returns

(median, 2.5 percentile, 97.5 percentile, 25th percentile, 75th percentile) tuple.

CM Model Classes

models.py

Contains a variety of models of NPI effectiveness, all subclassed from BaseCMModel.

class epimodel.pymc3_models.models.AdditiveModel(*args, **kwargs)

Bases: epimodel.pymc3_models.base_model.BaseCMModel

build_model(R_prior_mean=3.28, cm_prior_scale=10, gi_mean_mean=5, gi_mean_sd=1, gi_sd_mean=2, gi_sd_sd=2, growth_noise_scale=0.2, deaths_delay_mean_mean=21, deaths_delay_mean_sd=1, deaths_delay_disp_mean=9, deaths_delay_disp_sd=1, cases_delay_mean_mean=10, cases_delay_mean_sd=1, cases_delay_disp_mean=5, cases_delay_disp_sd=1, deaths_truncation=48, cases_truncation=32, **kwargs)

Build NPI effectiveness model :param R_prior_mean: R_0 prior mean :param cm_prior_scale: NPI effectiveness prior scale. For this model, this is the concentration parameter

dirichlet distribution, same for all NPIs.

Parameters
  • gi_mean_mean – mean of normal prior placed over the generation interval mean

  • gi_mean_sd – sd of normal prior placed over the generation interval mean

  • gi_sd_mean – mean of normal prior placed over the generation interval sd

  • gi_sd_sd – sd of normal prior placed over the generation interval sd

  • growth_noise_scale – growth noise scale

  • deaths_delay_mean_mean – mean of normal prior placed over death delay mean

  • deaths_delay_mean_sd – sd of normal prior placed over death delay mean

  • deaths_delay_disp_mean – mean of normal prior placed over death delay dispersion (alpha / psi)

  • deaths_delay_disp_sd – sd of normal prior placed over death delay dispersion (alpha / psi)

  • cases_delay_mean_mean – mean of normal prior placed over cases delay mean

  • cases_delay_mean_sd – sd of normal prior placed over cases delay mean

  • cases_delay_disp_mean – mean of normal prior placed over cases delay dispersion

  • cases_delay_disp_sd – sd of normal prior placed over cases delay dispersion

  • deaths_truncation – maximum death delay

  • cases_truncation – maximum reporting delay

class epimodel.pymc3_models.models.CasesOnlyModel(*args, **kwargs)

Bases: epimodel.pymc3_models.base_model.BaseCMModel

Cases only model.

Identical to the default model, other than modelling only cases.

build_model(R_prior_mean=3.28, cm_prior_scale=10, cm_prior='skewed', gi_mean_mean=5, gi_mean_sd=1, gi_sd_mean=2, gi_sd_sd=2, growth_noise_scale=0.2, cases_delay_mean_mean=10, cases_delay_mean_sd=1, cases_delay_disp_mean=5, cases_delay_disp_sd=1, cases_truncation=32, **kwargs)

Build PyMC3 model.

Parameters
  • R_prior_mean – R_0 prior mean

  • cm_prior_scale – NPI effectiveness prior scale

  • cm_prior – NPI effectiveness prior type. Either ‘normal’, ‘icl’ or skewed (asymmetric laplace)

  • gi_mean_mean – mean of normal prior placed over the generation interval mean

  • gi_mean_sd – sd of normal prior placed over the generation interval mean

  • gi_sd_mean – mean of normal prior placed over the generation interval sd

  • gi_sd_sd – sd of normal prior placed over the generation interval sd

  • growth_noise_scale – growth noise scale

  • cases_delay_mean_mean – mean of normal prior placed over cases delay mean

  • cases_delay_mean_sd – sd of normal prior placed over cases delay mean

  • cases_delay_disp_mean – mean of normal prior placed over cases delay dispersion

  • cases_delay_disp_sd – sd of normal prior placed over cases delay dispersion

  • deaths_truncation – maximum death delay

  • cases_truncation – maximum reporting delay

class epimodel.pymc3_models.models.DeathsOnlyModel(*args, **kwargs)

Bases: epimodel.pymc3_models.base_model.BaseCMModel

Deaths only model.

Identical to the default model, other than modelling only deaths.

build_model(R_prior_mean=3.28, cm_prior_scale=10, cm_prior='skewed', gi_mean_mean=5, gi_mean_sd=1, gi_sd_mean=2, gi_sd_sd=2, growth_noise_scale=0.2, deaths_delay_mean_mean=21, deaths_delay_mean_sd=1, deaths_delay_disp_mean=9, deaths_delay_disp_sd=1, deaths_truncation=48, **kwargs)

Build PyMC3 model.

Parameters
  • R_prior_mean – R_0 prior mean

  • cm_prior_scale – NPI effectiveness prior scale

  • cm_prior – NPI effectiveness prior type. Either ‘normal’, ‘icl’ or skewed (asymmetric laplace)

  • gi_mean_mean – mean of normal prior placed over the generation interval mean

  • gi_mean_sd – sd of normal prior placed over the generation interval mean

  • gi_sd_mean – mean of normal prior placed over the generation interval sd

  • gi_sd_sd – sd of normal prior placed over the generation interval sd

  • growth_noise_scale – growth noise scale

  • deaths_delay_mean_mean – mean of normal prior placed over death delay mean

  • deaths_delay_mean_sd – sd of normal prior placed over death delay mean

  • deaths_delay_disp_mean – mean of normal prior placed over death delay dispersion (alpha / psi)

  • deaths_delay_disp_sd – sd of normal prior placed over death delay dispersion (alpha / psi)

  • deaths_truncation – maximum death delay

class epimodel.pymc3_models.models.DefaultModel(*args, **kwargs)

Bases: epimodel.pymc3_models.base_model.BaseCMModel

Default Model

Default EpidemicForecasting.org NPI effectiveness model. Please see also https://www.medrxiv.org/content/10.1101/2020.05.28.20116129v3

build_model(R_prior_mean=3.28, cm_prior_scale=10, cm_prior='skewed', gi_mean_mean=5, gi_mean_sd=1, gi_sd_mean=2, gi_sd_sd=2, growth_noise_scale=0.2, deaths_delay_mean_mean=21, deaths_delay_mean_sd=1, deaths_delay_disp_mean=9, deaths_delay_disp_sd=1, cases_delay_mean_mean=10, cases_delay_mean_sd=1, cases_delay_disp_mean=5, cases_delay_disp_sd=1, deaths_truncation=48, cases_truncation=32)

Build NPI effectiveness model

Parameters
  • R_prior_mean – R_0 prior mean

  • cm_prior_scale – NPI effectiveness prior scale

  • cm_prior – NPI effectiveness prior type. Either ‘normal’, ‘icl’ or skewed (asymmetric laplace)

  • gi_mean_mean – mean of normal prior placed over the generation interval mean

  • gi_mean_sd – sd of normal prior placed over the generation interval mean

  • gi_sd_mean – mean of normal prior placed over the generation interval sd

  • gi_sd_sd – sd of normal prior placed over the generation interval sd

  • growth_noise_scale – growth noise scale

  • deaths_delay_mean_mean – mean of normal prior placed over death delay mean

  • deaths_delay_mean_sd – sd of normal prior placed over death delay mean

  • deaths_delay_disp_mean – mean of normal prior placed over death delay dispersion (alpha / psi)

  • deaths_delay_disp_sd – sd of normal prior placed over death delay dispersion (alpha / psi)

  • cases_delay_mean_mean – mean of normal prior placed over cases delay mean

  • cases_delay_mean_sd – sd of normal prior placed over cases delay mean

  • cases_delay_disp_mean – mean of normal prior placed over cases delay dispersion

  • cases_delay_disp_sd – sd of normal prior placed over cases delay dispersion

  • deaths_truncation – maximum death delay

  • cases_truncation – maximum reporting delay

class epimodel.pymc3_models.models.DifferentEffectsModel(*args, **kwargs)

Bases: epimodel.pymc3_models.base_model.BaseCMModel

build_model(R_prior_mean=3.28, cm_prior_scale=10, cm_prior='skewed', gi_mean_mean=5, gi_mean_sd=1, gi_sd_mean=2, gi_sd_sd=2, growth_noise_scale=0.2, alpha_noise_scale=0.1, deaths_delay_mean_mean=21, deaths_delay_mean_sd=1, deaths_delay_disp_mean=9, deaths_delay_disp_sd=1, cases_delay_mean_mean=10, cases_delay_mean_sd=1, cases_delay_disp_mean=5, cases_delay_disp_sd=1, deaths_truncation=48, cases_truncation=32, **kwargs)

Build NPI effectiveness model :param R_prior_mean: R_0 prior mean :param cm_prior_scale: NPI effectiveness prior scale. For this model, this is the concentration parameter

dirichlet distribution, same for all NPIs.

Parameters
  • gi_mean_mean – mean of normal prior placed over the generation interval mean

  • gi_mean_sd – sd of normal prior placed over the generation interval mean

  • gi_sd_mean – mean of normal prior placed over the generation interval sd

  • gi_sd_sd – sd of normal prior placed over the generation interval sd

  • growth_noise_scale – growth noise scale

  • deaths_delay_mean_mean – mean of normal prior placed over death delay mean

  • deaths_delay_mean_sd – sd of normal prior placed over death delay mean

  • deaths_delay_disp_mean – mean of normal prior placed over death delay dispersion (alpha / psi)

  • deaths_delay_disp_sd – sd of normal prior placed over death delay dispersion (alpha / psi)

  • cases_delay_mean_mean – mean of normal prior placed over cases delay mean

  • cases_delay_mean_sd – sd of normal prior placed over cases delay mean

  • cases_delay_disp_mean – mean of normal prior placed over cases delay dispersion

  • cases_delay_disp_sd – sd of normal prior placed over cases delay dispersion

  • deaths_truncation – maximum death delay

  • cases_truncation – maximum reporting delay

class epimodel.pymc3_models.models.DiscreteRenewalFixedGIModel(*args, **kwargs)

Bases: epimodel.pymc3_models.base_model.BaseCMModel

Discrete Renewal Model.

This model is the same as the default, but the infection model does not convert R into g using Wallinga, but rather uses a discrete renewal model, adding noise on R.

build_model(R_prior_mean=3.28, cm_prior_scale=10, cm_prior='skewed', R_noise_scale=0.8, deaths_delay_mean_mean=21, deaths_delay_mean_sd=1, deaths_delay_disp_mean=9, deaths_delay_disp_sd=1, cases_delay_mean_mean=10, cases_delay_mean_sd=1, cases_delay_disp_mean=5, cases_delay_disp_sd=1, deaths_truncation=48, cases_truncation=32, gi_truncation=28, conv_padding=7, **kwargs)

Build NPI effectiveness model

Parameters
  • R_prior_mean – R_0 prior mean

  • cm_prior_scale – NPI effectiveness prior scale

  • cm_prior – NPI effectiveness prior type. Either ‘normal’, ‘icl’ or skewed (asymmetric laplace)

  • R_noise_scale – multiplicative noise scale, now placed on R!

  • deaths_delay_mean_mean – mean of normal prior placed over death delay mean

  • deaths_delay_mean_sd – sd of normal prior placed over death delay mean

  • deaths_delay_disp_mean – mean of normal prior placed over death delay dispersion (alpha / psi)

  • deaths_delay_disp_sd – sd of normal prior placed over death delay dispersion (alpha / psi)

  • cases_delay_mean_mean – mean of normal prior placed over cases delay mean

  • cases_delay_mean_sd – sd of normal prior placed over cases delay mean

  • cases_delay_disp_mean – mean of normal prior placed over cases delay dispersion

  • cases_delay_disp_sd – sd of normal prior placed over cases delay dispersion

  • deaths_truncation – maximum death delay

  • cases_truncation – maximum reporting delay

  • gi_truncation – truncation used for generation interval discretisation

  • conv_padding – padding for renewal process

class epimodel.pymc3_models.models.DiscreteRenewalModel(*args, **kwargs)

Bases: epimodel.pymc3_models.base_model.BaseCMModel

Discrete Renewal Model.

This model is the same as the default, but the infection model does not convert R into g using Wallinga, but rather uses a discrete renewal model, adding noise on R.

build_model(R_prior_mean=3.28, cm_prior_scale=10, cm_prior='skewed', gi_mean_mean=5, gi_mean_sd=1, gi_sd_mean=2, gi_sd_sd=2, R_noise_scale=0.8, deaths_delay_mean_mean=21, deaths_delay_mean_sd=1, deaths_delay_disp_mean=9, deaths_delay_disp_sd=1, cases_delay_mean_mean=10, cases_delay_mean_sd=1, cases_delay_disp_mean=5, cases_delay_disp_sd=1, deaths_truncation=48, cases_truncation=32, gi_truncation=28, conv_padding=7, **kwargs)

Build NPI effectiveness model

Parameters
  • R_prior_mean – R_0 prior mean

  • cm_prior_scale – NPI effectiveness prior scale

  • cm_prior – NPI effectiveness prior type. Either ‘normal’, ‘icl’ or skewed (asymmetric laplace)

  • gi_mean_mean – mean of normal prior placed over the generation interval mean

  • gi_mean_sd – sd of normal prior placed over the generation interval mean

  • gi_sd_mean – mean of normal prior placed over the generation interval sd

  • gi_sd_sd – sd of normal prior placed over the generation interval sd

  • R_noise_scale – multiplicative noise scale, now placed on R!

  • deaths_delay_mean_mean – mean of normal prior placed over death delay mean

  • deaths_delay_mean_sd – sd of normal prior placed over death delay mean

  • deaths_delay_disp_mean – mean of normal prior placed over death delay dispersion (alpha / psi)

  • deaths_delay_disp_sd – sd of normal prior placed over death delay dispersion (alpha / psi)

  • cases_delay_mean_mean – mean of normal prior placed over cases delay mean

  • cases_delay_mean_sd – sd of normal prior placed over cases delay mean

  • cases_delay_disp_mean – mean of normal prior placed over cases delay dispersion

  • cases_delay_disp_sd – sd of normal prior placed over cases delay dispersion

  • deaths_truncation – maximum death delay

  • cases_truncation – maximum reporting delay

  • gi_truncation – truncation used for generation interval discretisation

  • conv_padding – padding for renewal process

class epimodel.pymc3_models.models.NoisyRModel(*args, **kwargs)

Bases: epimodel.pymc3_models.base_model.BaseCMModel

Noisy-R Model.

This is the same as the default model, but adds noise to R_t before converting this to the growth rate, g_t. In the default model, noise is added to g_t.

build_model(R_prior_mean=3.28, cm_prior_scale=10, cm_prior='skewed', gi_mean_mean=5, gi_mean_sd=1, gi_sd_mean=2, gi_sd_sd=2, R_noise_scale=0.8, deaths_delay_mean_mean=21, deaths_delay_mean_sd=1, deaths_delay_disp_mean=9, deaths_delay_disp_sd=1, cases_delay_mean_mean=10, cases_delay_mean_sd=1, cases_delay_disp_mean=5, cases_delay_disp_sd=1, deaths_truncation=48, cases_truncation=32, **kwargs)

Build NPI effectiveness model :param R_prior_mean: R_0 prior mean :param cm_prior_scale: NPI effectiveness prior scale :param cm_prior: NPI effectiveness prior type. Either ‘normal’, ‘icl’ or skewed (asymmetric laplace) :param gi_mean_mean: mean of normal prior placed over the generation interval mean :param gi_mean_sd: sd of normal prior placed over the generation interval mean :param gi_sd_mean: mean of normal prior placed over the generation interval sd :param gi_sd_sd: sd of normal prior placed over the generation interval sd :param growth_noise_scale: growth noise scale :param deaths_delay_mean_mean: mean of normal prior placed over death delay mean :param deaths_delay_mean_sd: sd of normal prior placed over death delay mean :param deaths_delay_disp_mean: mean of normal prior placed over death delay dispersion (alpha / psi) :param deaths_delay_disp_sd: sd of normal prior placed over death delay dispersion (alpha / psi) :param cases_delay_mean_mean: mean of normal prior placed over cases delay mean :param cases_delay_mean_sd: sd of normal prior placed over cases delay mean :param cases_delay_disp_mean: mean of normal prior placed over cases delay dispersion :param cases_delay_disp_sd: sd of normal prior placed over cases delay dispersion :param deaths_truncation: maximum death delay :param cases_truncation: maximum reporting delay