Open omsai opened 1 year ago
:tada: Welcome to PyMC! :tada: We're really excited to have your input into the project! :sparkling_heart:
If you haven't done so already, please make sure you check out our Contributing Guidelines and Code of Conduct.
CC @aloctavodia
Not sure what the solution should be in this case, when the mvnornal kernel is unstable...
In the meantime you can perhaps try using a different kernel that doesn't rely on a multivariate sampling of the particles and see if that works for you.
That worked! After switching to the Metropolis-Hastings kernel instead of Independent Metropolis-Hastings, I get no longer get that crash after trying 20 times:
$ for i in {1..20}; do python3 -Wignore perelson1993pymc_scipy_01_model.py echo $i: $? done
Initializing SMC sampler...
Sampling 8 chains in 8 jobs
The rhat statistic is larger than 1.01 for some parameters. This indicates problems during sampling. See https://arxiv.org/abs/1903.08008 for details
The effective sample size per chain is smaller than 100 for some parameters. A higher number is needed for reliable rhat and ess computation. See https://arxiv.org/abs/1903.08008 for details
1: 0
...[repeats 20x]...
$ diff -u perelson1993pymc_scipy_01_model.py{.orig,}
--- perelson1993pymc_scipy_01_model.py.orig 2023-06-21 17:45:21
+++ perelson1993pymc_scipy_01_model.py 2023-06-21 17:32:25
@@ -9,6 +9,7 @@
import numpy as np
import pandas as pd
import pymc as pm
+from pymc.smc.kernels import MH
from scipy.integrate import odeint
@@ -98,7 +99,7 @@
epsilon=10,
observed=OBSERVED)
# Collect inference data.
- idata_hiv = pm.sample_smc(cores=8, random_seed=456)
+ idata_hiv = pm.sample_smc(cores=8, kernel=MH)
with open("perelson1993-01_output-idata_hiv.pkl", "wb") as file_:
pickle.dump(idata_hiv, file_)
NB: I edited the original program above with a random_seed
to make it crash every time.
Describe the issue:
Close to the end stages of fitting an ODE model with ABC-SMC, the kernel fails with
np.linalg.LinAlgError
for a particular model. It's not possible to catch the exception in the model simulation code, which makes me wonder if some check are needed in the kernel? The error doesn't typically happen but these sets of parameters tend to create the crash (edit: made the crash reproducible every time instead of every other time usingrandom_seed=456
).You will need this small 2 KB CSV data file to run the reproducible code example: pantaleo1995-figure1.csv
Reproduceable code example:
Error message:
PyMC version information:
Context for the issue:
Causes a crash with these particular model parameters.