[Scipy-tickets] [SciPy] #1551: Distribution fit with more than one fixed parameter does not work

SciPy Trac scipy-tickets@scipy....
Thu Nov 3 06:43:25 CDT 2011


#1551: Distribution fit with more than one fixed parameter does not work
-------------------------+--------------------------------------------------
 Reporter:  pbrod        |       Owner:  somebody
     Type:  defect       |      Status:  new     
 Priority:  normal       |   Milestone:  0.11.0  
Component:  scipy.stats  |     Version:  devel   
 Keywords:               |  
-------------------------+--------------------------------------------------
 The following example
 {{{
 import numpy as np
 from scipy import stats

 np.set_printoptions(precision=4)
 print 'true'
 print 0.25, 0., 20.0
 print 'estimated, floc=0, loc=0'
 for i in range(10):
     x = stats.lognorm.rvs(0.25, 0., 20.0, size=2000)
     print np.array(stats.lognorm.fit(x, floc=0, fscale=20)), \
             np.array(stats.lognorm.fit(x, loc=0))
 }}}

 gives the following error


 {{{
 Traceback (most recent call last):
   File "<ipython console>", line 3, in <module>
   File "C:\Python26\lib\site-packages\scipy\stats\distributions.py", line
 1710, in fit
     x0, func, restore, args = self._reduce_func(args, kwds)
   File "C:\Python26\lib\site-packages\scipy\stats\distributions.py", line
 1627, in _reduce_func
     del x0[n]
 IndexError: list assignment index out of range
 }}}


 This error is easily fixed by replacing:


 {{{
 def _reduce_func(self, args, kwds):
         args = list(args)
         Nargs = len(args)
         fixedn = []
         index = range(Nargs)
         names = ['f%d' % n for n in range(Nargs - 2)] + ['floc', 'fscale']
         x0 = args[:]
         for n, key in zip(index, names):
             if kwds.has_key(key):
                 fixedn.append(n)
                 args[n] = kwds[key]
                 del x0[n]
 }}}

 with this code:


 {{{
 def _reduce_func(self, args, kwds):
         args = list(args)
         Nargs = len(args)
         fixedn = []
         index = range(Nargs)
         names = ['f%d' % n for n in range(Nargs - 2)] + ['floc', 'fscale']
         x0 = args[:]
         for n, key in zip(index[::-1], names[::-1]):
             if kwds.has_key(key):
                 fixedn.append(n)
                 args[n] = kwds[key]
                 del x0[n]
 }}}

-- 
Ticket URL: <http://projects.scipy.org/scipy/ticket/1551>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list