Since I observed the following behavior in the SVN respository version
of SciPy, it seemed to me proper to post to the dev mailing list. I'm
using Ubuntu Lucid Lynx 32 bit and a fresh GIT of Numpy. I am not
sure if a Trac bug report needs to be entered.
Below is some example code for fitting two statistical distributions.
Sometimes the numpy-generated data is fit, as I can see the estimated
and fitted parameters are different. Sometimes I receive many
messages repeated on the command line like:
Warning: invalid value encountered in absolute
Warning: invalid value encountered in subtract
and the estimated parameters equal the fitted parameter values,
indicating no fitting took place. Sometimes I receive on the command
line:
Traceback (most recent call last):
File "/home/zunzun/local/lib/python2.6/site-packages/scipy/stats/distributions.py",
line 1987, in func
sk = 2*(b-a)*math.sqrt(a + b + 1) / (a + b + 2) / math.sqrt(a*b)
ValueError: math domain error
Traceback (most recent call last):
File "example.py", line 10, in <module>
fitStart_beta = scipy.stats.beta._fitstart(data)
File "/home/zunzun/local/lib/python2.6/site-packages/scipy/stats/distributions.py",
line 1992, in _fitstart
a, b = optimize.fsolve(func, (1.0, 1.0))
File "/home/zunzun/local/lib/python2.6/site-packages/scipy/optimize/minpack.py",
line 125, in fsolve
maxfev, ml, mu, epsfcn, factor, diag)
minpack.error: Error occured while calling the Python function named func
and program flow is stopped.
In summary, three behaviors: (1) Fits OK (2) Many exceptions with no
fitting (3) minpack error. Running the program 10 times or so will
reproduce these behaviors without fail from the "bleeding-edge"
repository code.
James Phillips
########################################################
import numpy, scipy, scipy.stats
# test uniform distribution fitting
data = numpy.random.uniform(2.0, 3.0, size=100)
fitStart_uniform = scipy.stats.uniform._fitstart(data)
fittedParameters_uniform = scipy.stats.uniform.fit(data)
# test beta distribution fitting
data = numpy.random.beta(2.0, 3.0, size=100)
fitStart_beta = scipy.stats.beta._fitstart(data)
fittedParameters_beta = scipy.stats.beta.fit(data)
print
print 'uniform._fitstart returns', fitStart_uniform
print 'fitted parameters for uniform =', fittedParameters_uniform
print
print 'beta._fitstart returns', fitStart_beta
print 'fitted parameters for beta =', fittedParameters_beta
print