Skip to content

Commit

Permalink
Update pymc3_generative_model.py (#262)
Browse files Browse the repository at this point in the history
* Update pymc3_generative_model.py

add `init="adapt_diag"` to `pm.sample` to avoid the `Mass matrix contains zeros on the diagonal` error.

`jitter+adapt_diag` made initialization much more sensitive on the master branch, causing ValueError: Mass matrix contains zeros on the diagonal to appear more frequently.

* add multiple init settings
  • Loading branch information
wangfan860 committed Mar 17, 2022
1 parent 0cc85ad commit 1c3185e
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions generative_bayes_model/pymc3_generative_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,30 @@ def get_delay_distribution():
y_logp = pm.Deterministic("y_logp", y_past.logpt)

with model:
trace = pm.sample(
500, tune=800, chains=1, target_accept=0.95, random_seed=42, cores=8
)
try:
trace = pm.sample(
100, tune=100, chains=1, target_accept=0.95, random_seed=42, cores=1
)
except ValueError:
trace = pm.sample(
100,
tune=100,
chains=1,
target_accept=0.95,
random_seed=42,
cores=1,
init="adapt_diag",
)
else:
trace = pm.sample(
100,
tune=100,
chains=1,
target_accept=0.95,
random_seed=42,
cores=1,
init="advi+adapt_diag",
)
pm.save_trace(trace=trace, directory="./trace", overwrite=True)

with model:
Expand Down

0 comments on commit 1c3185e

Please sign in to comment.