Permalink
Browse files

BUG: fix precision issue with nbinom.pmf. Closes ticket 1779.

  • Loading branch information...
1 parent 9b4c5eb commit 9fc353a8217e1ca319b74ec25982dad745abf98d @rgommers committed Dec 2, 2012
Showing with 7 additions and 2 deletions.
  1. +1 −2 scipy/stats/distributions.py
  2. +6 −0 scipy/stats/tests/test_distributions.py
View
3 scipy/stats/distributions.py
@@ -6529,8 +6529,7 @@ def _rvs(self, n, p):
def _argcheck(self, n, p):
return (n >= 0) & (p >= 0) & (p <= 1)
def _pmf(self, x, n, p):
- coeff = exp(gamln(n+x) - gamln(x+1) - gamln(n))
- return coeff * power(p,n) * power(1-p,x)
+ return exp(self._logpmf(x, n, p))
def _logpmf(self, x, n, p):
coeff = gamln(n+x) - gamln(x+1) - gamln(n)
return coeff + n*log(p) + x*log(1-p)
View
6 scipy/stats/tests/test_distributions.py
@@ -160,6 +160,12 @@ def test_rvs(self):
assert_(isinstance(val, numpy.ndarray))
assert_(val.dtype.char in typecodes['AllInteger'])
+ def test_pmf(self):
+ # regression test for ticket 1779
+ assert_allclose(np.exp(stats.nbinom.logpmf(700, 721, 0.52)),
+ stats.nbinom.pmf(700, 721, 0.52))
+
+
class TestGeom(TestCase):
def test_rvs(self):
vals = stats.geom.rvs(0.75, size=(2, 50))

0 comments on commit 9fc353a

Please sign in to comment.