[Scipy-svn] r7093 - in trunk/scipy/stats: . tests

scipy-svn at scipy.org scipy-svn at scipy.org
Fri Jan 28 17:56:06 EST 2011


Author: rkern
Date: 2011-01-28 16:56:05 -0600 (Fri, 28 Jan 2011)
New Revision: 7093

Modified:
   trunk/scipy/stats/distributions.py
   trunk/scipy/stats/tests/test_distributions.py
Log:
BUG: Fix the lambda<=0 case for the Tukey-Lambda distribution.

Modified: trunk/scipy/stats/distributions.py
===================================================================
--- trunk/scipy/stats/distributions.py	2011-01-28 13:58:22 UTC (rev 7092)
+++ trunk/scipy/stats/distributions.py	2011-01-28 22:56:05 UTC (rev 7093)
@@ -4362,7 +4362,7 @@
         Fx = arr(special.tklmbda(x,lam))
         Px = Fx**(lam-1.0) + (arr(1-Fx))**(lam-1.0)
         Px = 1.0/arr(Px)
-        return where((lam > 0) & (abs(x) < 1.0/lam), Px, 0.0)
+        return where((lam <= 0) | (abs(x) < 1.0/arr(lam)), Px, 0.0)
     def _cdf(self, x, lam):
         return special.tklmbda(x, lam)
     def _ppf(self, q, lam):

Modified: trunk/scipy/stats/tests/test_distributions.py
===================================================================
--- trunk/scipy/stats/tests/test_distributions.py	2011-01-28 13:58:22 UTC (rev 7092)
+++ trunk/scipy/stats/tests/test_distributions.py	2011-01-28 22:56:05 UTC (rev 7093)
@@ -666,6 +666,19 @@
     #adjust to avoid nan with 0*log(0)
     assert_almost_equal(stats.chi2.pdf(0.0, 2), 0.5, 14)
 
+def test_regression_tukey_lambda():
+    """ Make sure that Tukey-Lambda distribution correctly handles non-positive lambdas.
+    """
+    x = np.linspace(-5.0, 5.0, 101)
+    for lam in [0.0, -1.0, -2.0, np.array([[-1.0], [0.0], [-2.0]])]:
+        p = stats.tukeylambda._pdf(x, lam)
+        assert_((p != 0.0).all())
+    lam = np.array([[-1.0], [0.0], [2.0]])
+    p = stats.tukeylambda._pdf(x, lam)
+    assert_((p[0] != 0.0).all())
+    assert_((p[1] != 0.0).all())
+    assert_((p[2] != 0.0).any())
+    assert_((p[2] == 0.0).any())
 
 if __name__ == "__main__":
     run_module_suite()




More information about the Scipy-svn mailing list