@@ -30,6 +30,7 @@ import pandas as pd
30
30
import pymc as pm
31
31
import statsmodels.api as sm
32
32
33
+ from IPython.display import HTML, display
33
34
from pymc.sampling_jax import sample_blackjax_nuts
34
35
```
35
36
@@ -309,17 +310,17 @@ def shade_background(ppc, ax, idx, palette="cividis"):
309
310
310
311
311
312
def plot_ppc(idata, df, group="posterior_predictive"):
312
- fig, axs = plt.subplots(2, 1, figsize=(20 , 15))
313
+ fig, axs = plt.subplots(2, 1, figsize=(25 , 15))
313
314
df = pd.DataFrame(idata_fake_data["observed_data"]["obs"].data, columns=["x", "y"])
314
315
axs = axs.flatten()
315
316
ppc = az.extract_dataset(idata, group=group, num_samples=100)["obs"]
316
317
# Minus the lagged terms and the constant
317
- shade_background(ppc, axs, 0, "plasma ")
318
+ shade_background(ppc, axs, 0, "magma ")
318
319
axs[0].plot(np.arange(ppc.shape[0]), ppc[:, 0, :].mean(axis=1), color="cyan", label="Mean")
319
320
axs[0].plot(df["x"], "o", color="black", markersize=6, label="Observed")
320
321
axs[0].set_title("VAR Series 1")
321
322
axs[0].legend()
322
- shade_background(ppc, axs, 1, "plasma ")
323
+ shade_background(ppc, axs, 1, "magma ")
323
324
axs[1].plot(df["y"], "o", color="black", markersize=6, label="Observed")
324
325
axs[1].plot(np.arange(ppc.shape[0]), ppc[:, 1, :].mean(axis=1), color="cyan", label="Mean")
325
326
axs[1].set_title("VAR Series 2")
@@ -398,12 +399,12 @@ def plot_ppc_macro(idata, df, group="posterior_predictive"):
398
399
axs = axs.flatten()
399
400
ppc = az.extract_dataset(idata, group=group, num_samples=100)["obs"]
400
401
401
- shade_background(ppc, axs, 0, "plasma ")
402
+ shade_background(ppc, axs, 0, "magma ")
402
403
axs[0].plot(np.arange(ppc.shape[0]), ppc[:, 0, :].mean(axis=1), color="cyan", label="Mean")
403
404
axs[0].plot(df["dl_gdp"], "o", color="black", markersize=6, label="Observed")
404
405
axs[0].set_title("Differenced and Logged GDP")
405
406
axs[0].legend()
406
- shade_background(ppc, axs, 1, "plasma ")
407
+ shade_background(ppc, axs, 1, "magma ")
407
408
axs[1].plot(df["dl_cons"], "o", color="black", markersize=6, label="Observed")
408
409
axs[1].plot(np.arange(ppc.shape[0]), ppc[:, 1, :].mean(axis=1), color="cyan", label="Mean")
409
410
axs[1].set_title("Differenced and Logged Consumption")
@@ -533,7 +534,18 @@ idata_full_test
533
534
We can see how the structure of the model has grown quite complicated.
534
535
535
536
``` {code-cell} ipython3
536
- pm.model_to_graphviz(model_full_test)
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="full_model.png" alt="Model Structure">
546
+ </div>"""
547
+ )
548
+ )
537
549
```
538
550
539
551
``` {code-cell} ipython3
@@ -643,7 +655,7 @@ for ax, country in zip(axs, countries):
643
655
f"obs_{country}"
644
656
]
645
657
for i in range(3):
646
- shade_background(ppc, ax, i, "plasma ")
658
+ shade_background(ppc, ax, i, "magma ")
647
659
ax[0].plot(np.arange(ppc.shape[0]), ppc[:, 0, :].mean(axis=1), color="cyan", label="Mean")
648
660
ax[0].plot(temp["dl_gdp"], "o", color="black", markersize=4, label="Observed")
649
661
ax[0].set_title(f"Posterior Predictive GDP: {country}")
0 commit comments