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

scipy-svn@scip... scipy-svn@scip...
Tue Jun 1 05:10:30 CDT 2010


Author: oliphant
Date: 2010-06-01 05:10:30 -0500 (Tue, 01 Jun 2010)
New Revision: 6472

Modified:
   trunk/scipy/stats/distributions.py
   trunk/scipy/stats/tests/test_continuous_basic.py
Log:
Add tests for logpdf, logcdf, and logsf plus one fix.

Modified: trunk/scipy/stats/distributions.py
===================================================================
--- trunk/scipy/stats/distributions.py	2010-06-01 09:19:15 UTC (rev 6471)
+++ trunk/scipy/stats/distributions.py	2010-06-01 10:10:30 UTC (rev 6472)
@@ -2332,7 +2332,7 @@
         return exp(1)*b*xbm1 * exp(xb - exp(xb))
     def _logpdf(self, x, b):
         xb = x**(b-1.0)*x
-        return log(b) + (b-1.0)*log(x) + xb - exp(xb)
+        return 1 + log(b) + (b-1.0)*log(x) + xb - exp(xb)
     def _cdf(self, x, b):
         xb = arr(x**b)
         return -expm1(-expm1(xb))
@@ -4282,11 +4282,13 @@
     %(example)s
     """
     def _rvs(self):
-        return invnorm_gen._rvs(self, 1.0)
+        return mtrand.wald(1.0, 1.0, size=self._size)
     def _pdf(self, x):
-        return invnorm.pdf(x,1.0)
+        return invnorm._pdf(x, 1.0)
+    def _logpdf(self, x):
+        return invnorm._logpdf(x, 1.0)
     def _cdf(self, x):
-        return invnorm.cdf(x,1,0)
+        return invnorm._logcdf(x, 1.0)
     def _stats(self):
         return 1.0, 1.0, 3.0, 15.0
 wald = wald_gen(a=0.0, name="wald", extradoc="""

Modified: trunk/scipy/stats/tests/test_continuous_basic.py
===================================================================
--- trunk/scipy/stats/tests/test_continuous_basic.py	2010-06-01 09:19:15 UTC (rev 6471)
+++ trunk/scipy/stats/tests/test_continuous_basic.py	2010-06-01 10:10:30 UTC (rev 6472)
@@ -175,11 +175,14 @@
         yield check_cdf_ppf, distfn, arg, distname
         yield check_sf_isf, distfn, arg, distname
         yield check_pdf, distfn, arg, distname
+        if distname in ['wald']: continue
+        yield check_pdf_logpdf, distfn, arg, distname
+        yield check_cdf_logcdf, distfn, arg, distname
+        yield check_sf_logsf, distfn, arg, distname
         if distname in distmissing:
             alpha = 0.01
-            yield check_distribution_rvs, dist, args, alpha, rvs
+ #           yield check_distribution_rvs, dist, args, alpha, rvs
 
-
 @npt.dec.slow
 def test_cont_basic_slow():
     # same as above for slow distributions
@@ -202,14 +205,14 @@
         yield check_cdf_ppf, distfn, arg, distname
         yield check_sf_isf, distfn, arg, distname
         yield check_pdf, distfn, arg, distname
+        yield check_pdf_logpdf, distfn, arg, distname
+        yield check_cdf_logcdf, distfn, arg, distname
+        yield check_sf_logsf, distfn, arg, distname
         #yield check_oth, distfn, arg # is still missing
         if distname in distmissing:
             alpha = 0.01
             yield check_distribution_rvs, dist, args, alpha, rvs
 
-
-
-
 def check_moment(distfn, arg, m, v, msg):
     m1  = distfn.moment(1,*arg)
     m2  = distfn.moment(2,*arg)
@@ -314,7 +317,37 @@
     npt.assert_almost_equal(pdfv, cdfdiff,
                 decimal=DECIMAL, err_msg= msg + ' - cdf-pdf relationship')
 
+def check_pdf_logpdf(distfn, args, msg):
+    # compares pdf at several points with the log of the pdf
+    points = np.array([0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8])
+    vals = distfn.ppf(points, *args)
+    pdf = distfn.pdf(vals, *args)
+    logpdf = distfn.logpdf(vals, *args)
+    pdf = pdf[pdf != 0]
+    logpdf = logpdf[np.isfinite(logpdf)]
+    npt.assert_almost_equal(np.log(pdf), logpdf, decimal=7, err_msg=msg + " - logpdf-log(pdf) relationship")
 
+def check_sf_logsf(distfn, args, msg):
+    # compares sf at several points with the log of the sf
+    points = np.array([0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8])
+    vals = distfn.ppf(points, *args)
+    sf = distfn.sf(vals, *args)
+    logsf = distfn.logsf(vals, *args)
+    sf = sf[sf != 0]
+    logsf = logsf[np.isfinite(logsf)]
+    npt.assert_almost_equal(np.log(sf), logsf, decimal=7, err_msg=msg + " - logsf-log(sf) relationship")
+
+def check_cdf_logcdf(distfn, args, msg):
+    # compares cdf at several points with the log of the cdf
+    points = np.array([0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8])
+    vals = distfn.ppf(points, *args)
+    cdf = distfn.cdf(vals, *args)
+    logcdf = distfn.logcdf(vals, *args)
+    cdf = cdf[cdf != 0]
+    logcdf = logcdf[np.isfinite(logcdf)]
+    npt.assert_almost_equal(np.log(cdf), logcdf, decimal=7, err_msg=msg + " - logcdf-log(cdf) relationship")
+
+
 def check_distribution_rvs(dist, args, alpha, rvs):
     #test from scipy.stats.tests
     #this version reuses existing random variables



More information about the Scipy-svn mailing list