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:
sample(latent_infections, **kwargs)[source]#

Samples from the observation process

Parameters:
  • latent_infections (ArrayLike) – Latent infections.

  • **kwargs (dict, optional) – Additional keyword arguments passed through to internal sample() calls, should there be any.

Return type:

HospitalAdmissionsSample

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:

None

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.

Type:

ArrayLike or None

multiplier#

The day of the week effect multiplier. Defaults to None. It should match the number of timepoints in the latent hospital admissions.

Type:

ArrayLike or None

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:

InfectionsSample

static validate()[source]#

Validation of kwargs to be implemented in subclasses.

Return type:

None

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#

The estimated latent infections. Default 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)\) values

  • 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.

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 feedback

  • infection_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), where Rt_adjusted is the infection-feedback-adjusted timeseries of the reproduction number \(\mathcal{R}(t)\) and infections is the incident infection timeseries.

Return type:

tuple

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:
  • I_raw_t (float) – The “unadjusted” incidence at time t, i.e. the incidence given an infinite number of available susceptible individuals.

  • frac_susceptible (float) – fraction of remaining susceptible individuals in the population

  • n_population (float) – Total size of the population.

Returns:

The adjusted value of \(I(t)\).

Return type:

float

Infection Initialization Process#

class InfectionInitializationProcess(name, I_pre_init_rv, infection_init_method)[source]#

Bases: RandomVariable

Generate an initial infection history

Parameters:
sample()[source]#

Sample the Infection Initialization Process.

Returns:

the number of initialized infections at each time point.

Return type:

ArrayLike

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:

None

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.

Parameters:

I_pre_init (ArrayLike) – An array representing some number of latent infections to be used with the specified InfectionInitializationMethod.

Returns:

An array of length n_timepoints with the number of initialized infections at each time point.

Return type:

ArrayLike

static validate(n_timepoints)[source]#

Validate inputs to the InfectionInitializationMethod constructor.

Parameters:

n_timepoints (int) – the number of time points to generate initial infections for

Return type:

None

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\) is rate, and \(t_p\) is t_pre_init. This ensures that \(I(t_p) = I_p\). We default to t_pre_init = n_timepoints - 1, so that I_pre_init represents the number of incident infections immediately before the renewal process begins.

Parameters:
initialize_infections(I_pre_init)[source]#

Generate initial infections according to exponential growth.

Parameters:

I_pre_init (ArrayLike) – An array of size 1 representing the number of infections at time t_pre_init.

Returns:

An array of length n_timepoints with the number of initialized infections at each time point.

Return type:

ArrayLike

class InitializeInfectionsFromVec(n_timepoints)[source]#

Bases: InfectionInitializationMethod

Create initial infections from a vector of infections.

Parameters:

n_timepoints (int)

initialize_infections(I_pre_init)[source]#

Create initial infections from a vector of infections.

Parameters:

I_pre_init (ArrayLike) – An array with the same length as n_timepoints to be used as the initial infections.

Returns:

An array of length n_timepoints with the number of initialized infections at each time point.

Return type:

ArrayLike

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)

initialize_infections(I_pre_init)[source]#

Pad the initial infections with zeros at the beginning of the time series.

Parameters:

I_pre_init (ArrayLike) – An array with initialized infections to be padded with zeros.

Returns:

An array of length n_timepoints with the number of initialized infections at each time point.

Return type:

ArrayLike