[Scipy-svn] r6433 - trunk/scipy/stats
scipy-svn at scipy.org
scipy-svn at scipy.org
Sat May 29 23:51:49 EDT 2010
Author: oliphant
Date: 2010-05-29 22:51:49 -0500 (Sat, 29 May 2010)
New Revision: 6433
Modified:
trunk/scipy/stats/_support.py
trunk/scipy/stats/distributions.py
trunk/scipy/stats/stats.py
Log:
A few cleanups.
Modified: trunk/scipy/stats/_support.py
===================================================================
--- trunk/scipy/stats/_support.py 2010-05-30 03:11:17 UTC (rev 6432)
+++ trunk/scipy/stats/_support.py 2010-05-30 03:51:49 UTC (rev 6433)
@@ -134,8 +134,7 @@
Format: adm (a,criterion) where criterion is like 'x[2]==37'\n"""
- function = 'lines = filter(lambda x: '+criterion+',a)'
- exec(function)
+ lines = eval('filter(lambda x: '+criterion+',a)')
try:
lines = np.array(lines)
except:
Modified: trunk/scipy/stats/distributions.py
===================================================================
--- trunk/scipy/stats/distributions.py 2010-05-30 03:11:17 UTC (rev 6432)
+++ trunk/scipy/stats/distributions.py 2010-05-30 03:51:49 UTC (rev 6433)
@@ -1423,15 +1423,26 @@
if (Narg < self.numargs):
start = self._fitstart(data) # get distribution specific starting locations
args += start[Narg:]
- # location and scale are at the end
- x0 = args + map(kwds.get, ['loc', 'scale'], self.fit_loc_scale(data))
+ # location and scale
+ loc0, scale0 = None, None
+ if 'loc' not in kwds or 'scale' not in kwds:
+ loc0, scale0 = self.fit_loc_scale(data, *args)
+ loc = kwds.get('loc', loc0)
+ scale = kwds.get('scale', scale0)
+
+ if not np.isfinite(scale):
+ scale = np.sqrt(data.std())
+ if not np.isfinite(loc):
+ loc = data.mean()
+
+ x0 = args + (loc, scale)
return optimize.fmin(self.nnlf,x0,args=(ravel(data),),disp=0)
def fit_loc_scale(self, data, *args):
"""
Estimate loc and scale parameters from data using 1st and 2nd moments
"""
- mu, mu2 = self.stats(*args,**{'moments':'mv'})
+ mu, mu2 = self.stats(*args,moments='mv')
muhat = st.nanmean(data)
mu2hat = st.nanstd(data)
Shat = sqrt(mu2hat / mu2)
@@ -1574,6 +1585,7 @@
return 0.0, 1.0, 0.0, 0.0
def _entropy(self):
return 0.5*(log(2*pi)+1)
+ def fit(self, data, *args, **kwds):
return arr(data).mean(), arr(data).std(ddof=0)
norm = norm_gen(name='norm',longname='A normal',extradoc="""
@@ -4861,7 +4873,7 @@
signature = inspect.getargspec(self._stats.im_func)
if (signature[2] is not None) or ('moments' in signature[0]):
- mu, mu2, g1, g2 = self._stats(*args,**{'moments':moments})
+ mu, mu2, g1, g2 = self._stats(*args,moments=moments)
else:
mu, mu2, g1, g2 = self._stats(*args)
if g1 is None:
Modified: trunk/scipy/stats/stats.py
===================================================================
--- trunk/scipy/stats/stats.py 2010-05-30 03:11:17 UTC (rev 6432)
+++ trunk/scipy/stats/stats.py 2010-05-30 03:51:49 UTC (rev 6433)
@@ -2,7 +2,7 @@
#
# Disclaimer
#
-# This software is provided "as-is". There are no expressed or implied
+# This software is provided "as-is". There are no exprgoessed or implied
# warranties of any kind, including, but not limited to, the warranties
# of merchantability and fittness for a given application. In no event
# shall Gary Strangman be liable for any direct, indirect, incidental,
@@ -1777,18 +1777,6 @@
-def zmap(scores, compare, axis=0):
- """
-Returns an array of z-scores the shape of scores (e.g., [x,y]), compared to
-array passed to compare (e.g., [time,x,y]). Assumes collapsing over dim 0
-of the compare array.
-
-"""
- mns = np.mean(compare,axis)
- sstd = samplestd(compare,0)
- return (scores - mns) / sstd
-
-
#####################################
####### TRIMMING FUNCTIONS #######
#####################################
More information about the Scipy-svn
mailing list