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
评论列表
文章目录