Skip to content

Commit b2433dd

Browse files
author
juanitorduz
committed
rename time series length
1 parent 01fb650 commit b2433dd

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

examples/time_series/Time_Series_Generative_Graph.ipynb

Lines changed: 31 additions & 31 deletions
Large diffs are not rendered by default.

examples/time_series/Time_Series_Generative_Graph.myst.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ kernelspec:
1313
(time_series_generative_graph)=
1414
# Time Series Models Derived From a Generative Graph
1515

16-
:::{post} March, 2024
16+
:::{post} July, 2024
1717
:tags: time-series,
1818
:category: intermediate, reference
1919
:author: Jesse Grabowski, Juan Orduz and Ricardo Vieira
@@ -95,7 +95,7 @@ Let's see concrete implementations:
9595

9696
```{code-cell} ipython3
9797
lags = 2 # Number of lags
98-
trials = 100 # Time series length
98+
timeseries_length = 100 # Time series length
9999
100100
101101
# This is the transition function for the AR(2) model.
@@ -113,7 +113,7 @@ def ar_dist(ar_init, rho, sigma, size):
113113
fn=ar_step,
114114
outputs_info=[{"initial": ar_init, "taps": range(-lags, 0)}],
115115
non_sequences=[rho, sigma],
116-
n_steps=trials - lags,
116+
n_steps=timeseries_length - lags,
117117
strict=True,
118118
)
119119
@@ -127,8 +127,8 @@ Now that we have implemented the AR(2) step, we can assign priors to the paramet
127127
```{code-cell} ipython3
128128
coords = {
129129
"lags": range(-lags, 0),
130-
"steps": range(trials - lags),
131-
"trials": range(trials),
130+
"steps": range(timeseries_length - lags),
131+
"trials": range(timeseries_length),
132132
}
133133
with pm.Model(coords=coords, check_bounds=False) as model:
134134
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):
169169
lower = hdi.sel(hdi="lower")
170170
upper = hdi.sel(hdi="higher")
171171
ax.fill_between(
172-
x=np.arange(trials),
172+
x=np.arange(timeseries_length),
173173
y1=lower,
174174
y2=upper,
175175
alpha=(i - 0.2) * 0.2,
@@ -324,7 +324,7 @@ def conditional_ar_dist(y_data, rho, sigma, size):
324324
fn=ar_step,
325325
sequences=[{"input": y_data, "taps": list(range(-lags, 0))}],
326326
non_sequences=[rho, sigma],
327-
n_steps=trials - lags,
327+
n_steps=timeseries_length - lags,
328328
strict=True,
329329
)
330330
@@ -342,8 +342,8 @@ We need to shift the coordinate `steps` forward by one! The reasons is that the
342342
```{code-cell} ipython3
343343
coords = {
344344
"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!
347347
}
348348
with pm.Model(coords=coords, check_bounds=False) as conditional_model:
349349
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
438438
```{code-cell} ipython3
439439
coords = {
440440
"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),
443443
}
444444
with pm.Model(coords=coords, check_bounds=False) as forecasting_model:
445445
forecast_initial_state = pm.Data("forecast_initial_state", ar_obs[-lags:], dims=("lags",))

0 commit comments

Comments
 (0)