Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix for Ticket #1842 : wrong value returned by scipy.stats.binom prob…

…ability mass function when true probability is 1

+ a test for it.
  • Loading branch information...
commit c4b390b19df056ab9000f2b4169fa7b2d7222476 1 parent dbaaad3
@pbrod pbrod authored pv committed
View
2  scipy/stats/distributions.py
@@ -6597,7 +6597,7 @@ def _logpmf(self, x, n, p):
k = floor(x)
combiln = (gamln(n+1) - (gamln(k+1) +
gamln(n-k+1)))
- return combiln + k*np.log(p) + (n-k)*np.log(1-p)
+ return combiln + special.xlogy(k,p) + special.xlog1py(n-k, -p)
def _pmf(self, x, n, p):
return exp(self._logpmf(x, n, p))
def _cdf(self, x, n, p):
View
6 scipy/stats/tests/test_distributions.py
@@ -137,6 +137,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 #1842
+ vals1 = stats.binom.pmf(100, 100,1)
+ vals2 = stats.binom.pmf(0, 100,0)
+ assert_allclose(vals1, 1.0, rtol=1e-15, atol=0)
+ assert_allclose(vals2, 1.0, rtol=1e-15, atol=0)
class TestBernoulli(TestCase):
def test_rvs(self):
Please sign in to comment.
Something went wrong with that request. Please try again.