[SciPy-dev] Definition of gammaln(x) for negative x
G-J van Rooyen
gvrooyen@gmail....
Sat Nov 1 11:54:23 CDT 2008
Hey everyone
Ticket #737 refers:
-----
Gamma in negative for negative x whose floor value is odd. As such,
gammaln does not make sense for those values (while staying in the
real domain, at least). scipy.special.gammaln returns bogus values:
import numpy as np
from scipy.special import gamma, gammaln
print np.log(gamma(-0.5))
print gammaln(-0.5)
Returns nan in the first case (expected) and 1.26551212348 in the
second (totally meaningless value).
-----
The info line for gammaln reads:
* gammaln -- Log of the absolute value of the gamma function.
With this definition of gammaln, the function actually works fine,
since np.log(abs(gamma(-0.5))) is in fact 1.2655. However, this seems
to be an unusual definition for gammaln. What is the best way to fix
it? Options:
1) Keep it as it is, with gammaln(x) = ln|gamma(x)|
2) Change it so that it returns NaN for negative values of gamma(x)
(i.e. negative x whose floor value is odd)
3) Change it to always give NaN for negative values of x (Matlab's approach)
4) Have it return complex values for negative logarithms
Which is best?
G-J
More information about the Scipy-dev
mailing list