Latent#
Hospital Admissions#
- class HospitalAdmissions(infection_to_admission_interval_rv, infection_hospitalization_ratio_rv, day_of_week_effect_rv=None, hospitalization_reporting_ratio_rv=None, obs_data_first_day_of_the_week=0)[source]#
Bases:
RandomVariable
Latent hospital admissions
Implements a renewal process for the expected number of hospital admissions.
Notes
The following text was directly extracted from the wastewater model documentation (link).
Following other semi-mechanistic renewal frameworks, we model the expected hospital admissions per capita \(H(t)\) as a convolution of the expected latent incident infections per capita \(I(t)\), and a discrete infection to hospitalization distribution \(d(\tau)\), scaled by the probability of being hospitalized \(p_\mathrm{hosp}(t)\).
To account for day-of-week effects in hospital reporting, we use an estimated day of the week effect \(\omega(t)\). If \(t\) and \(t'\) are the same day of the week, \(\omega(t) = \omega(t')\). The seven values that \(\omega(t)\) takes on are constrained to have mean 1.
\[H(t) = \omega(t) p_\mathrm{hosp}(t) \sum_{\tau = 0}^{T_d} d(\tau) I(t-\tau)\]Where \(T_d\) is the maximum delay from infection to hospitalization that we consider.
- Parameters:
infection_to_admission_interval_rv (RandomVariable)
infection_hospitalization_ratio_rv (RandomVariable)
day_of_week_effect_rv (RandomVariable | None)
hospitalization_reporting_ratio_rv (RandomVariable | None)
obs_data_first_day_of_the_week (int)
- sample(latent_infections, **kwargs)[source]#
Samples from the observation process
- Parameters:
- Return type:
- static validate(infection_to_admission_interval_rv, infection_hospitalization_ratio_rv, day_of_week_effect_rv, hospitalization_reporting_ratio_rv, obs_data_first_day_of_the_week)[source]#
Validates that the IHR, weekday effects, probability of being reported hospitalized distributions, and infection to hospital admissions reporting delay pmf are RandomVariable types
- Parameters:
infection_to_admission_interval_rv (
Any
) – Possibly incorrect input for the infection to hospitalization interval distribution.infection_hospitalization_ratio_rv (
Any
) – Possibly incorrect input for infection to hospitalization rate distribution.day_of_week_effect_rv (
Any
) – Possibly incorrect input for day of the week effect.hospitalization_reporting_ratio_rv (
Any
) – Possibly incorrect input for distribution or fixed value for the hospital admission reporting probability.obs_data_first_day_of_the_week (
Any
) – Possibly incorrect input for the day of the week that the first day of the observation data corresponds to. Valid values are 0-6, where 0 is Monday and 6 is Sunday.
- Return type:
- Raises:
AssertionError – If any of the random variables are not of the correct type, or if the day of the week is not within the valid range.
- class HospitalAdmissionsSample(infection_hosp_rate=None, latent_hospital_admissions=None, multiplier=None)[source]#
Bases:
NamedTuple
A container to hold the output of
HospitalAdmissions.sample()
.- Parameters:
infection_hosp_rate (ArrayLike | None)
latent_hospital_admissions (ArrayLike | None)
multiplier (ArrayLike | None)
- infection_hosp_rate#
The infection-to-hospitalization rate. Defaults to None.
- Type:
ArrayLike
, optional
- latent_hospital_admissions#
The computed number of hospital admissions. Defaults to None.
- multiplier#
The day of the week effect multiplier. Defaults to None. It should match the number of timepoints in the latent hospital admissions.
- infection_hosp_rate: ArrayLike | None#
Alias for field number 0
- latent_hospital_admissions: ArrayLike | None#
Alias for field number 1
- multiplier: ArrayLike | None#
Alias for field number 2
Infections#
- class Infections(**kwargs)[source]#
Bases:
RandomVariable
Latent infections
This class samples infections given \(\mathcal{R}(t)\), initial infections, and generation interval.
Notes
The mathematical model is given by:
\[I(t) = R(t) \times \sum_{\tau < t} I(\tau) g(t-\tau)\]where \(I(t)\) is the number of infections at time \(t\), \(R(t)\) is the reproduction number at time \(t\), and \(g(t-\tau)\) is the generation interval.
- sample(Rt, I0, gen_int, **kwargs)[source]#
Sample infections given \(\mathcal{R}(t)\), initial infections, and generation interval.
- Parameters:
Rt (
ArrayLike
) – Reproduction number.I0 (
ArrayLike
) – Initial infections vector of the same length as the generation interval.gen_int (
ArrayLike
) – Generation interval pmf vector.**kwargs (
dict
, optional) – Additional keyword arguments passed through to internal sample calls, should there be any.
- Returns:
A named tuple with a
post_initialization_infections
field.- Return type:
- class InfectionsSample(post_initialization_infections=None)[source]#
Bases:
NamedTuple
A container for holding the output from
Infections.sample()
.- Parameters:
post_initialization_infections (ArrayLike | None)
- post_initialization_infections: ArrayLike | None#
Alias for field number 0
Infection Functions#
- compute_infections_from_rt(I0, Rt, reversed_generation_interval_pmf)[source]#
Generate infections according to a renewal process with a time-varying reproduction number \(\mathcal{R}(t)\)
- Parameters:
I0 (
ArrayLike
) – Array of initial infections of the same length as the generation interval pmf vector.Rt (
ArrayLike
) – Timeseries of \(\mathcal{R}(t)\) valuesreversed_generation_interval_pmf (
ArrayLike
) – discrete probability mass vector representing the generation interval of the infection process, where the final entry represents an infection 1 time unit in the past, the second-to-last entry represents an infection two time units in the past, etc.
- Returns:
The timeseries of infections.
- Return type:
jnp.ndarray
- compute_infections_from_rt_with_feedback(I0, Rt_raw, infection_feedback_strength, reversed_generation_interval_pmf, reversed_infection_feedback_pmf)[source]#
Generate infections according to a renewal process with infection feedback (generalizing Asher 2018).
- Parameters:
I0 (
ArrayLike
) – Array of initial infections of the same length as the generation interval pmf vector.Rt_raw (
ArrayLike
) – Timeseries of raw \(\mathcal{R}(t)\) values not adjusted by infection feedbackinfection_feedback_strength (
ArrayLike
) – Strength of the infection feedback. Either a scalar (constant feedback strength in time) or a vector representing the infection feedback strength at a given point in time.reversed_generation_interval_pmf (
ArrayLike
) – discrete probability mass vector representing the generation interval of the infection process, where the final entry represents an infection 1 time unit in the past, the second-to-last entry represents an infection two time units in the past, etc.reversed_infection_feedback_pmf (
ArrayLike
) – discrete probability mass vector representing the infection feedback process, where the final entry represents the relative contribution to infection feedback from infections that occurred 1 time unit in the past, the second-to-last entry represents the contribution from infections that occurred 2 time units in the past, etc.
- Returns:
A tuple
(infections, Rt_adjusted)
, whereRt_adjusted
is the infection-feedback-adjusted timeseries of the reproduction number \(\mathcal{R}(t)\) andinfections
is the incident infection timeseries.- Return type:
Notes
This function implements the following renewal process:
\[\begin{aligned} I(t) & = \mathcal{R}(t)\sum_{\tau=1}^{T_g}I(t - \tau)g(\tau) \\ \mathcal{R}(t) & = \mathcal{R}^u(t)\exp\left(\gamma(t)\ \sum_{\tau=1}^{T_f}I(t - \tau)f(\tau)\right) \end{aligned} \]where \(\mathcal{R}(t)\) is the reproductive number, \(\gamma(t)\) is the infection feedback strength, \(T_g\) is the max-length of the generation interval, \(\mathcal{R}^u(t)\) is the raw reproduction number, \(f(t)\) is the infection feedback pmf, and \(T_f\) is the max-length of the infection feedback pmf.
Note that negative \(\gamma(t)\) implies that recent incident infections reduce \(\mathcal{R}(t)\) below its raw value in the absence of feedback, while positive \(\gamma\) implies that recent incident infections increase \(\mathcal{R}(t)\) above its raw value, and \(\gamma(t)=0\) implies no feedback.
In general, negative \(\gamma\) is the more common modeling choice, as it can be used to model susceptible depletion, reductions in contact rate due to awareness of high incidence, et cetera.
- logistic_susceptibility_adjustment(I_raw_t, frac_susceptible, n_population)[source]#
Apply the logistic susceptibility adjustment to a potential new incidence
I_raw_t
proposed in equation 6 of Bhatt et al 2023.- Parameters:
- Returns:
The adjusted value of \(I(t)\).
- Return type:
Infection Initialization Process#
- class InfectionInitializationProcess(name, I_pre_init_rv, infection_init_method)[source]#
Bases:
RandomVariable
Generate an initial infection history
- Parameters:
I_pre_init_rv (RandomVariable)
infection_init_method (InfectionInitializationMethod)
- sample()[source]#
Sample the Infection Initialization Process.
- Returns:
the number of initialized infections at each time point.
- Return type:
- static validate(I_pre_init_rv, infection_init_method)[source]#
Validate the input arguments to the InfectionInitializationProcess class constructor
- Parameters:
I_pre_init_rv (
RandomVariable
) – A random variable representing the number of infections that occur at some time before the renewal process begins.infection_init_method (
InfectionInitializationMethod
) – An method to generate the initial infections.
- Return type:
Infection Initialization Method#
- class InfectionInitializationMethod(n_timepoints)[source]#
Bases:
object
Method for initializing infections in a renewal process.
- Parameters:
n_timepoints (int)
- abstract initialize_infections(I_pre_init)[source]#
Generate the number of initialized infections at each time point.
- static validate(n_timepoints)[source]#
Validate inputs to the
InfectionInitializationMethod
constructor.
- class InitializeInfectionsExponentialGrowth(n_timepoints, rate_rv, t_pre_init=None)[source]#
Bases:
InfectionInitializationMethod
Generate initial infections according to exponential growth.
Notes
The number of incident infections at time t is given by:
\[I(t) = I_p \exp \left( r (t - t_p) \right) \]Where \(I_p\) is
I_pre_init
, \(r\) israte
, and \(t_p\) ist_pre_init
. This ensures that \(I(t_p) = I_p\). We default tot_pre_init = n_timepoints - 1
, so thatI_pre_init
represents the number of incident infections immediately before the renewal process begins.- Parameters:
n_timepoints (int)
rate_rv (RandomVariable)
t_pre_init (int | None)
- class InitializeInfectionsFromVec(n_timepoints)[source]#
Bases:
InfectionInitializationMethod
Create initial infections from a vector of infections.
- Parameters:
n_timepoints (int)
- class InitializeInfectionsZeroPad(n_timepoints)[source]#
Bases:
InfectionInitializationMethod
Create an initial infection vector of specified length by padding a shorter vector with an appropriate number of zeros at the beginning of the time series.
- Parameters:
n_timepoints (int)