This is my first question on the site! I want to get the sum of two (or more) random variables, so I did this
from scipy.stats import exponweib
import numpy as np
import matplotlib.pyplot as plt
# Parameters
shape, scale, delta = 1.3, 12, 1e-2
dist = exponweib(a=1, loc=0, c=shape, scale=scale)
grid = np.arange(0, 100, delta)
pmfs = dist.pdf(grid)*delta
# Do convolution (?)
def conv(a,b):
x = np.array([sum(a[:i+1]*b[i::-1]) for i in range(len(a))])
return x
# Loop to convolve over multiple RVs
c = {1: pmfs}
for i in range(2, 4):
c[i] = conv(c[i-1], pmfs)
plt.plot(grid, c[1])
plt.plot(grid, c[2])
plt.plot(grid, c[3]);
So, this gets me this, which looks like what I want, but it is super slow to run.
I want to implement this equation to sum two independent random variables and get their discretized PDF. Other questions suggested to use scipy.signal.fftconvolve
x = fftconvolve(pmfs, pmfs, 'same')
plt.plot(grid, x);
But it got me this. Why is it different?
