pennsignals / bayes-chime

Bayesian fit to SEIR model. An extension to Penn Medicine's CHIME tool.
MIT License
28 stars 18 forks source link

RuntimeWarning: overflow encountered in exp #68

Closed Mdraugelis closed 4 years ago

Mdraugelis commented 4 years ago

Unexpected overflow warnings

/chime_sims/_99_shared_functions.py:134: RuntimeWarning: overflow encountered in exp

and

/home/datascience/miked/chime_sims/_02_munge_chains.py:15: RuntimeWarning: overflow encountered in exp

cjbayesian commented 4 years ago

@Mdraugelis These warnings happened when running the master branch, correct?

cjbayesian commented 4 years ago

First overflow is happening in:

def logistic(L, k, x0, x):
    return L / (1 + np.exp(-k * (x - x0)))

And the second one is happening in the same function inside of _02_munge_chains.py.

I wouldn't expect the second instance as the the first overflow should have resulted in the proposed parameter location being rejected and therefor not being retained in the posterior chain for post-processing.

cjbayesian commented 4 years ago

np.exp will overflow for arguments >~ 710.0 on a 64 bit architecture (max floating point values ~ 8.218407461554972e+307). This results in the runtime warning you're seeing:

In [9]: np.exp(1000)                                                                                                                                          
/home/datascience/anaconda3/bin/ipython:1: RuntimeWarning: overflow encountered in exp
  #!/home/datascience/anaconda3/bin/python
Out[9]: inf

However, when this happens, the logistic function returns 0.0 as (float(x)/np.inf) == 0.0:

In [12]: logistic(10, 1000, 1, 0)                                                                                                                             
/home/datascience/anaconda3/bin/ipython:2: RuntimeWarning: overflow encountered in exp

Out[12]: 0.0

Therefore, this overflow can happen and nevertheless yield a valid likelihood value.

cjbayesian commented 4 years ago

We may want to catch that overflow explicitly and have logistic return np.nan so that those regions of the parameter space are explicitly rejected.

Mdraugelis commented 4 years ago

got it. thanks for investigating. And I ran this on acd_dev. I should have noted that. I did not see this warning on the master.