[Scipy-svn] r6463 - branches/0.8.x/scipy/stats

scipy-svn@scip... scipy-svn@scip...
Tue Jun 1 00:51:53 CDT 2010


Author: oliphant
Date: 2010-06-01 00:51:53 -0500 (Tue, 01 Jun 2010)
New Revision: 6463

Modified:
   branches/0.8.x/scipy/stats/distributions.py
Log:
Add documentationfor more new methods of distributions.  Fix an indentation bug in expect.  Use super when calling parent class methods.

Modified: branches/0.8.x/scipy/stats/distributions.py
===================================================================
--- branches/0.8.x/scipy/stats/distributions.py	2010-06-01 04:09:28 UTC (rev 6462)
+++ branches/0.8.x/scipy/stats/distributions.py	2010-06-01 05:51:53 UTC (rev 6463)
@@ -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)
@@ -1606,10 +1686,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:
@@ -1618,8 +1698,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)
@@ -1659,7 +1739,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):
@@ -4482,7 +4561,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
@@ -5181,15 +5260,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
@@ -5197,7 +5276,7 @@
 
         Returns
         -------
-            expected value : float
+        expected value : float
 
         Notes
         -----
@@ -5214,7 +5293,6 @@
             (a maximum of suppnmin+1000 positive plus suppnmin+1000 negative integers
             are evaluated)
 
-
         """
 
         #moment_tol = 1e-12 # increase compared to self.moment_tol,
@@ -5274,7 +5352,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