Reference: Models¶
-
class
pydemic.models.seirpp.NonMarkovianSEIRSimulationBase(total_population, age_distribution=1, *, r0=3.2, serial_dist=<GammaDistribution(shape=1.51, scale=2.64)>, mitigation=None, hetero_lambda=1.0, severity_profiles=None, seasonal_forcing_amp=0.2, peak_day=15)[source]¶ Main driver for non-Markovian simulations, used as a base class for SEIR++ variants.
The following arguments are required:
- Parameters
total_population – The total size of the population.
The following keyword-only arguments are recognized:
- Parameters
age_distribution – A
numpy.ndarrayspecifying the relative fraction of the population in various age groups. Defaults to1, i.e., no age grouping.mitigation – A function of time specifying a multiplicative factor. Defaults to
lambda t: 1.r0 – The basic reproduction number.
serial_dist – The serial interval distribution, i.e., an instance of (a subclass of)
DistributionBase).hetero_lambda – The depletion coefficient that scales the effect changes in the susceptible population fraction have on infectivity. Defaults to
1.seasonal_forcing_amp – The amplitude (i.e., maximum fractional change) in the force of infection due to seasonal effects.
peak_day – The day of the year at which seasonal forcing is greatest.
-
__call__(tspan, y0, dt=0.05)[source]¶ - Parameters
tspan – A
tuplespecifying the initiala and final times (aspandas.Timestamp’s or asfloat’s specifying the number of days since Jan 1, 2020).y0 – A
dictwith the initial values (asnumpy.ndarray’s) for the'infected'and'susceptible'states.dt – The timestep.
- Returns
A
SimulationResultwith attributest, the array of times of evaluation, andy, adictof results where time proceeds along the first axis.
-
classmethod
get_model_data(t, **kwargs)[source]¶ A wrapper to
__init__()and__call__()for initializing and running a simulation from keyword arguments only (i.e., as used byLikelihoodEstimator.)- Parameters
t – A
pandas.DatetimeIndex(ornumpy.ndarrayof times in days since 2020/1/1) of times at which to evaluate the solution.
The following keyword arguments are required:
- Parameters
start_day – The day (relative to 2020/1/1) at which to begin the simulation—i.e., the day corresponding to the initial condition where
initial_casescases (evenly distributed overage_distribution) are introduced into the population.total_population – The total size of the population.
initial_cases – The total numnber of initial cases.
age_distribution – A
numpy.ndarrayspecifying the relative fraction of the population in various age groups.
In addition, a
MitigationModelis created from passed keyword arguments viainit_from_kwargs().The following optional keyword arguments are also recognized:
- Parameters
min_mitigation_spacing – The minimum number of days of separation between mitigation events. Defaults to
5.
All remaining keyword arguments are passed to
__init__().- Raises
InvalidParametersError – if
tspecifies any days of evaluation which are not at least one day afterstart_day.InvalidParametersError – if mitigation events are not ordered and separated by
min_mitigation_spacing.
- Returns
A
pandas.DataFrameof simulation results.
-
class
pydemic.models.SEIRPlusPlusSimulation(total_population, age_distribution=1, *, r0=3.2, serial_dist=<GammaDistribution(shape=1.51, scale=2.64)>, mitigation=None, hetero_lambda=1.0, severity_profiles=None, seasonal_forcing_amp=0.2, peak_day=15, ifr=None, incubation_dist=<GammaDistribution(shape=7.56, scale=0.727)>, p_symptomatic=1.0, p_positive=1.0, hospitalized_dist=<GammaDistribution(shape=2.64, scale=2.46)>, p_hospitalized=1.0, discharged_dist=<GammaDistribution(shape=2.25, scale=2.67)>, critical_dist=<GammaDistribution(shape=1, scale=2)>, p_critical=1.0, dead_dist=<GammaDistribution(shape=1, scale=7.5)>, p_dead=1.0, recovered_dist=<GammaDistribution(shape=1, scale=7.5)>, all_dead_dist=<GammaDistribution(shape=1, scale=2.5)>, all_dead_multiplier=1.0)[source]¶ SEIR++ model with unconnected infectivity loop. Readout topology is:
-> symptomatic -> hospitalized -> recovered -> critical -> dead -> all_dead -> hospitalized -> recovered
In addition to the arguments recognized by
NonMarkovianSEIRSimulationBase, the following keyword-only arguments are recognized:- Parameters
age_distribution – A
numpy.ndarrayspecifying the relative fraction of the population in various age groups.ifr – The infection fatality ratio, i.e., the proportion of the infected population who eventually die. If not None, will rescale
p_symptomaticto effect the passed value.p_symptomatic – The distribution of the proportion of infected individuals who become symptomatic.
incubation_dist – The delay-time distribution for developing symptoms after being infected.
p_positive – The fraction of symptomatic individuals who are tested and test positive.
p_hospitalized – The distribution of the proportion of symptomatic individuals who enter the hospital.
hospitalized_dist – The delay-time distribution of entering the hospital after becoming symptomatic.
discharged_dist – The delay-time distribution of survivors being discharged after entering the hospital.
p_critical – The distribution of the proportion of hospitalized individuals who become critical.
critical_dist – The delay-time distribution of hospitalized individuals entering the ICU.
p_dead – The distribution of the proportion of ICU patients who die.
dead_dist – The delay-time distribution of ICU patients dying.
recovered_dist – The delay-time distribution of ICU patients recovering and returning to the general ward.
all_dead_multiplier – The ratio of total deaths to deaths occurring in the ICU.
all_dead_dist – The delay-time distribution between ICU deaths and all reported deaths.
Other utilities for modeling¶
-
class
pydemic.distributions.DistributionBase[source]¶ Base class for distributions.
-
convolve_pdf(t, influx, prefactor=1, profile=None, method='fft', complement=False)[source]¶ Convolves an array
influxwith the PDF of the distribution.- Parameters
t – The times of evaluation.
influx – The array to be convolved, \(y\).
prefactor – A multiplicative prefactor, \(P\).
method – A
strspecifying whether to convolve by Fast Fourier Transform ('fft') or via direct covolution ('direct').
-
convolve_survival(t, influx, prefactor=1, method='fft')[source]¶ Convolves an array
influxwith the survival function of the distribution,\[S(x) = 1 - \int \mathrm{d} x' \, f(x').\]- Parameters
t – The times of evaluation.
influx – The array to be convolved.
prefactor – A multiplicative prefactor.
method – A
strspecifying whether to convolve by Fast Fourier Transform ('fft') or via direct covolution ('direct').
-
-
class
pydemic.GammaDistribution(mean=None, std=None, shape=None, scale=None)[source]¶ Implements functionality for the gamma distribution, with PDF
\[f(x) = \frac{1}{\Gamma(k) \theta^{k}} x^{k-1} e^{- x / \theta }\]One can specify the distribution by its mean \(\mu\) and standard deviation \(\sigma\) or by the standard shape and scale parameters \(k\) and \(\theta\), which are related by
\[ \begin{align}\begin{aligned}k = \frac{\mu^2}{\sigma^2}\\\theta = \frac{\sigma^2}{\mu}.\end{aligned}\end{align} \]- Parameters
mean – The mean, \(\mu\).
std – The standard derviation, \(\sigma\).
shape – The shape, \(k\).
scale – The scale, \(\theta\).
Passed values for
meanandstdtake precendece over those forshapeandscale.
-
class
pydemic.MitigationModel(t0, tf, t, factors, multiplier=None)[source]¶ An interface for creating (smooth, monotonic) piecewise linear functions. Subclasses
scipy.interpolate.PchipInterpolator.Constructs the interpolating function which takes the constant values
factors[0]betweent0andt[0]andfactors[-1]betweent[-1]andtf.- Parameters
t0 – A
floatrepresenting the first input value for interpolation.tf – A
floatrepresenting the last input value for interpolation.t – A
numpy.ndarrayof interpolating nodes (betweent0andtf).factors – A
numpy.ndarrayof function values to interpolate to at the nodest.