Closed BryanRumsey closed 2 years ago
Hi, thanks for reporting the crash. It is due to the covariance matrix being ill-conditioned, while applying the perturbation during SMC ABC. The ideal way to solve this would be to rescale the range of the prior. I performed a quick test by changing the prior and simulator as,
from sciope.utilities.priors import uniform_prior
# take default from mode 1 as reference
default_param = np.array(list(model.listOfParameters.items()))[:, 1]
parameter_names = []
bound = []
for exp in default_param:
bound.append(float(exp.expression))
parameter_names.append(exp.name)
bound = np.log(bound)
# Set the bounds
bound = np.array(bound)
dmin = bound * 0.1
dmax = bound * 2.0
# Here we use uniform prior
uni_prior = uniform_prior.UniformPrior(dmin, dmax)
Here we have just added a np.log transformation to the bounds. Then we do the opposite while simulating as,
# Here we use the GillesPy2 Solver
def simulator(params, model):
params = np.exp(params)
model_update = set_model_parameters(params, model)
res = model_update.run(**kwargs)
devils = res['Devils']
infected = res['I']
return np.vstack([devils, infected]).reshape(1, 2, -1)
Note that only the first line (np.exp) has been added. This should work, or you could also rescale to [0,1] for example. Do let us know if this consistently fixes the issue.
We attempted this solution and are consistently get this error:
/opt/conda/lib/python3.8/site-packages/sciope/inference/rep_smc_abc.py:224: RuntimeWarning:
divide by zero encountered in double_scalars
---------------------------------------------------------------------------
OverflowError Traceback (most recent call last)
<ipython-input-18-74032fd839d8> in <module>
6 # First compute the fixed(observed) mean
7 abc.compute_fixed_mean(chunk_size=2)
----> 8 res = abc.infer(num_samples=100, batch_size=10, chunk_size=2)
/opt/conda/lib/python3.8/site-packages/sciope/inference/rep_smc_abc.py in infer(self, num_samples, alpha, R_trial, c, p_min, batch_size, chunk_size)
222 N_acc = np.sum(N_accs)
223
--> 224 R = int(round(np.log(c) / np.log(1 - p_acc)))
225
226 # Perturb again with better estimate
OverflowError: cannot convert float infinity to integer
The latest commit on sciope master now takes care of this scenario. I have also updated your notebook to use vanilla SMC ABC, can you please check if the attached notebook works as expected for you, with the latest code on sciope master? Please note that the replenishment variant might not work and needs more investigation and setup. The vanialla SMC should work as expected. devils_test.zip
devils_v0_month.ipynb.zip
Data File: DFDT Population Devil Population
We are consistently getting the following error using the above model: