util.py 文件源码

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

项目:pyro 作者: uber 项目源码 文件源码
def log_gamma(xx):
    if isinstance(xx, torch.Tensor):
        xx = Variable(xx)
    ttype = xx.data.type()
    gamma_coeff = [
        76.18009172947146,
        -86.50532032941677,
        24.01409824083091,
        -1.231739572450155,
        0.1208650973866179e-2,
        -0.5395239384953e-5,
    ]
    magic1 = 1.000000000190015
    magic2 = 2.5066282746310005
    x = xx - 1.0
    t = x + 5.5
    t = t - (x + 0.5) * torch.log(t)
    ser = Variable(torch.ones(x.size()).type(ttype)) * magic1
    for c in gamma_coeff:
        x = x + 1.0
        ser = ser + torch.pow(x / c, -1)
    return torch.log(ser * magic2) - t
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号