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 tonumpyro.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:
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:]
andjax.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.
- class DayOfWeekEffect(offset, quantity_to_broadcast)[source]#
Bases:
PeriodicEffect
Weekly effect with repeating values from a random variable.
- Parameters:
offset (int)
quantity_to_broadcast (RandomVariable)
- 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:
fundamental_process (RandomVariable)
differencing_order (int)
- 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:
- 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 theinit_diff_vals
argument tointegrate_discrete()
n (
int
) – Number of values to sample. Will samplen - differencing_order
values fromself.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 theinit_vals
keyword argument toself.fundamental_process.sample()
. DefaultNone
.**kwargs (
dict
, optional) – Keyword arguments passed toself.fundamental_process.sample()
.
- Returns:
An array representing the undifferenced timeseries
- Return type:
jnp.ndarray
- 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 theRandomVariable
’sexpand_by()
method, if available, and fall back onnumpyro.contrib.control_flow.scan()
otherwise. If False, always usescan()
. Default False.**kwargs – Additional keyword arguments passed to
self.element_rv.sample()
.
- Returns:
n samples from
self.distribution
.- Return type:
- class PeriodicEffect(offset, quantity_to_broadcast)[source]#
Bases:
RandomVariable
Periodic effect with repeating values from a random variable.
- Parameters:
offset (int)
quantity_to_broadcast (RandomVariable)
- 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:
name (str)
offset (int)
period_size (int)
log_rt_rv (RandomVariable)
autoreg_rv (RandomVariable)
periodic_diff_sd_rv (RandomVariable)
ar_process_suffix (str)
- class RtWeeklyDiffARProcess(name, offset, log_rt_rv, autoreg_rv, periodic_diff_sd_rv)[source]#
Bases:
RtPeriodicDiffARProcess
Weekly Rt with autoregressive first differences.
- Parameters:
name (str)
offset (int)
log_rt_rv (RandomVariable)
autoreg_rv (RandomVariable)
periodic_diff_sd_rv (RandomVariable)
- 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.