Skip to content

Commit 9bbe9e5

Browse files
committed
[Hierarchical BVAR pymc-devs#286] reverting full model image
Signed-off-by: Nathaniel <[email protected]>
1 parent 7248bd6 commit 9bbe9e5

File tree

3 files changed

+7090
-5613
lines changed

3 files changed

+7090
-5613
lines changed

examples/time_series/bayesian_var_model.ipynb

+7,083-5,592
Large diffs are not rendered by default.

examples/time_series/full_model.png

-616 KB
Binary file not shown.

myst_nbs/time_series/bayesian_var_model.myst.md

+7-21
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ kernelspec:
2121
:::
2222

2323
```{code-cell} ipython3
24-
import aesara as at
2524
import arviz as az
26-
import matplotlib.dates as mdates
2725
import matplotlib.pyplot as plt
2826
import numpy as np
2927
import pandas as pd
3028
import pymc as pm
3129
import statsmodels.api as sm
3230
33-
from IPython.display import HTML, display
3431
from pymc.sampling_jax import sample_blackjax_nuts
3532
```
3633

@@ -315,12 +312,12 @@ def plot_ppc(idata, df, group="posterior_predictive"):
315312
axs = axs.flatten()
316313
ppc = az.extract_dataset(idata, group=group, num_samples=100)["obs"]
317314
# Minus the lagged terms and the constant
318-
shade_background(ppc, axs, 0, "magma")
315+
shade_background(ppc, axs, 0, "viridis")
319316
axs[0].plot(np.arange(ppc.shape[0]), ppc[:, 0, :].mean(axis=1), color="cyan", label="Mean")
320317
axs[0].plot(df["x"], "o", color="black", markersize=6, label="Observed")
321318
axs[0].set_title("VAR Series 1")
322319
axs[0].legend()
323-
shade_background(ppc, axs, 1, "magma")
320+
shade_background(ppc, axs, 1, "viridis")
324321
axs[1].plot(df["y"], "o", color="black", markersize=6, label="Observed")
325322
axs[1].plot(np.arange(ppc.shape[0]), ppc[:, 1, :].mean(axis=1), color="cyan", label="Mean")
326323
axs[1].set_title("VAR Series 2")
@@ -399,12 +396,12 @@ def plot_ppc_macro(idata, df, group="posterior_predictive"):
399396
axs = axs.flatten()
400397
ppc = az.extract_dataset(idata, group=group, num_samples=100)["obs"]
401398
402-
shade_background(ppc, axs, 0, "magma")
399+
shade_background(ppc, axs, 0, "inferno")
403400
axs[0].plot(np.arange(ppc.shape[0]), ppc[:, 0, :].mean(axis=1), color="cyan", label="Mean")
404401
axs[0].plot(df["dl_gdp"], "o", color="black", markersize=6, label="Observed")
405402
axs[0].set_title("Differenced and Logged GDP")
406403
axs[0].legend()
407-
shade_background(ppc, axs, 1, "magma")
404+
shade_background(ppc, axs, 1, "inferno")
408405
axs[1].plot(df["dl_cons"], "o", color="black", markersize=6, label="Observed")
409406
axs[1].plot(np.arange(ppc.shape[0]), ppc[:, 1, :].mean(axis=1), color="cyan", label="Mean")
410407
axs[1].set_title("Differenced and Logged Consumption")
@@ -534,18 +531,7 @@ idata_full_test
534531
We can see how the structure of the model has grown quite complicated.
535532

536533
```{code-cell} ipython3
537-
gv = pm.model_to_graphviz(model_full_test)
538-
gv.render(filename="full_model", format="png");
539-
```
540-
541-
```{code-cell} ipython3
542-
display(
543-
HTML(
544-
"""<div style='width: 4500px; overflow: scroll;'>
545-
<img src="../examples/time_series/full_model.png" alt="Model Structure">
546-
</div>"""
547-
)
548-
)
534+
pm.model_to_graphviz(model_full_test)
549535
```
550536

551537
```{code-cell} ipython3
@@ -645,7 +631,7 @@ We can see these estimates of the correlations between the 3 economic variables
645631
countries = gdp_hierarchical["country"].unique()
646632
# countries = ["Ireland", "United States"]
647633
648-
fig, axs = plt.subplots(8, 3, figsize=(20, 30))
634+
fig, axs = plt.subplots(8, 3, figsize=(20, 40))
649635
for ax, country in zip(axs, countries):
650636
temp = pd.DataFrame(
651637
idata_full_test["observed_data"][f"obs_{country}"].data,
@@ -655,7 +641,7 @@ for ax, country in zip(axs, countries):
655641
f"obs_{country}"
656642
]
657643
for i in range(3):
658-
shade_background(ppc, ax, i, "magma")
644+
shade_background(ppc, ax, i, "inferno")
659645
ax[0].plot(np.arange(ppc.shape[0]), ppc[:, 0, :].mean(axis=1), color="cyan", label="Mean")
660646
ax[0].plot(temp["dl_gdp"], "o", color="black", markersize=4, label="Observed")
661647
ax[0].set_title(f"Posterior Predictive GDP: {country}")

0 commit comments

Comments
 (0)