1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
Description: Don't use gammaln on complex input
In scipy >= 1.0, it rejects such input with
TypeError: ufunc 'gammaln' not supported for the input types, and the
inputs could not be safely coerced to any supported types according
to the casting rule ''safe''
Author: Kevin "bashtage" Sheppard, Rebecca N. Palmer <rebecca_palmer@zoho.com>
Origin: upstream https://github.com/statsmodels/statsmodels/pull/3964/commits/c11c6242ff81a0f83d3e7fd83a8105397d3cbc1d
Forwarded: not-needed
--- statsmodels-0.8.0.orig/statsmodels/discrete/discrete_model.py
+++ statsmodels-0.8.0/statsmodels/discrete/discrete_model.py
@@ -22,6 +22,10 @@ __all__ = ["Poisson", "Logit", "Probit",
from statsmodels.compat.python import lmap, lzip, range
import numpy as np
from scipy.special import gammaln
+try:
+ from scipy.special import loggamma
+except ImportError:
+ loggamma = gammaln
from scipy import stats, special, optimize # opt just for nbin
import statsmodels.tools.tools as tools
from statsmodels.tools import data as data_tools
@@ -2004,12 +2008,16 @@ class NegativeBinomial(CountModel):
self._initialize()
def _ll_nbin(self, params, alpha, Q=0):
+ if np.any(np.iscomplex(params)) or np.iscomplex(alpha):
+ gamma_ln = loggamma
+ else:
+ gamma_ln = gammaln
endog = self.endog
mu = self.predict(params)
size = 1/alpha * mu**Q
prob = size/(size+mu)
- coeff = (gammaln(size+endog) - gammaln(endog+1) -
- gammaln(size))
+ coeff = (gamma_ln(size+endog) - gamma_ln(endog+1) -
+ gamma_ln(size))
llf = coeff + size*np.log(prob) + endog*np.log(1-prob)
return llf
|