Random Process#

class ARProcess(**kwargs)[source]#

Bases: RandomVariable

RandomVariable representing an an AR(p) process.

sample(noise_name, n, autoreg, init_vals, noise_sd)[source]#

Sample from the AR process

Parameters:
  • noise_name (str) – A name for the sample site holding the Normal(0, noise_sd) noise for the AR process. Passed to numpyro.sample().

  • n (int) – Length of the sequence.

  • autoreg (ArrayLike) – Autoregressive coefficients. The length of the array’s first dimension determines the order \(p\) of the AR process.

  • init_vals (ArrayLike) – Array of initial values. Must have the same first dimension size as the order.

  • noise_sd (ArrayLike) – Standard deviation of the AR process Normal noise, which by definition has mean 0.

Returns:

with first dimension of length n and additional dimensions as inferred from the shapes of autoreg, init_vals, and noise_sd.

Return type:

ArrayLike

Notes

The first dimension of the return value with be of length n and represents time. Trailing dimensions follow standard numpy broadcasting rules and are determined from the second through n th dimensions, if any, of autoreg and init_vals, as well as the all dimensions of noise_sd (i.e. jax.numpy.shape(autoreg)[1:], jax.numpy.shape(init_vals)[1:] and jax.numpy.shape(noise_sd)

Those shapes must be broadcastable together via jax.lax.broadcast_shapes(). This can be used to produce multiple AR processes of the same order but with either shared or different initial values, AR coefficient vectors, and/or and noise standard deviation values.

static validate()[source]#

Validates input parameters, implementation pending.

class DayOfWeekEffect(offset, quantity_to_broadcast)[source]#

Bases: PeriodicEffect

Weekly effect with repeating values from a random variable.

Parameters:
static validate(offset)[source]#

Validate the input parameters.

Parameters:

offset (int) – Relative point at which data starts, must be between 0 and 6.

Return type:

None

class DifferencedProcess(fundamental_process, differencing_order, **kwargs)[source]#

Bases: RandomVariable

Class for differenced stochastic process X(t), constructed by placing a fundamental stochastic process on the \(n^{th}\) differences (rates of change). See https://otexts.com/fpp3/stationarity.html for a discussion of differencing in the context of discrete timeseries data.

Notes

The order of differencing is the discrete analogue of the order of a derivative in single variable calculus. A first difference (derivative) represents a rate of change. A second difference (derivative) represents the rate of change of that rate of change, et cetera.

Parameters:
static assert_valid_differencing_order(differencing_order)[source]#

To be valid, a differencing order must be an integer and must be strictly positive. This function raises a value error if its argument is not a valid differencing order.

Parameters:

differencing_order (Any) – Potential differencing order to validate.

Returns:

or raises a ValueError

Return type:

None

sample(init_vals, n, *args, fundamental_process_init_vals=None, **kwargs)[source]#

Sample from the process

Parameters:
  • init_vals (ArrayLike) – initial values for the \(0^{th}\) through \((n-1)^{st}\) differences, passed as the init_diff_vals argument to integrate_discrete()

  • n (int) – Number of values to sample. Will sample n - differencing_order values from self.fundamental_process() to ensure that the de-differenced output is of length :code`n`.

  • *args – Additional positional arguments passed to self.fundamental_process.sample()

  • fundamental_process_init_vals (ArrayLike, optional) – Initial values for the fundamental process. Passed as the init_vals keyword argument to self.fundamental_process.sample(). Default None.

  • **kwargs (dict, optional) – Keyword arguments passed to self.fundamental_process.sample().

Returns:

An array representing the undifferenced timeseries

Return type:

jnp.ndarray

validate()[source]#

Empty validation method.

class IIDRandomSequence(element_rv, **kwargs)[source]#

Bases: RandomVariable

Class for constructing random sequence of independent and identically distributed elements given an arbitrary RandomVariable representing those elements.

Parameters:

element_rv (RandomVariable)

sample(n, *args, vectorize=False, **kwargs)[source]#

Sample an IID random sequence.

Parameters:
  • n (int) – Length of the sequence to sample.

  • *args – Additional positional arguments passed to self.element_rv.sample()

  • vectorize (bool) – Sample vectorized? If True, use the RandomVariable’s expand_by() method, if available, and fall back on numpyro.contrib.control_flow.scan() otherwise. If False, always use scan(). Default False.

  • **kwargs – Additional keyword arguments passed to self.element_rv.sample().

Returns:

n samples from self.distribution.

Return type:

ArrayLike

static validate()[source]#

Validates input parameters, implementation pending.

class PeriodicEffect(offset, quantity_to_broadcast)[source]#

Bases: RandomVariable

Periodic effect with repeating values from a random variable.

Parameters:
sample(duration, **kwargs)[source]#

Sample from the process.

Parameters:
  • duration (int) – Number of timepoints to sample.

  • **kwargs (dict, optional) – Additional keyword arguments passed through to the quantity_to_broadcast.

Return type:

ArrayLike

static validate(quantity_to_broadcast)[source]#

Validate the broadcasting quatity.

Parameters:

quantity_to_broadcast (RandomVariable) – Values to be broadcasted (repeated or tiled).

Return type:

None

class RandomWalk(step_rv, **kwargs)[source]#

Bases: DifferencedProcess

Class for a Markovian random walk with an arbitrary step distribution, implemented via DifferencedProcess and IIDRandomSequence

Parameters:

step_rv (RandomVariable)

class RtPeriodicDiffARProcess(name, offset, period_size, log_rt_rv, autoreg_rv, periodic_diff_sd_rv, ar_process_suffix='_first_diff_ar_process_noise')[source]#

Bases: RandomVariable

Periodic Rt with autoregressive first differences

Notes

This class samples a periodic reproduction number R(t) by placing an AR(1) process on the first differences in log[R(t)]. Formally:

\[\log[\mathcal{R}^\mathrm{u}(t_3)] \sim \mathrm{Normal}\left(\log[\mathcal{R}^\mathrm{u}(t_2)] \ + \beta \left(\log[\mathcal{R}^\mathrm{u}(t_2)] - \ \log[\mathcal{R}^\mathrm{u}(t_1)]\right), \sigma_r \right) \]

where \(\mathcal{R}^\mathrm{u}(t)\) is the periodic reproduction number at time \(t\), \(\beta\) is the autoregressive parameter, and \(\sigma_r\) is the standard deviation of the noise.

Parameters:
sample(duration, **kwargs)[source]#

Samples the periodic \(\mathcal{R}(t)\) with autoregressive first differences.

Parameters:
  • duration (int) – Duration of the sequence.

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

Returns:

Sampled \(\mathcal{R}(t)\) values.

Return type:

ArrayLike

static validate(log_rt_rv, autoreg_rv, periodic_diff_sd_rv)[source]#

Validate the input parameters.

Parameters:
  • log_rt_rv (any) – Log Rt prior for the first two observations.

  • autoreg_rv (any) – Autoregressive parameter.

  • periodic_diff_sd_rv (any) – Standard deviation of the noise.

Return type:

None

class RtWeeklyDiffARProcess(name, offset, log_rt_rv, autoreg_rv, periodic_diff_sd_rv)[source]#

Bases: RtPeriodicDiffARProcess

Weekly Rt with autoregressive first differences.

Parameters:
class StandardNormalRandomWalk(step_rv_name, **kwargs)[source]#

Bases: RandomWalk

A random walk with standard Normal (mean = 0, standard deviation = 1) steps, implmemented via the base RandomWalk class.

Parameters:

step_rv_name (str)

class StandardNormalSequence(element_rv_name, element_shape=None, **kwargs)[source]#

Bases: IIDRandomSequence

Class for a sequence of IID standard Normal (mean = 0, sd = 1) random variables.

Parameters:
  • element_rv_name (str)

  • element_shape (tuple)