def expectation_z_quad(mu, var, L, w = 3):
"""
USE QUAD (NUMERICAL INTEGRATION)
Evaluate the expectation of log[ S(u)^L (1-S(u))^(1-L) ]
when u ~ Normal(mu, var)
"""
#U = np.random.normal(mu, np.sqrt(var), num)
if L == 1:
f = lambda u: scipy.stats.norm.pdf(u, loc = mu, scale = np.sqrt(var) ) * np.log(S(u))
else:
f = lambda u: scipy.stats.norm.pdf(u, loc = mu, scale = np.sqrt(var) ) * (np.log(1 - S(u)))
#return f
std = np.sqrt(var)
#return scipy.integrate.quad(f, mu - w*std, mu + w*std, epsabs = 1.0e-4, epsrel = 1.0e-4, limit = 25)[0]
return scipy.integrate.quad(f, mu - w*std, mu + w*std)[0]
评论列表
文章目录