Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for stats.lognorm.pdf(0,s) reports nan

  • Loading branch information...
commit 560f23d02af4cf9f581312073903e8cb8e01488d 1 parent 2619f0c
@pbrod pbrod authored
View
5 scipy/stats/distributions.py
@@ -4165,8 +4165,9 @@ class lognorm_gen(rv_continuous):
def _rvs(self, s):
return exp(s * norm.rvs(size=self._size))
def _pdf(self, x, s):
- Px = exp(-log(x)**2 / (2*s**2))
- return Px / (s*x*sqrt(2*pi))
+ return exp(self._logpdf(x, s))
+ def _logpdf(self, x, s):
+ return -log(x)**2 / (2*s**2) + np.where(x==0 , 0, - log(s*x*sqrt(2*pi)))
def _cdf(self, x, s):
return norm.cdf(log(x)/s)
def _ppf(self, q, s):
View
7 scipy/stats/tests/test_distributions.py
@@ -410,6 +410,13 @@ def test_cdf(self):
assert_almost_equal(stats.skellam.cdf(k, mu1, mu2), skcdfR, decimal=5)
+class TestLognorm(TestCase):
+ def test_pdf(self):
+ ''' Regression test for Ticket #1471:
+ cornercase avoid nan with 0/0 situation
+ '''
+ pdf = stats.lognorm.pdf(0,1)
+ assert_almost_equal(pdf, 0.0)
class TestGamma(TestCase):
Please sign in to comment.
Something went wrong with that request. Please try again.