Best way to write a Python function that integrates a gaussian?

前端 未结 5 1175
小鲜肉
小鲜肉 2021-02-04 18:48

In attempting to use scipy\'s quad method to integrate a gaussian (lets say there\'s a gaussian method named gauss), I was having problems passing needed parameters to gauss and

5条回答
  •  太阳男子
    2021-02-04 19:06

    I assume you're handling multivariate Gaussians; if so, SciPy already has the function you're looking for: it's called MVNDIST ("MultiVariate Normal DISTribution). The SciPy documentation is, as ever, terrible, so I can't even find where the function is buried, but it's in there somewhere. The documentation is easily the worst part of SciPy, and has frustrated me to no end in the past.

    Single-variable Gaussians just use the good old error function, of which many implementations are available.

    As for attacking the problem in general, yes, as James Thompson mentions, you just want to write your own gaussian distribution function and feed it to quad(). If you can avoid the generalized integration, though, it's a good idea to do so -- specialized integration techniques for a particular function (like MVNDIST uses) are going to be much faster than a standard Monte Carlo multidimensional integration, which can be extremely slow for high accuracy.

提交回复
热议问题