Skip to content

Commit d169164

Browse files
mmckyclaude
andcommitted
[sargent_surico] Update arviz calls for the 1.x API
The lecture installs arviz unpinned, and `pip install arviz` now resolves 1.2.0 -- the rewrite that dispatches to arviz-base/arviz-stats/arviz-plots. Two calls still used the 0.x API. `az.from_dict` took the posterior group as its first positional argument in 0.x, so a flat {var_name: array} mapping worked. In 1.x the first argument is {group_name: {var_name: array}}, so each entry of FREE was read as a group and dict_to_dataset() was handed a raw ndarray, failing the HTML build with `AttributeError: 'numpy.ndarray' object has no attribute 'items'`. `az.summary` no longer emits hdi_3%/hdi_97%; it defaults to an 89% ETI. Ask for ci_kind='hdi', ci_prob=0.94 to keep the interval the 0.x default gave, and select the new hdi94_lb/hdi94_ub columns. Execution stopped at the from_dict cell above, so this second break never reached the CI log. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent c43db95 commit d169164

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

lectures/sargent_surico.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,8 @@ A correlated chain of length $N$ is worth fewer than $N$ independent draws, and
12841284
```{code-cell} ipython3
12851285
import arviz as az
12861286
1287-
rwmh_idata = az.from_dict({n: kept[:, j][None, :] for j, n in enumerate(FREE)})
1287+
rwmh_idata = az.from_dict(
1288+
{'posterior': {n: kept[:, j][None, :] for j, n in enumerate(FREE)}})
12881289
rwmh_summary = az.summary(rwmh_idata, var_names=FREE)
12891290
print(rwmh_summary[['mean', 'sd', 'ess_bulk']].to_string())
12901291
print(f'\n{len(kept)} retained draws out of {N_DRAWS}, in {rwmh_seconds:.0f} seconds')
@@ -1637,9 +1638,10 @@ print(f'divergences '
16371638
16381639
```{code-cell} ipython3
16391640
nuts_idata = az.from_numpyro(mcmc)
1640-
nuts_summary = az.summary(nuts_idata, var_names=FREE)
1641+
nuts_summary = az.summary(nuts_idata, var_names=FREE,
1642+
ci_kind='hdi', ci_prob=0.94)
16411643
nuts_kept = np.column_stack([np.asarray(mcmc.get_samples()[n]) for n in FREE])
1642-
nuts_summary[['mean', 'sd', 'hdi_3%', 'hdi_97%', 'ess_bulk', 'r_hat']]
1644+
nuts_summary[['mean', 'sd', 'hdi94_lb', 'hdi94_ub', 'ess_bulk', 'r_hat']]
16431645
```
16441646
16451647
### A warning sign in the diagnostics

0 commit comments

Comments
 (0)