crowd_model.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:code-uai16 作者: thanhan 项目源码 文件源码
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]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号