Suppose that it is necessary to calculate the convolution of the total number of discrete probability density functions. The following example shows four distributions that take values โโof 0,1,2 with given probabilities:
import numpy as np pdfs = np.array([[0.6,0.3,0.1],[0.5,0.4,0.1],[0.3,0.7,0.0],[1.0,0.0,0.0]])
A convolution can be found as follows:
pdf = pdfs[0] for i in range(1,pdfs.shape[0]): pdf = np.convolve(pdfs[i], pdf)
The probabilities of seeing 0,1, ..., 8 are then given by the expression
array([ 0.09 , 0.327, 0.342, 0.182, 0.052, 0.007, 0. , 0. , 0. ])
This part is a bottleneck in my code, and there seems to be something available to vectorize this operation. Does anyone have a suggestion to do this faster?
Alternatively, a solution in which you could use
pdf1 = np.array([[0.6,0.3,0.1],[0.5,0.4,0.1]]) pdf2 = np.array([[0.3,0.7,0.0],[1.0,0.0,0.0]]) convolve(pd1,pd2)
and get pairwise convolutions
array([[ 0.18, 0.51, 0.24, 0.07, 0. ], [ 0.5, 0.4, 0.1, 0. , 0. ]])
also very helpful.