Skip to content

Commit

Permalink
ENH: improve accuracy of distributions.ncx2, add logpdf method. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
rgommers committed Aug 22, 2011
1 parent ff96ef0 commit 98c9f7c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions scipy/stats/distributions.py
Expand Up @@ -4351,11 +4351,12 @@ class ncx2_gen(rv_continuous):
""" """
def _rvs(self, df, nc): def _rvs(self, df, nc):
return mtrand.noncentral_chisquare(df,nc,self._size) return mtrand.noncentral_chisquare(df,nc,self._size)
def _pdf(self, x, df, nc): def _logpdf(self, x, df, nc):
a = arr(df/2.0) a = arr(df/2.0)
Px = exp(-nc/2.0)*special.hyp0f1(a,nc*x/4.0) fac = -nc/2.0 - x/2.0 + (a-1)*np.log(x) - a*np.log(2) - special.gammaln(a)
Px *= exp(-x/2.0)*x**(a-1) / arr(2**a * special.gamma(a)) return fac + np.nan_to_num(np.log(special.hyp0f1(a, nc * x/4.0)))
return Px def _pdf(self, x, df, nc):
return np.exp(self._logpdf(x, df, nc))
def _cdf(self, x, df, nc): def _cdf(self, x, df, nc):
return special.chndtr(x,df,nc) return special.chndtr(x,df,nc)
def _ppf(self, q, df, nc): def _ppf(self, q, df, nc):
Expand Down

0 comments on commit 98c9f7c

Please sign in to comment.