[Scipy-svn] r5137 - trunk/scipy/stats/tests

scipy-svn at scipy.org scipy-svn at scipy.org
Sun Nov 16 18:27:18 EST 2008


Author: josef
Date: 2008-11-16 17:27:15 -0600 (Sun, 16 Nov 2008)
New Revision: 5137

Modified:
   trunk/scipy/stats/tests/test_continuous_basic.py
   trunk/scipy/stats/tests/test_continuous_extra.py
   trunk/scipy/stats/tests/test_discrete_basic.py
Log:
add skew, kurtosis and entropy test to discrete rv, add tests for 2 tickets, some cleanup of messages

Modified: trunk/scipy/stats/tests/test_continuous_basic.py
===================================================================
--- trunk/scipy/stats/tests/test_continuous_basic.py	2008-11-16 20:36:10 UTC (rev 5136)
+++ trunk/scipy/stats/tests/test_continuous_basic.py	2008-11-16 23:27:15 UTC (rev 5137)
@@ -71,6 +71,7 @@
     ['levy_l', ()],
 #    ['levy_stable', (0.35667405469844993,
 #                     -0.67450531578494011)], #NotImplementedError
+    #           rvs not tested
     ['loggamma', (0.41411931826052117,)],
     ['logistic', ()],
     ['loglaplace', (3.2505926592051435,)],
@@ -89,6 +90,7 @@
     ['powernorm', (4.4453652254590779,)],
     ['rayleigh', ()],
     ['rdist', (3.8266985793976525,)],
+    ['rdist', (541.0,)],   # from ticket #758
     ['recipinvgauss', (0.63004267809369119,)],
     ['reciprocal', (0.0062309367010521255, 1.0062309367010522)],
     ['rice', (0.7749725210111873,)],

Modified: trunk/scipy/stats/tests/test_continuous_extra.py
===================================================================
--- trunk/scipy/stats/tests/test_continuous_extra.py	2008-11-16 20:36:10 UTC (rev 5136)
+++ trunk/scipy/stats/tests/test_continuous_extra.py	2008-11-16 23:27:15 UTC (rev 5137)
@@ -24,9 +24,8 @@
         yield check_loc_scale, distfn, arg, distname + \
               ' loc, scale test'
         #entropy test checks only for isnan, currently 6 isnan
-        #
 ##        yield check_entropy, distfn, arg, distname + \
-##              ' loc, scale test'
+##              ' entropy nan test'
 
 
 def check_ppf_limits(distfn,arg,msg):

Modified: trunk/scipy/stats/tests/test_discrete_basic.py
===================================================================
--- trunk/scipy/stats/tests/test_discrete_basic.py	2008-11-16 20:36:10 UTC (rev 5136)
+++ trunk/scipy/stats/tests/test_discrete_basic.py	2008-11-16 23:27:15 UTC (rev 5137)
@@ -4,6 +4,8 @@
 
 from scipy import stats
 
+DECIMAL_meanvar = 0#1  # was 0
+
 distdiscrete = [
     ['bernoulli',(0.3,)],
     ['binom',    (5, 0.4)],
@@ -13,12 +15,16 @@
     ['hypergeom',(30, 12, 6)],
     ['logser',   (0.6,)],
     ['nbinom',   (5, 0.5)],
+    ['nbinom',   (0.4, 0.4)], #from tickets: 583
     ['planck',   (0.51,)],   #4.1
     ['poisson',  (0.6,)],
     ['randint',  (7, 31)],
     ['zipf',     (4,)] ]   # arg=4 is ok,
                            # Zipf broken for arg = 2, e.g. weird .stats
+                           # looking closer, mean, var should be inf for arg=2
 
+
+
 def test_discrete_basic():
     for distname, arg in distdiscrete:
         distfn = getattr(stats,distname)
@@ -27,11 +33,16 @@
         m,v = distfn.stats(*arg)
         #yield npt.assert_almost_equal(rvs.mean(), m, decimal=4,err_msg='mean')
         #yield npt.assert_almost_equal, rvs.mean(), m, 2, 'mean' # does not work
-        yield check_sample_mean, rvs.mean(), m, distname + 'sample mean test'
-        yield check_sample_mean, rvs.var(), v, distname + 'sample var test'
-        yield check_cdf_ppf, distfn, arg
-        yield check_pmf_cdf, distfn, arg
-        yield check_oth, distfn, arg
+        yield check_sample_meanvar, rvs.mean(), m, distname + 'sample mean test'
+        yield check_sample_meanvar, rvs.var(), v, distname + 'sample var test'
+        yield check_cdf_ppf, distfn, arg, distname
+        yield check_pmf_cdf, distfn, arg, distname
+        yield check_oth, distfn, arg, distname
+        skurt = stats.kurtosis(rvs)
+        sskew = stats.skew(rvs)
+        yield check_sample_skew_kurt, distfn, arg, skurt, sskew, distname
+        yield check_entropy, distfn, arg, distname + \
+              ' entropy nan test'
 
 def test_discrete_private():
     #testing private methods mostly for debugging
@@ -43,36 +54,36 @@
         m,v = distfn.stats(*arg)
 
         yield check_ppf_ppf, distfn, arg
-        yield check_cdf_ppf_private, distfn, arg
+        yield check_cdf_ppf_private, distfn, arg, distname
         yield check_generic_moment, distfn, arg, m, 1, 3   # last is decimal
         yield check_generic_moment, distfn, arg, v+m*m, 2, 3 # last is decimal
         yield check_moment_frozen, distfn, arg, m, 1, 3   # last is decimal
         yield check_moment_frozen, distfn, arg, v+m*m, 2, 3 # last is decimal
 
 
-def check_sample_mean(sm,m,msg):
-    if m < np.inf:
-        npt.assert_almost_equal(sm, m, decimal=0, err_msg=msg + \
+def check_sample_meanvar(sm,m,msg):
+    if not np.isinf(m):
+        npt.assert_almost_equal(sm, m, decimal=DECIMAL_meanvar, err_msg=msg + \
                                 ' - finite moment')
     else:
         assert sm > 10000, 'infinite moment, sm = ' + str(sm)
 
-def check_sample_var(sm,m):
-    npt.assert_almost_equal(sm, m, decimal=0, err_msg= 'var')
+def check_sample_var(sm,m,msg):
+    npt.assert_almost_equal(sm, m, decimal=DECIMAL_meanvar, err_msg= msg + 'var')
 
-def check_cdf_ppf(distfn,arg):
+def check_cdf_ppf(distfn,arg,msg):
     ppf05 = distfn.ppf(0.5,*arg)
     cdf05 = distfn.cdf(ppf05,*arg)
     npt.assert_almost_equal(distfn.ppf(cdf05-1e-6,*arg),ppf05,
-                            err_msg=str(distfn) + 'ppf-cdf-median')
-    assert (distfn.ppf(cdf05+1e-4,*arg)>ppf05), str(distfn) + 'ppf-cdf-next'
+                            err_msg=msg + 'ppf-cdf-median')
+    assert (distfn.ppf(cdf05+1e-4,*arg)>ppf05), msg + 'ppf-cdf-next'
 
-def check_cdf_ppf_private(distfn,arg):
+def check_cdf_ppf_private(distfn,arg,msg):
     ppf05 = distfn._ppf(0.5,*arg)
     cdf05 = distfn.cdf(ppf05,*arg)
     npt.assert_almost_equal(distfn._ppf(cdf05-1e-6,*arg),ppf05,
-                            err_msg=str(distfn) + 'ppf-cdf-median')
-    assert (distfn._ppf(cdf05+1e-4,*arg)>ppf05), str(distfn) + 'ppf-cdf-next'
+                            err_msg=msg + '_ppf-cdf-median ')
+    assert (distfn._ppf(cdf05+1e-4,*arg)>ppf05), msg + '_ppf-cdf-next'
 
 def check_ppf_ppf(distfn, arg):
     assert distfn.ppf(0.5,*arg) < np.inf
@@ -84,13 +95,13 @@
     assert ppf_s[0] == ppfs[0]
     assert ppf_s[1] == ppfs[1]
 
-def check_pmf_cdf(distfn, arg):
+def check_pmf_cdf(distfn, arg, msg):
     startind = np.int(distfn._ppf(0.01,*arg)-1)
     index = range(startind,startind+10)
     cdfs = distfn.cdf(index,*arg)
     npt.assert_almost_equal(cdfs, distfn.pmf(index, *arg).cumsum() + \
                             cdfs[0] - distfn.pmf(index[0],*arg),
-                            decimal=4, err_msg='pmf-cdf')
+                            decimal=4, err_msg= msg + 'pmf-cdf')
 
 def check_generic_moment(distfn, arg, m, k, decim):
     npt.assert_almost_equal(distfn.generic_moment(k,*arg), m, decimal=decim,
@@ -100,7 +111,7 @@
     npt.assert_almost_equal(distfn(*arg).moment(k), m, decimal=decim,
                             err_msg= str(distfn) + ' frozen moment test')
 
-def check_oth(distfn, arg):
+def check_oth(distfn, arg, msg):
     #checking other methods of distfn
     meanint = round(distfn.stats(*arg)[0]) # closest integer to mean
     npt.assert_almost_equal(distfn.sf(meanint, *arg), 1 - \
@@ -112,5 +123,17 @@
     npt.assert_equal(distfn.isf(0.5, *arg), distfn.ppf(0.5, *arg))
 
 
+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'
+    check_sample_meanvar, ss, s, msg + 'sample kurtosis test'
+
+
+def check_entropy(distfn,arg,msg):
+    ent = distfn.entropy(*arg)
+    #print 'Entropy =', ent
+    assert not np.isnan(ent), msg + 'test Entropy is nan'\
+
 if __name__ == "__main__":
-    nose.run(argv=['', __file__])
+    #nose.run(argv=['', __file__])
+    nose.runmodule(argv=[__file__,'-s'], exit=False)




More information about the Scipy-svn mailing list