@@ -13,7 +13,7 @@ kernelspec:
13
13
(time_series_generative_graph)=
14
14
# Time Series Models Derived From a Generative Graph
15
15
16
- :::{post} March , 2024
16
+ :::{post} July , 2024
17
17
:tags: time-series,
18
18
:category: intermediate, reference
19
19
:author: Jesse Grabowski, Juan Orduz and Ricardo Vieira
@@ -95,7 +95,7 @@ Let's see concrete implementations:
95
95
96
96
``` {code-cell} ipython3
97
97
lags = 2 # Number of lags
98
- trials = 100 # Time series length
98
+ timeseries_length = 100 # Time series length
99
99
100
100
101
101
# This is the transition function for the AR(2) model.
@@ -113,7 +113,7 @@ def ar_dist(ar_init, rho, sigma, size):
113
113
fn=ar_step,
114
114
outputs_info=[{"initial": ar_init, "taps": range(-lags, 0)}],
115
115
non_sequences=[rho, sigma],
116
- n_steps=trials - lags,
116
+ n_steps=timeseries_length - lags,
117
117
strict=True,
118
118
)
119
119
@@ -127,8 +127,8 @@ Now that we have implemented the AR(2) step, we can assign priors to the paramet
127
127
``` {code-cell} ipython3
128
128
coords = {
129
129
"lags": range(-lags, 0),
130
- "steps": range(trials - lags),
131
- "trials": range(trials ),
130
+ "steps": range(timeseries_length - lags),
131
+ "trials": range(timeseries_length ),
132
132
}
133
133
with pm.Model(coords=coords, check_bounds=False) as model:
134
134
rho = pm.Normal(name="rho", mu=0, sigma=0.2, dims=("lags",))
@@ -169,7 +169,7 @@ for i, hdi_prob in enumerate((0.94, 0.64), 1):
169
169
lower = hdi.sel(hdi="lower")
170
170
upper = hdi.sel(hdi="higher")
171
171
ax.fill_between(
172
- x=np.arange(trials ),
172
+ x=np.arange(timeseries_length ),
173
173
y1=lower,
174
174
y2=upper,
175
175
alpha=(i - 0.2) * 0.2,
@@ -324,7 +324,7 @@ def conditional_ar_dist(y_data, rho, sigma, size):
324
324
fn=ar_step,
325
325
sequences=[{"input": y_data, "taps": list(range(-lags, 0))}],
326
326
non_sequences=[rho, sigma],
327
- n_steps=trials - lags,
327
+ n_steps=timeseries_length - lags,
328
328
strict=True,
329
329
)
330
330
@@ -342,8 +342,8 @@ We need to shift the coordinate `steps` forward by one! The reasons is that the
342
342
``` {code-cell} ipython3
343
343
coords = {
344
344
"lags": range(-lags, 0),
345
- "steps": range(-1, trials - lags - 1), # <- Coordinate shift!
346
- "trials": range(1, trials + 1), # <- Coordinate shift!
345
+ "steps": range(-1, timeseries_length - lags - 1), # <- Coordinate shift!
346
+ "trials": range(1, timeseries_length + 1), # <- Coordinate shift!
347
347
}
348
348
with pm.Model(coords=coords, check_bounds=False) as conditional_model:
349
349
y_data = pm.Data("y_data", ar_obs)
@@ -438,8 +438,8 @@ The idea is to use the posterior samples and the latest available two data point
438
438
``` {code-cell} ipython3
439
439
coords = {
440
440
"lags": range(-lags, 0),
441
- "trials": range(trials ),
442
- "steps": range(trials, trials + forecast_steps),
441
+ "trials": range(timeseries_length ),
442
+ "steps": range(timeseries_length, timeseries_length + forecast_steps),
443
443
}
444
444
with pm.Model(coords=coords, check_bounds=False) as forecasting_model:
445
445
forecast_initial_state = pm.Data("forecast_initial_state", ar_obs[-lags:], dims=("lags",))
0 commit comments