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 :math`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.

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.

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.

Parameter#

differcing_orderany

Potential differencing order to validate.

rtype:

None or raises a ValueError

integrate(init_diff_vals, highest_order_diff_vals)[source]#

Integrate (de-difference) the differenced process, obtaining the process values \(X(t=0), X(t=1), ... X(t)\) from the \(n^{th}\) differences and a set of initial process / difference values \(X(t=0), X^1(t=1), X^2(t=2), ... X^{(n-1)}(t=n-1)\), where \(X^k(t)\) is the value of the \(n^{th}\) difference at index \(t\) of the process, obtaining a sequence of length equal to the length of the provided highest_order_diff_vals vector plus the order of the process.

Parameters:
  • init_diff_vals (ArrayLike) – Values of \(X(t=0), X^1(t=1), X^2(t=2) ... X^{(n-1)}(t=n-1)\).

  • highest_order_diff_vals (ArrayLike) – Array of differences at the highest order of differencing, i.e. the order of the overall process, starting with \(X^{n}(t=n)\)

Returns:

  • The integrated (de-differenced) sequence of values,

  • of length n_diffs + order, where n_diffs is the

  • number of highest_order_diff_vals and order is the

  • order of the process.

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 DifferencedProcess.integrate()

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

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

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

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

Returns:

representing the undifferenced timeseries

Return type:

ArrayLike

static validate()[source]#

Validates input parameters, implementation pending.

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.

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 RandomVariable.expand_by(), whenever available, and fall back on numpyro.contrib.control_flow.scan(). 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.

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

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.

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

Samples the periodic Rt with autoregressive difference.

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

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.

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.