Priesemann-Group / covid19_inference

Bayesian python toolbox for inference and forecast of the spread of the Coronavirus
GNU General Public License v3.0
73 stars 70 forks source link

Large models lead to bad initial energy/failing chains #4

Closed jdehning closed 4 years ago

jdehning commented 4 years ago

Probably because somewhere nans are appearing in the calculation

tarbaig commented 4 years ago

Is this due to the ode? If yes a first step to a solution could be to replace the handwritten ode solver in https://github.com/Priesemann-Group/covid19_inference/blob/9df8b1ec7043c132d2edc34af1b29583d3eff88e/covid19_inference/model.py#L107

by the pymc3 internal solution from pymc3.ode, which in turn uses scipy.integrate.odeint

If you think this is sensible, I can give it a try later.

jdehning commented 4 years ago

Not really sure. I didn't know the ode module. But I don't think it is very good approach as it won't work for the SEIR-model (not yet in this repo) as it not only needs the past timestep, but up to 9 in the past. The reason is that we implemented it such that the delay is not exponentially distrubuted, but lognormal.

jdehning commented 4 years ago

Theano has a debug mode, where it stops when nans occur, I will try that next

tarbaig commented 4 years ago

I bet you a beer its the ode solver.

jdehning commented 4 years ago

Deal ;) I learnt today, that there exist a way to implement also the SEIR model with a not-exponential incubation period with an ODE (Erlang-SEIR https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3673147/). So I do now think that it would be sensible to use the pymc3 ode solver for the SIR model. If you still want to do it, go on :) I did try to avoid nans in the SIR model by clipping the infected and susceptible number between 0 and N_population, so I would think that this isn't reason for the errors.

jdehning commented 4 years ago

The error was in the weekend correction, where I used an hierarchical beta distribution. There I forgot to assure, that the sigma is in a correct range, which lead to nans. It is corrected by eb8e4e42ce6f03a2f31739fd790cee85afd0c561