Returns the logarithm of the gamma function.
(x)
| 813 | # See also: http://www.mhtl.uwaterloo.ca/courses/me755/web_chap1.pdf |
| 814 | |
| 815 | def gammaln(x): |
| 816 | """ Returns the logarithm of the gamma function. |
| 817 | """ |
| 818 | x = x - 1.0 |
| 819 | y = x + 5.5 |
| 820 | y = (x + 0.5) * log(y) - y |
| 821 | n = 1.0 |
| 822 | for i in range(6): |
| 823 | x += 1 |
| 824 | n += (76.18009173, -86.50532033, 24.01409822, -1.231739516e0, 0.120858003e-2, -0.536382e-5)[i] / x |
| 825 | return y + log(2.50662827465 * n) |
| 826 | |
| 827 | def gamma(x): |
| 828 | return exp(gammaln(x)) |