-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
defectA clear bug or issue that prevents SciPy from being installed or used as expectedA clear bug or issue that prevents SciPy from being installed or used as expectedscipy.stats
Milestone
Description
There's a part of the gengamma distribution code that divides two gamma functions. As a result, The mean of the distribution is nan
for values of a
> ~170.
from scipy import special
import numpy as np
n = -2
a = 200
c = 1.
# Calcuate the mean (gives nan)
print(scipy.stats.distributions.gengamma(a, n, scale=c).mean())
# Function used in _munp (gives nan)
print(special.gamma(a+n*1.0/c) / special.gamma(a))
# Possible fix for large argument values? (gives correct answer)
print(np.exp(special.gammaln(a+n*1.0/c) - special.gammaln(a)))
Perhaps this in scipy/stats/_continuous_distns.py:2041
?
def _munp(self, n, a, c):
if a > 170 or a+n*1.0/c > 170:
return np.exp(gamln(a+n*1.0/c) - gamln(a))
return special.gamma(a+n*1.0/c) / special.gamma(a)
But I am unsure if this catches all edge cases including positive/negative large/small values of n
and c
.
Metadata
Metadata
Assignees
Labels
defectA clear bug or issue that prevents SciPy from being installed or used as expectedA clear bug or issue that prevents SciPy from being installed or used as expectedscipy.stats