Process
ARProcess
ARProcess(**kwargs)
Bases: RandomVariable
RandomVariable representing an an AR(p) process.
Source code in pyrenew/metaclass.py
47 48 49 50 51 |
|
sample
sample(
noise_name: str,
n: int,
autoreg: ArrayLike,
init_vals: ArrayLike,
noise_sd: float | ArrayLike,
) -> ArrayLike
Sample from the AR process
Parameters:
Name | Type | Description | Default |
---|---|---|---|
noise_name
|
str
|
A name for the sample site holding the
Normal( |
required |
n
|
int
|
Length of the sequence. |
required |
autoreg
|
ArrayLike
|
Autoregressive coefficients. The length of the array's first dimension determines the order \(p\) of the AR process. |
required |
init_vals
|
ArrayLike
|
Array of initial values. Must have the same first dimension size as the order. |
required |
noise_sd
|
float | ArrayLike
|
Standard deviation of the AR process Normal noise, which by definition has mean 0. |
required |
Returns:
Type | Description |
---|---|
ArrayLike
|
with first dimension of length |
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.
Source code in pyrenew/process/ar.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
validate
staticmethod
validate()
Validates input parameters, implementation pending.
Source code in pyrenew/process/ar.py
181 182 183 184 185 186 |
|
DayOfWeekEffect
DayOfWeekEffect(offset: int, quantity_to_broadcast: RandomVariable)
Bases: PeriodicEffect
Weekly effect with repeating values from a random variable.
Default constructor for DayOfWeekEffect class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset
|
int
|
Relative point at which data starts, must be between 0 and 6. |
required |
quantity_to_broadcast
|
RandomVariable
|
Values to be broadcasted (repeated or tiled). |
required |
Returns:
Type | Description |
---|---|
None
|
|
Source code in pyrenew/process/periodiceffect.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
validate
staticmethod
validate(offset: int)
Validate the input parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset
|
int
|
Relative point at which data starts, must be between 0 and 6. |
required |
Returns:
Type | Description |
---|---|
None
|
|
Source code in pyrenew/process/periodiceffect.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
DifferencedProcess
DifferencedProcess(
fundamental_process: RandomVariable, differencing_order: int, **kwargs
)
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.
Default constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fundamental_process
|
RandomVariable
|
Stochastic process for the
differences. Must accept an
|
required |
differencing_order
|
int
|
How many fold-differencing the the process represents. Must be an integer greater than or equal to 1. 1 represents a process on the first differences (the rate of change), 2 a process on the 2nd differences (rate of change of the rate of change), et cetera. |
required |
Returns:
Type | Description |
---|---|
None
|
|
Source code in pyrenew/process/differencedprocess.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
assert_valid_differencing_order
staticmethod
assert_valid_differencing_order(differencing_order: Any)
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:
Name | Type | Description | Default |
---|---|---|---|
differencing_order
|
Any
|
Potential differencing order to validate. |
required |
Returns:
Type | Description |
---|---|
None
|
or raises a |
Source code in pyrenew/process/differencedprocess.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
sample
sample(
init_vals: ArrayLike,
n: int,
*args,
fundamental_process_init_vals: ArrayLike = None,
**kwargs,
) -> ndarray
Sample from the process
Parameters:
Name | Type | Description | Default |
---|---|---|---|
init_vals
|
ArrayLike
|
initial values for the \(0^{th}\) through
\((n-1)^{st}\) differences, passed as the
|
required |
n
|
int
|
Number of values to sample. Will sample
|
required |
*args
|
Additional positional arguments passed to
|
()
|
|
fundamental_process_init_vals
|
ArrayLike
|
Initial values for the fundamental process.
Passed as the |
None
|
**kwargs
|
Keyword arguments passed to
|
{}
|
Returns:
Type | Description |
---|---|
ndarray
|
An array representing the undifferenced timeseries |
Source code in pyrenew/process/differencedprocess.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
validate
validate()
Empty validation method.
Source code in pyrenew/process/differencedprocess.py
100 101 102 103 104 |
|
IIDRandomSequence
IIDRandomSequence(element_rv: RandomVariable, **kwargs)
Bases: RandomVariable
Class for constructing random sequence of independent and identically distributed elements given an arbitrary RandomVariable representing those elements.
Default constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element_rv
|
RandomVariable
|
RandomVariable representing a single element in the sequence. |
required |
Returns:
Type | Description |
---|---|
None
|
|
Source code in pyrenew/process/iidrandomsequence.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
sample
Sample an IID random sequence.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
Length of the sequence to sample. |
required |
*args
|
Additional positional arguments passed to self.element_rv.sample() |
()
|
|
vectorize
|
bool
|
Sample vectorized? If True, use the
|
False
|
**kwargs
|
Additional keyword arguments passed to
|
{}
|
Returns:
Type | Description |
---|---|
ArrayLike
|
|
Source code in pyrenew/process/iidrandomsequence.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
validate
staticmethod
validate()
Validates input parameters, implementation pending.
Source code in pyrenew/process/iidrandomsequence.py
91 92 93 94 95 96 97 |
|
PeriodicEffect
PeriodicEffect(offset: int, quantity_to_broadcast: RandomVariable)
Bases: RandomVariable
Periodic effect with repeating values from a random variable.
Default constructor for PeriodicEffect class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset
|
int
|
Relative point at which data starts, must be between 0 and period_size - 1. |
required |
quantity_to_broadcast
|
RandomVariable
|
Values to be broadcasted (repeated or tiled). |
required |
Returns:
Type | Description |
---|---|
None
|
|
Source code in pyrenew/process/periodiceffect.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
sample
sample(duration: int, **kwargs)
Sample from the process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
duration
|
int
|
Number of timepoints to sample. |
required |
**kwargs
|
Additional keyword arguments passed through to the |
{}
|
Returns:
Type | Description |
---|---|
ArrayLike
|
|
Source code in pyrenew/process/periodiceffect.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
validate
staticmethod
validate(quantity_to_broadcast: RandomVariable) -> None
Validate the broadcasting quatity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
quantity_to_broadcast
|
RandomVariable
|
Values to be broadcasted (repeated or tiled). |
required |
Returns:
Type | Description |
---|---|
None
|
|
Source code in pyrenew/process/periodiceffect.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
RandomWalk
RandomWalk(step_rv: RandomVariable, **kwargs)
Bases: DifferencedProcess
Class for a Markovian random walk with an arbitrary step distribution, implemented via DifferencedProcess and IIDRandomSequence
Default constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
step_rv
|
RandomVariable
|
RandomVariable representing a single step (difference) in the random walk. |
required |
**kwargs
|
Additional keyword arguments passed to the parent class constructor. |
{}
|
Returns:
Type | Description |
---|---|
None
|
|
Source code in pyrenew/process/randomwalk.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
RtPeriodicDiffARProcess
RtPeriodicDiffARProcess(
name: str,
offset: int,
period_size: int,
log_rt_rv: RandomVariable,
autoreg_rv: RandomVariable,
periodic_diff_sd_rv: RandomVariable,
ar_process_suffix: str = "_first_diff_ar_process_noise",
)
Bases: RandomVariable
Periodic Rt with autoregressive first differences
Notes
This class samples a periodic reproduction number \(\mathcal{R}(t)\) by placing an AR(1) process on the first differences in \(\log[\mathcal{R}(t)]\). Formally:
Default constructor for RtPeriodicDiffARProcess class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the site. |
required |
offset
|
int
|
Relative point at which data starts, must be between 0 and period_size - 1. |
required |
log_rt_rv
|
RandomVariable
|
Log Rt prior for the first two observations. |
required |
autoreg_rv
|
RandomVariable
|
Autoregressive parameter. |
required |
periodic_diff_sd_rv
|
RandomVariable
|
Standard deviation of the noise. |
required |
ar_process_suffix
|
str
|
Suffix to append to the |
'_first_diff_ar_process_noise'
|
Returns:
Type | Description |
---|---|
None
|
|
Source code in pyrenew/process/rtperiodicdiffar.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
sample
Samples the periodic \(\mathcal{R}(t)\) with autoregressive first differences.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
duration
|
int
|
Duration of the sequence. |
required |
**kwargs
|
Additional keyword arguments passed through to
internal |
{}
|
Returns:
Type | Description |
---|---|
ArrayLike
|
Sampled \(\mathcal{R}(t)\) values. |
Source code in pyrenew/process/rtperiodicdiffar.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
validate
staticmethod
Validate the input parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
log_rt_rv
|
any
|
Log Rt prior for the first two observations. |
required |
autoreg_rv
|
any
|
Autoregressive parameter. |
required |
periodic_diff_sd_rv
|
any
|
Standard deviation of the noise. |
required |
Returns:
Type | Description |
---|---|
None
|
|
Source code in pyrenew/process/rtperiodicdiffar.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
RtWeeklyDiffARProcess
RtWeeklyDiffARProcess(
name: str,
offset: int,
log_rt_rv: RandomVariable,
autoreg_rv: RandomVariable,
periodic_diff_sd_rv: RandomVariable,
)
Bases: RtPeriodicDiffARProcess
Weekly Rt with autoregressive first differences.
Default constructor for RtWeeklyDiffARProcess class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the site. |
required |
offset
|
int
|
Relative point at which data starts, must be between 0 and 6. |
required |
log_rt_rv
|
RandomVariable
|
Log Rt prior for the first two observations. |
required |
autoreg_rv
|
RandomVariable
|
Autoregressive parameter. |
required |
periodic_diff_sd_rv
|
RandomVariable
|
Standard deviation of the noise. |
required |
Returns:
Type | Description |
---|---|
None
|
|
Source code in pyrenew/process/rtperiodicdiffar.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
|
StandardNormalRandomWalk
StandardNormalRandomWalk(step_rv_name: str, **kwargs)
Bases: RandomWalk
A random walk with standard Normal (mean = 0, standard deviation = 1) steps, implmemented via the base RandomWalk class.
Default constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
step_rv_name
|
str
|
Name for the DistributionalVariable from which the Normal(0, 1) steps are sampled. |
required |
**kwargs
|
Additional keyword arguments passed to the parent class constructor. |
{}
|
Return
None
Source code in pyrenew/process/randomwalk.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
StandardNormalSequence
Bases: IIDRandomSequence
Class for a sequence of IID standard Normal (mean = 0, sd = 1) random variables.
Default constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element_rv_name
|
str
|
Name for the internal element_rv, here a DistributionalVariable encoding a standard Normal (mean = 0, sd = 1) distribution. |
required |
element_shape
|
tuple
|
Shape for each element in the sequence. If None, elements are scalars. Default None. |
None
|
Returns:
Type | Description |
---|---|
None
|
|
Source code in pyrenew/process/iidrandomsequence.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|