[Scipy-svn] r6464 - trunk/scipy/stats

scipy-svn at scipy.org scipy-svn at scipy.org
Tue Jun 1 01:54:12 EDT 2010


Author: oliphant
Date: 2010-06-01 00:54:12 -0500 (Tue, 01 Jun 2010)
New Revision: 6464

Modified:
   trunk/scipy/stats/distributions.py
Log:
Apply docstring clean-up patch and bug fixes in 0.8.x branch to trunk.

Modified: trunk/scipy/stats/distributions.py
===================================================================
--- trunk/scipy/stats/distributions.py	2010-06-01 05:51:53 UTC (rev 6463)
+++ trunk/scipy/stats/distributions.py	2010-06-01 05:54:12 UTC (rev 6464)
@@ -5,10 +5,14 @@
 #          SciPy Developers 2004-2010
 #
 
+import math
+from copy import copy
+
 from scipy.misc import comb, derivative
 from scipy import special
 from scipy import optimize
 from scipy import integrate
+from scipy.special import gammaln as gamln
 
 import inspect
 from numpy import alltrue, where, arange, putmask, \
@@ -22,8 +26,6 @@
 import numpy as np
 import numpy.random as mtrand
 from numpy import flatnonzero as nonzero
-from scipy.special import gammaln as gamln
-from copy import copy
 import vonmises_cython
 
 def _moment(data, n, mu=None):
@@ -562,34 +564,112 @@
         return vals
 
     def median(self, *args, **kwds):
+        """
+        Median of the distribution.
+
+        Parameters
+        ----------
+        arg1, arg2, arg3,... : array-like
+            The shape parameter(s) for the distribution (see docstring of the
+            instance object for more information)
+        loc : array-like, optional
+            location parameter (default=0)
+        scale : array-like, optional
+            scale parameter (default=1)
+
+        Returns
+        -------
+        median : float
+            the median of the distribution.
+
+        See Also
+        --------
+        self.ppf --- inverse of the CDF
+        """
         return self.ppf(0.5, *args, **kwds)
 
     def mean(self, *args, **kwds):
+        """
+        Mean of the distribution
+
+        Parameters
+        ----------
+        arg1, arg2, arg3,... : array-like
+            The shape parameter(s) for the distribution (see docstring of the
+            instance object for more information)
+        loc : array-like, optional
+            location parameter (default=0)
+        scale : array-like, optional
+            scale parameter (default=1)
+
+        Returns
+        -------
+        mean : float
+            the mean of the distribution
+        """
         kwds['moments'] = 'm'
         res = self.stats(*args, **kwds)
         if isinstance(res, ndarray) and res.ndim == 0:
             return res[()]
+        return res
 
     def var(self, *args, **kwds):
+        """
+        Variance of the distribution
+
+        Parameters
+        ----------
+        arg1, arg2, arg3,... : array-like
+            The shape parameter(s) for the distribution (see docstring of the
+            instance object for more information)
+        loc : array-like, optional
+            location parameter (default=0)
+        scale : array-like, optional
+            scale parameter (default=1)
+
+        Returns
+        -------
+        var : float
+            the variance of the distribution
+
+        """
         kwds['moments'] = 'v'
         res = self.stats(*args, **kwds)
         if isinstance(res, ndarray) and res.ndim == 0:
             return res[()]
-        else:
-            return res
+        return res
 
     def std(self, *args, **kwds):
+        """
+        Standard deviation of the distribution.
+
+        Parameters
+        ----------
+        arg1, arg2, arg3,... : array-like
+            The shape parameter(s) for the distribution (see docstring of the
+            instance object for more information)
+        loc : array-like, optional
+            location parameter (default=0)
+        scale : array-like, optional
+            scale parameter (default=1)
+
+        Returns
+        -------
+        std : float
+            standard deviation of the distribution
+
+        """
         kwds['moments'] = 'v'
-        res = sqrt(self.stats(*args, **kwds))
+        res = math.sqrt(self.stats(*args, **kwds))
         return res
 
     def interval(self, alpha, *args, **kwds):
-        """Confidence interval centered on the median
+        """Confidence interval with equal areas around the median
 
         Parameters
         ----------
         alpha : array-like float in [0,1]
-            Probability that an rv will be drawn from the returned range
+            Probability that an rv will be drawn from the returned range        
         arg1, arg2, ... : array-like
             The shape parameter(s) for the distribution (see docstring of the instance
             object for more information)
@@ -1605,10 +1685,10 @@
         """
         if func is None:
             def fun(x, *args):
-                return x*self.pdf(x, *args, loc=loc, scale=scale)
+                return x*self.pdf(x, *args, **{'loc':loc, 'scale':scale})
         else:
             def fun(x, *args):
-                return func(x)*self.pdf(x, *args, loc=loc, scale=scale)
+                return func(x)*self.pdf(x, *args, **{'loc':loc, 'scale':scale})
         if lb is None:
             lb = (self.a - loc)/(1.0*scale)
         if ub is None:
@@ -1617,8 +1697,8 @@
             invfac = self.sf(lb,*args) - self.sf(ub,*args)
         else:
             invfac = 1.0
-            kwds['args'] = args
-            return integrate.quad(fun, lb, ub, **kwds)[0] / invfac
+        kwds['args'] = args
+        return integrate.quad(fun, lb, ub, **kwds)[0] / invfac
 
  
 _EULER = 0.577215664901532860606512090082402431042  # -special.psi(1)
@@ -1658,7 +1738,6 @@
 # loc = mu, scale = std
 # Keep these implementations out of the class definition so they can be reused
 # by other distributions.
-import math
 _norm_pdf_C = math.sqrt(2*pi)
 _norm_pdf_logC = math.log(_norm_pdf_C)
 def _norm_pdf(x):
@@ -4481,7 +4560,7 @@
                  moment_tol=1e-8,values=None,inc=1,longname=None,
                  shapes=None, extradoc=None):
 
-        rv_generic.__init__(self)
+        super(rv_generic,self).__init__()
 
         if badvalue is None:
             badvalue = nan
@@ -5180,15 +5259,15 @@
 
         Parameters
         ----------
-            fn : function (default: identity mapping)
+        fn : function (default: identity mapping)
                Function for which integral is calculated. Takes only one argument.
-            args : tuple
+        args : tuple
                argument (parameters) of the distribution
-            optional keyword parameters
-            lb, ub : numbers
+        optional keyword parameters
+        lb, ub : numbers
                lower and upper bound for integration, default is set to the support
                of the distribution, lb and ub are inclusive (ul<=k<=ub)
-            conditional : boolean (False)
+        conditional : boolean (False)
                If true then the expectation is corrected by the conditional
                probability of the integration interval. The return value is the
                expectation of the function, conditional on being in the given
@@ -5196,7 +5275,7 @@
 
         Returns
         -------
-            expected value : float
+        expected value : float
 
         Notes
         -----
@@ -5213,7 +5292,6 @@
             (a maximum of suppnmin+1000 positive plus suppnmin+1000 negative integers
             are evaluated)
 
-
         """
 
         #moment_tol = 1e-12 # increase compared to self.moment_tol,
@@ -5273,7 +5351,7 @@
                 pos -= self.inc
                 count += 1
         if count > maxcount:
-            # replace with proper warning
+            # fixme: replace with proper warning
             print 'sum did not converge'
         return tot/invfac
     




More information about the Scipy-svn mailing list