Permalink
Browse files

BUG: fix stats.distributions.geom.logpmf bug. Closes #1793.

Thanks to Jonathan Scholz.
  • Loading branch information...
1 parent 51fa54c commit ef851906a948b2b0422170ccb641c86e3e8e2d0c @rgommers rgommers committed Dec 17, 2012
Showing with 7 additions and 1 deletion.
  1. +1 −1 scipy/stats/distributions.py
  2. +6 −0 scipy/stats/tests/test_distributions.py
View
2 scipy/stats/distributions.py
@@ -6582,7 +6582,7 @@ def _argcheck(self, p):
def _pmf(self, k, p):
return (1-p)**(k-1) * p
def _logpmf(self, k, p):
- return (k-1)*log(1-p) + p
+ return (k-1)*log(1-p) + log(p)
def _cdf(self, x, p):
k = floor(x)
return (1.0-(1.0-p)**k)
View
6 scipy/stats/tests/test_distributions.py
@@ -182,6 +182,12 @@ def test_pmf(self):
vals = stats.geom.pmf([1,2,3],0.5)
assert_array_almost_equal(vals,[0.5,0.25,0.125])
+ def test_logpmf(self):
+ # regression test for ticket 1793
+ vals1 = np.log(stats.geom.pmf([1,2,3], 0.5))
+ vals2 = stats.geom.logpmf([1,2,3], 0.5)
+ assert_allclose(vals1, vals2, rtol=1e-15, atol=0)
+
def test_cdf_sf(self):
vals = stats.geom.cdf([1,2,3],0.5)
vals_sf = stats.geom.sf([1,2,3],0.5)

0 comments on commit ef85190

Please sign in to comment.