user3771231
user3771231

Reputation: 3

How to convolve two distirbutions from scipy library

I have seen (by researching) convolution being done via numpy, but if I wish to convolve two standard distributions (specifically a normal with a uniform) which are readily available in the scipy library, is there a direct way of doing it rather than creating two arrays via numpy and convolve?

Upvotes: 0

Views: 259

Answers (1)

Robert Dodier
Robert Dodier

Reputation: 17576

In general, computing convolutions for distributions requires solving integrals. I worked on this problem as part of the work for my dissertation [1] and wrote some Java (rather idiosyncratic) to carry out the operations. Basically my approach was to make a catalog of distributions for which there are known results, and fall back on a numerical method (convolution via discretization and FFT) if there is no known result.

For the combination of a Gaussian and a uniform, the result is like a Gaussian bump split into two and pasted onto each end of a uniform distribution, when the uniform is wide enough, otherwise it just looks like a bump. I can try to find formulas for that if you are interested.

You can try to compute the integrals via a symbolic computation system such as Maxima. [2] For example, Maxima says the convolution of a unit Gaussian with a unit uniform is:

-(erf((sqrt(2)*s-sqrt(2))/2)-erf(s/sqrt(2)))/2

[1] http://riso.sourceforge.net/docs/dodier-dissertation.pdf (in particular section C.3.17)

[2] http://sourceforge.net/p/maxima

Upvotes: 1

Related Questions