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

scipy-svn at scipy.org scipy-svn at scipy.org
Sun May 30 02:46:37 EDT 2010


Author: oliphant
Date: 2010-05-30 01:46:37 -0500 (Sun, 30 May 2010)
New Revision: 6436

Modified:
   trunk/scipy/stats/distributions.py
Log:
Add the ability to fix some parameters during a fitting funtion.   Add some special cases to a few distributions. Add some helper functions for internal use in method of moments.

Modified: trunk/scipy/stats/distributions.py
===================================================================
--- trunk/scipy/stats/distributions.py	2010-05-30 06:33:01 UTC (rev 6435)
+++ trunk/scipy/stats/distributions.py	2010-05-30 06:46:37 UTC (rev 6436)
@@ -2653,6 +2653,22 @@
     def _fitstart(self, data):
         a = 4 / _skew(data)**2
         return super(gamma_gen, self)._fitstart(data, args=(a,))
+    def fit(self, data, *args, **kwds):
+        floc = kwds.get('floc', None):
+        if floc == 0:
+            xbar = ravel(data).mean()
+            logx_bar = ravel(log(data)).mean()
+            s = log(xbar) - logx_bar
+            def func(a):
+                return log(a) - special.digamma(a) - s
+            aest = (3-s + math.sqrt((s-3)**2 + 24*s)) / (12*s)
+            xa = aest*(1-0.4)
+            xb = aest*(1+0.4)
+            a = optimize.brentq(func, [xa, xb], disp=0)
+            scale = xbar / a
+            return a, floc, scale
+        else:
+            return super(gamma_gen, self).fit(data, *args, **kwds)
 gamma = gamma_gen(a=0.0,name='gamma',longname='A gamma',
                   shapes='a',extradoc="""
 




More information about the Scipy-svn mailing list