Package: python-scipy
Version: 0.3.2-6
Severity: normal
Tags: patch

There are typographic bugs in stats.py that make two functions fail.  In
addition, the calculation for nanstd() provides obviously wrong answers.
I have not done any formal checking for the correction attached below.

In the distributions.py file, the calculation of est_loc_scale() uses
a sibling method wrongly and references an import by the wrong name.
In the same file, nnlf() method passes its own object twice to _nnlf()
and its parameter parsing is incompatible with the fit() method's needs.

The patch below is on directory /lib/python*/site-packages/scipy/stats


*** stats.py    2005-08-10 10:05:38.000000000 -0700
--- stats.py.orig       2005-08-10 09:31:59.000000000 -0700
***************
*** 241,249 ****
      x = x.copy()
      Norig = x.shape[axis]
      factor = 1.0-sum(isnan(x),axis)*1.0/Norig
!     n = N.sum(isnan(x),axis)
      N.putmask(x,isnan(x),0)
!     return mean(x,axis)/factor
      
  def nanstd(x,axis=-1,bias=0):
      """Compute the standard deviation over the given axis ignoring nans
--- 241,249 ----
      x = x.copy()
      Norig = x.shape[axis]
      factor = 1.0-sum(isnan(x),axis)*1.0/Norig
!     n = N-sum(isnan(x),axis)
      N.putmask(x,isnan(x),0)
!     return stats.mean(x,axis)/factor
      
  def nanstd(x,axis=-1,bias=0):
      """Compute the standard deviation over the given axis ignoring nans
***************
*** 253,266 ****
      Norig = x.shape[axis]
      n = Norig - sum(isnan(x),axis)*1.0
      factor = n/Norig
      N.putmask(x,isnan(x),0)
!     mn = expand_dims(mean(x,axis),axis)
!     y = ss(x-mn,axis)
      if bias:
!        y /= n
      else:
!        y /= n-1
!     return sqrt(y)
  
  def _nanmedian(arr1d):  # This only works on 1d arrays
     cond = 1-isnan(arr1d)
--- 253,268 ----
      Norig = x.shape[axis]
      n = Norig - sum(isnan(x),axis)*1.0
      factor = n/Norig
+     n = N-sum(isnan(x),axis)
      N.putmask(x,isnan(x),0)
!     m1 = stats.mean(x,axis)
!     m1c = m1/factor
!     m2 = stats.mean((x-m1c)**2.0,axis)
      if bias:
!         m2c = m2/factor
      else:
!         m2c = m2*Norig/(n-1.0)
!     return m2c
  
  def _nanmedian(arr1d):  # This only works on 1d arrays
     cond = 1-isnan(arr1d)
*** distributions.py.orig       2005-08-10 09:25:14.000000000 -0700
--- distributions.py    2005-08-10 10:32:11.000000000 -0700
***************
*** 730,740 ****
          #
          try:
              x = args[-1]
!             loc = args[-2]
!             scale = args[-3]
!             args = args[:-3]
          except IndexError:
!             raise ValueError, "Not enough input arguments."
          if not self._argcheck(*args) or scale <= 0:
              return inf
          x = arr((x-loc) / scale)
--- 730,746 ----
          #
          try:
              x = args[-1]
!           args = args[:-1]
          except IndexError:
!             raise ValueError, "Need shape and data arguments."
!       try:
!             if len(args) == 1:
!               args = args[0]
!           loc = args[-1]
!             scale = args[-2]
!             args = args[:-2]
!         except IndexError:
!             raise ValueError, "Not enough shape arguments."
          if not self._argcheck(*args) or scale <= 0:
              return inf
          x = arr((x-loc) / scale)
***************
*** 743,749 ****
              return inf
          else:
              N = len(x)
!             return self._nnlf(self, x, *args) + N*log(scale)
  
      def fit(self, data, *args, **kwds):
          loc0, scale0 = map(kwds.get, ['loc', 'scale'],[0.0, 1.0])
--- 749,755 ----
              return inf
          else:
              N = len(x)
!             return self._nnlf(x, *args) + N*log(scale)
  
      def fit(self, data, *args, **kwds):
          loc0, scale0 = map(kwds.get, ['loc', 'scale'],[0.0, 1.0])
***************
*** 758,766 ****
          return optimize.fmin(self.nnlf,x0,args=(ravel(data),),disp=0)
  
      def est_loc_scale(self, data, *args):
!         mu, mu2, g1, g2 = self.stats(*args,**{'moments':'mv'})
!         muhat = stats.nanmean(data)
!         mu2hat = stats.nanstd(data)
          Shat = sqrt(mu2hat / mu2)
          Lhat = muhat - Shat*mu
          return Lhat, Shat
--- 764,772 ----
          return optimize.fmin(self.nnlf,x0,args=(ravel(data),),disp=0)
  
      def est_loc_scale(self, data, *args):
!         mu, mu2 = self.stats(*args,**{'moments':'mv'})
!         muhat = st.nanmean(data)
!         mu2hat = st.nanstd(data)
          Shat = sqrt(mu2hat / mu2)
          Lhat = muhat - Shat*mu
          return Lhat, Shat




-- System Information:
Debian Release: testing/unstable
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.4.23
Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1)

Versions of packages python-scipy depends on:
ii  python2.3-scipy               0.3.2-6    scientific tools for Python 2.3

python-scipy recommends no packages.

-- no debconf information


Reply via email to