-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvolution.py
More file actions
40 lines (31 loc) · 1.28 KB
/
convolution.py
File metadata and controls
40 lines (31 loc) · 1.28 KB
1
#!/opt/local/bin/pythonimport numpy as npimport scipy.special# ex-Gaussian distributiondef convolve_exp_norm(alpha, mu, sigma, x): co = alpha/2.0 * np.exp( alpha*mu+ alpha*alpha*sigma*sigma/2.0) x_erf = (mu + alpha*sigma*sigma - x)/(np.sqrt(2.0)*sigma) y = co * np.exp(-alpha*x) * (1.0 - scipy.special.erf(x_erf)) return y# input parametersx = np.arange(-5.0,5.0,0.1)alpha = 1.0 # index of the exponential functionsigma = 0.5 # dispersion of the normal distributionmu = -0.5 # center of the normal distributionexponential = []for i in range(len(x)): value = alpha * np.exp(-alpha*x[i]) if (x[i]>=0.0) else 0.0 exponential.append(value)np.array(exponential)normal = 1.0/(sqrt(2.0*np.pi)*sigma) * np.exp(-(x-mu)*(x-mu)/(2.0*sigma*sigma))# convolveconvolution = convolve_exp_norm(alpha, mu, sigma, x)# plot resultplot(x,convolution,color='red',linewidth=2.0)plot(x,exponential,color='blue')plot(x,normal,color='green')legend(('Exponentially modified Gaussian','Exponential Distribution (input)','Normal Distribution (input)'),frameon=False)xlim(-2,5)text(3.0,0.7,r'$\lambda=1.5$',fontsize=20,verticalalignment='center')text(3.0,0.6,r'$\mu=-0.5$',fontsize=20,verticalalignment='center')text(3.0,0.5,r'$\sigma=0.5$',fontsize=20,verticalalignment='center')