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

scipy-svn at scipy.org scipy-svn at scipy.org
Tue Nov 18 13:38:36 EST 2008


Author: josef
Date: 2008-11-18 12:35:08 -0600 (Tue, 18 Nov 2008)
New Revision: 5147

Modified:
   trunk/scipy/stats/distributions.py
   trunk/scipy/stats/tests/test_discrete_basic.py
Log:
correct boundary and out-of-boundary return of isf analogously to ppf, add test for this

Modified: trunk/scipy/stats/distributions.py
===================================================================
--- trunk/scipy/stats/distributions.py	2008-11-18 15:32:54 UTC (rev 5146)
+++ trunk/scipy/stats/distributions.py	2008-11-18 18:35:08 UTC (rev 5147)
@@ -1754,8 +1754,8 @@
 class genextreme_gen(rv_continuous):
     def _argcheck(self, c):
         self.b = where(c > 0, 1.0 / c, inf)
-        self.a = where(c < 0, 1.0 / c, -inf)
-        return (c==c) #True #(c!=0)
+        self.a = where(c < 0, 1.0 / c, -inf)       
+        return (c==c) #True #(c!=0) #see ticket:793
     def _pdf(self, x, c):
         ##        ex2 = 1-c*x
         ##        pex2 = pow(ex2,1.0/c)
@@ -3789,15 +3789,19 @@
         cond1 = (q > 0) & (q < 1)
         cond2 = (q==1) & cond0
         cond = cond0 & cond1
-        output = valarray(shape(cond),value=self.b,typecode='d')
-        #typecode 'd' to handle nin and inf
-        place(output,(1-cond0)*(cond1==cond1), self.badvalue)
-        place(output,cond2,self.a-1)
+        #old:
+##        output = valarray(shape(cond),value=self.b,typecode='d')
+##        #typecode 'd' to handle nin and inf
+##        place(output,(1-cond0)*(cond1==cond1), self.badvalue)
+##        place(output,cond2,self.a-1)
 
-
         #same problem as with ppf
+        # copied from ppf and changed
+        output = valarray(shape(cond),value=self.badvalue,typecode='d')
+        #output type 'd' to handle nin and inf
+        place(output,(q==0)*(cond==cond), self.b)
+        place(output,cond2,self.a-1)
 
-
         # call place only if at least 1 valid argument
         if any(cond):
             goodargs = argsreduce(cond, *((q,)+args+(loc,)))

Modified: trunk/scipy/stats/tests/test_discrete_basic.py
===================================================================
--- trunk/scipy/stats/tests/test_discrete_basic.py	2008-11-18 15:32:54 UTC (rev 5146)
+++ trunk/scipy/stats/tests/test_discrete_basic.py	2008-11-18 18:35:08 UTC (rev 5147)
@@ -44,6 +44,14 @@
         yield check_entropy, distfn, arg, distname + \
               ' entropy nan test'
 
+def test_discrete_extra():
+    for distname, arg in distdiscrete:
+        distfn = getattr(stats,distname)
+        yield check_ppf_limits, distfn, arg, distname + \
+              ' ppf limit test'
+        yield check_isf_limits, distfn, arg, distname + \
+              ' isf limit test'
+
 def _est_discrete_private():
     #testing private methods mostly for debugging
     #   some tests might fail by design,
@@ -122,7 +130,36 @@
     assert distfn.cdf(median_sf + 1, *arg) > 0.5
     npt.assert_equal(distfn.isf(0.5, *arg), distfn.ppf(0.5, *arg))
 
+#next 3 functions copied from test_continous_extra
+#    adjusted
+    
+def check_ppf_limits(distfn,arg,msg):
+    below,low,upp,above = distfn.ppf([-1,0,1,2], *arg)
+    #print distfn.name, distfn.a, low, distfn.b, upp
+    #print distfn.name,below,low,upp,above
+    assert_equal_inf_nan(distfn.a-1,low, msg + 'ppf lower bound')
+    assert_equal_inf_nan(distfn.b,upp, msg + 'ppf upper bound')
+    assert np.isnan(below), msg + 'ppf out of bounds - below'
+    assert np.isnan(above), msg + 'ppf out of bounds - above'
 
+def check_isf_limits(distfn,arg,msg):
+    below,low,upp,above = distfn.isf([-1,0,1,2], *arg)
+    #print distfn.name, distfn.a, low, distfn.b, upp
+    #print distfn.name,below,low,upp,above
+    assert_equal_inf_nan(distfn.a-1,upp, msg + 'isf lower bound')
+    assert_equal_inf_nan(distfn.b,low, msg + 'isf upper bound')
+    assert np.isnan(below), msg + 'isf out of bounds - below'
+    assert np.isnan(above), msg + 'isf out of bounds - above'
+
+def assert_equal_inf_nan(v1,v2,msg):
+    assert not np.isnan(v1)
+    if not np.isinf(v1):
+        npt.assert_almost_equal(v1, v2, decimal=10, err_msg = msg + \
+                                   ' - finite')
+    else:
+        assert np.isinf(v2) or np.isnan(v2), \
+               msg + ' - infinite, v2=%s' % str(v2)
+
 def check_sample_skew_kurt(distfn, arg, sk, ss, msg):
     k,s = distfn.stats(moment='ks',*arg)
     check_sample_meanvar, sk, k, msg + 'sample skew test'




More information about the Scipy-svn mailing list