Latent#

Hospital Admissions#

class HospitalAdmissions(infection_to_admission_interval_rv, infect_hosp_rate_rv, latent_hospital_admissions_varname='latent_hospital_admissions', day_of_week_effect_rv=None, hosp_report_prob_rv=None)[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.

sample(latent_infections, **kwargs)[source]#

Samples from the observation process

Parameters:
  • latent (ArrayLike) – Latent infections.

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

Return type:

HospitalAdmissionsSample

static validate(infect_hosp_rate_rv, day_of_week_effect_rv, hosp_report_prob_rv)[source]#

Validates that the IHR, weekday effects, and probability of being reported hospitalized distributions are RandomVariable types

Parameters:
  • infect_hosp_rate_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.

  • hosp_report_prob_rv (Any) – Possibly incorrect input for distribution or fixed value for the hospital admission reporting probability.

Return type:

None

Raises:

AssertionError – If the object distr is not an instance of dist.Distribution, indicating that the validation has failed.

class HospitalAdmissionsSample(infection_hosp_rate: float | None = None, latent_hospital_admissions: ArrayLike | None = None)[source]#

Bases: NamedTuple

A container to hold the output of latent.HospAdmissions.sample().

infection_hosp_rate#

The infection-to-hospitalization rate. Defaults to None.

Type:

float, optional

latent_hospital_admissions#

The computed number of hospital admissions. Defaults to None.

Type:

ArrayLike or None

infection_hosp_rate: float | None#

Alias for field number 0

latent_hospital_admissions: Union[Array, ndarray, bool, number, bool, int, float, complex, None]#

Alias for field number 1

Infections#

class Infections(**kwargs)[source]#

Bases: RandomVariable

Latent infections

This class samples infections given Rt, 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]#

Samples infections given Rt, 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:

Named tuple with “infections”.

Return type:

InfectionsSample

static validate()[source]#

Validation of kwargs to be implemented in subclasses.

Return type:

None

class InfectionsSample(post_seed_infections: ArrayLike | None = None)[source]#

Bases: NamedTuple

A container for holding the output from latent.Infections.sample().

post_seed_infections#

The estimated latent infections. Defaults to None.

Type:

ArrayLike | None, optional

post_seed_infections: Union[Array, ndarray, bool, number, bool, int, float, complex, 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 R(t)

Parameters:
  • I0 (ArrayLike) – Array of initial infections of the same length as the generation interval pmf vector.

  • Rt (ArrayLike) – Timeseries of 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, as a JAX array

Return type:

ArrayLike

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: https://doi.org/10.1016/j.epidem.2017.02.009)

Parameters:
  • I0 (ArrayLike) – Array of initial infections of the same length as the generation interval pmf vector.

  • Rt_raw (ArrayLike) – Timeseries of raw 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 R(t) and infections is the incident infection timeseries.

Return type:

tuple

Notes

This function implements the following renewal process:

\[ \begin{align}\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}\end{align} \]

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_unadjusted proposed in equation 6 of Bhatt et al 2023 [1]

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

References

“Semi-mechanistic Bayesian modelling of COVID-19 with renewal processes.” Journal of the Royal Statistical Society Series A: Statistics in Society 186.4 (2023): 601-615. https://doi.org/10.1093/jrsssa/qnad030

Infection Seeding Process#

class InfectionSeedingProcess(name, I_pre_seed_rv, infection_seed_method)[source]#

Bases: RandomVariable

Generate an initial infection history

sample()[source]#

Sample the infection seeding process.

Returns:

a tuple where the only element is an array with the number of seeded infections at each time point.

Return type:

tuple

static validate(I_pre_seed_rv, infection_seed_method)[source]#

Validate the input arguments to the InfectionSeedingProcess class constructor

Parameters:
  • I_pre_seed_rv (RandomVariable) – A random variable representing the number of infections that occur at some time before the renewal process begins.

  • infection_seed_method (InfectionSeedMethod) – An method to generate the seed infections.

Return type:

None

Infection Seeding Method#

class InfectionSeedMethod(n_timepoints)[source]#

Bases: object

Method for seeding initial infections in a renewal process.

abstract seed_infections(I_pre_seed)[source]#

Generate the number of seeded infections at each time point.

Parameters:

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

Returns:

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

Return type:

ArrayLike

static validate(n_timepoints)[source]#

Validate inputs for the InfectionSeedMethod class constructor

Parameters:

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

Return type:

None

class SeedInfectionsExponential(n_timepoints, rate, t_pre_seed=None)[source]#

Bases: InfectionSeedMethod

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

seed_infections(I_pre_seed)[source]#

Generate seed infections according to exponential growth.

Parameters:

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

Returns:

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

Return type:

ArrayLike

class SeedInfectionsFromVec(n_timepoints)[source]#

Bases: InfectionSeedMethod

Create seed infections from a vector of infections.

seed_infections(I_pre_seed)[source]#

Create seed infections from a vector of infections.

Parameters:

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

Returns:

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

Return type:

ArrayLike

class SeedInfectionsZeroPad(n_timepoints)[source]#

Bases: InfectionSeedMethod

Create a seed infection vector of specified length by padding a shorter vector with an appropriate number of zeros at the beginning of the time series.

seed_infections(I_pre_seed)[source]#

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

Parameters:

I_pre_seed (ArrayLike) – An array with seeded infections to be padded with zeros.

Returns:

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

Return type:

ArrayLike