If I have a random number Z, which is defined as the sum of the sum of two other random numbers , Xand Y, then the probability distribution Zis a convolution of the probability distributions for Xand Y. Convolution is basically an integral of the product of distribution functions. Often there is no analytical solution to the integral in convolution, therefore, it must be calculated using the basic quadrature algorithm. In pseudo code:
prob_z(z) = integrate(lambda t: prob_x(t) * prob_y(z-t), -inf, inf)
For a specific example, the sum of a Znormally distributed variable Xand a logarithmically normally distributed variable Ycan be calculated using the following Python / Scipy code:
from scipy.integrate import quad
from scipy.stats import norm, lognorm
from scipy import log
prob_x = lambda x: norm.pdf(x, 0, 1)
prob_y = lambda y: lognorm.pdf(y, 0.1, scale=10)
def prob_z(z):
return quad(lambda t: prob_x(t)*prob_y(z-t), -inf, inf)
Now I want to calculate the probability of the log. A naive solution is simple:
def log_prob_z(z):
return log(prob_z(z))
. 39 0.0, , , . norm.pdf(39, 1, 0), 0,0 norm.logpdf(39, 1, 0), -761. , Scipy logpdf log(pdf) -it , -inf, . .
( , , . - . , - , , -inf nan.)
: - , log(quad(...)), quad(...) 0.0 ?