Skip to content

Commit 613d1e3

Browse files
authored
Update LKJ nb from v4 to v5 (#583)
1 parent 0e74cef commit 613d1e3

File tree

2 files changed

+81
-204
lines changed

2 files changed

+81
-204
lines changed

examples/case_studies/LKJ.ipynb

+78-200
Large diffs are not rendered by default.

examples/case_studies/LKJ.myst.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ colab:
2727
id: 17Thh2DHr2Pa
2828
outputId: 90631275-86c9-4f4a-f81a-22465d0c8b8c
2929
---
30-
%env MKL_THREADING_LAYER=GNU
3130
import arviz as az
3231
import numpy as np
3332
import pymc as pm
34-
import seaborn as sns
3533
3634
from matplotlib import pyplot as plt
3735
from matplotlib.lines import Line2D
@@ -156,7 +154,7 @@ Often however, you'll be interested in the posterior distribution of the correla
156154
:id: ac3eQeMJr2Pf
157155
158156
coords = {"axis": ["y", "z"], "axis_bis": ["y", "z"], "obs_id": np.arange(N)}
159-
with pm.Model(coords=coords, rng_seeder=RANDOM_SEED) as model:
157+
with pm.Model(coords=coords) as model:
160158
chol, corr, stds = pm.LKJCholeskyCov(
161159
"chol", n=2, eta=2.0, sd_dist=pm.Exponential.dist(1.0, shape=2)
162160
)
@@ -189,6 +187,7 @@ outputId: f039bfb8-1acf-42cb-b054-bc2c97697f96
189187
---
190188
with model:
191189
trace = pm.sample(
190+
random_seed=rng,
192191
idata_kwargs={"dims": {"chol_stds": ["axis"], "chol_corr": ["axis", "axis_bis"]}},
193192
)
194193
az.summary(trace, var_names="~chol", round_to=2)
@@ -264,7 +263,7 @@ Sigma_post = trace.posterior["cov"].mean(("chain", "draw")).values
264263

265264
+++ {"id": "DMDwKtp0r2Pj"}
266265

267-
So the posterior means are within 3% of the true values of $\mu$ and $\Sigma$.
266+
So the posterior means are within 1% of the true values of $\mu$ and $\Sigma$.
268267

269268
Now let's replicate the plot we did at the beginning, but let's overlay the posterior distribution on top of the true distribution -- you'll see there is excellent visual agreement between both:
270269

0 commit comments

Comments
 (0)