scipy/scipy — pull request #2844 by EvgeniBurovski (2013-09-08 19:07:19+00:00)
Title: avoid spurious divergencies in .expect

For continuous distributions with unbounded support, `expect` returns spurious `inf`s in some cases. This can be traced to floating-point errors which make a distribution function an `inf`. For example:

```
>>> stats.rice.expect(lambda x: 1, args=(0.73,))
/home/br/virtualenvs/scipy-dev/local/lib/python2.7/site-packages/scipy/stats/distributions.py:5555: RuntimeWarning: invalid value encountered in multiply
return x*exp(-(x*x+b*b)/2.0)*special.i0(x*b)
/home/br/virtualenvs/scipy-dev/local/lib/python2.7/site-packages/scipy/integrate/quadpack.py:293: UserWarning: The occurrence of roundoff error is detected, which prevents the requested tolerance from being achieved. The error may be underestimated.
warnings.warn(msg)
nan
```
While usually `quad` does an excellent job at doing integrals over the infinite support, here it cannot work it magic --- the function it tries to integrate overflows to infinity.

This PR implements a bit of heuristics in order to detect such situations and try adjusting the integration bounds to make them large but finite. Basically, it's a version of 'try integrating from -100 to 100' course of action, only very slightly more flexible.

The price to pay is that for diverging integrals, `expect` might produce a large but finite number and a warning.