Dear all,
I am trying to fit a powerlaw to a small dataset using
Scientific.Func tions.LeastSqua res fit.
Unfortunately, the algorithm seems to diverge and throws an
OverflowExcepti on.
Here is how I try it:
.... (2.5, 589.0, 0.1000000000000 0001),
.... (7.5, 442.0, 0.1000000000000 0001),
.... (12.5, 96.0, 0.1000000000000 0001),
.... (17.5, 36.0, 0.1000000000000 0001),
.... (22.5, 16.0, 0.1000000000000 0001),
.... (27.5, 7.0, 0.1000000000000 0001),
.... (32.5, 6.0, 0.1000000000000 0001),
.... (37.5, 3.0, 0.1000000000000 0001),
.... (42.5, 3.0, 0.1000000000000 0001),
.... (47.5, 1.0, 0.1000000000000 0001),
.... (52.5, 3.0, 0.1000000000000 0001),
.... (57.5, 1.0, 0.1000000000000 0001),
.... (67.5, 1.0, 0.1000000000000 0001),
.... (77.5, 2.0, 0.1000000000000 0001),
.... (82.5, 1.0, 0.1000000000000 0001),
.... (87.5, 2.0, 0.1000000000000 0001)
.... ]
.... return a*x**b
....
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File
"/usr/lib/python2.4/site-packages/Scientific/Functions/LeastSquares.py ",
line 72, in leastSquaresFit
next_chi_sq, next_alpha = _chiSquare(mode l, next_p, data)
File
"/usr/lib/python2.4/site-packages/Scientific/Functions/LeastSquares.py ",
line 22, in _chiSquare
f = model(parameter s, point[0])
File "<stdin>", line 2, in powerlaw
File
"/usr/lib/python2.4/site-packages/Scientific/Functions/FirstDerivative s.py",
line 182, in __rpow__
return pow(other, self)
File
"/usr/lib/python2.4/site-packages/Scientific/Functions/FirstDerivative s.py",
line 171, in __pow__
raise OverflowError, "Numerical result of pow(%s,%s) out of range."
% (self.value,oth er.value-1)
OverflowError: Numerical result of pow(2.5,8376.79 243687) out of range.
I added some debugging output in
/usr/lib/python-2.4/site-packages/Scientifc/Functions/LeastSquares.py
in the function _chiSquare that prints the fit parameters during the
Levenberg-Marquardt iteration.
The procedure seems do diverge after the first step:
((10, [1]), (-3, [0, 1]))
[(-67402.311817579 117, [1]), (8377.792436871 6158, [0, 1])]
Note that I could easily fit the above data using gnuplots internal
fitting procedure. Any idea what is going wrong here? Is it a known
problem? Are there any work arounds or other packages?
Any help is appreciated!
- harold -
I am trying to fit a powerlaw to a small dataset using
Scientific.Func tions.LeastSqua res fit.
Unfortunately, the algorithm seems to diverge and throws an
OverflowExcepti on.
Here is how I try it:
>>from Scientific.Func tions.LeastSqua res import leastSquaresFit
>>>
>>data = [
>>>
>>data = [
.... (7.5, 442.0, 0.1000000000000 0001),
.... (12.5, 96.0, 0.1000000000000 0001),
.... (17.5, 36.0, 0.1000000000000 0001),
.... (22.5, 16.0, 0.1000000000000 0001),
.... (27.5, 7.0, 0.1000000000000 0001),
.... (32.5, 6.0, 0.1000000000000 0001),
.... (37.5, 3.0, 0.1000000000000 0001),
.... (42.5, 3.0, 0.1000000000000 0001),
.... (47.5, 1.0, 0.1000000000000 0001),
.... (52.5, 3.0, 0.1000000000000 0001),
.... (57.5, 1.0, 0.1000000000000 0001),
.... (67.5, 1.0, 0.1000000000000 0001),
.... (77.5, 2.0, 0.1000000000000 0001),
.... (82.5, 1.0, 0.1000000000000 0001),
.... (87.5, 2.0, 0.1000000000000 0001)
.... ]
>>>
>>def powerlaw((a,b), x) :
>>def powerlaw((a,b), x) :
....
>>params,chis q = leastSquaresFit (powerlaw,(10,-3),data)
File "<stdin>", line 1, in ?
File
"/usr/lib/python2.4/site-packages/Scientific/Functions/LeastSquares.py ",
line 72, in leastSquaresFit
next_chi_sq, next_alpha = _chiSquare(mode l, next_p, data)
File
"/usr/lib/python2.4/site-packages/Scientific/Functions/LeastSquares.py ",
line 22, in _chiSquare
f = model(parameter s, point[0])
File "<stdin>", line 2, in powerlaw
File
"/usr/lib/python2.4/site-packages/Scientific/Functions/FirstDerivative s.py",
line 182, in __rpow__
return pow(other, self)
File
"/usr/lib/python2.4/site-packages/Scientific/Functions/FirstDerivative s.py",
line 171, in __pow__
raise OverflowError, "Numerical result of pow(%s,%s) out of range."
% (self.value,oth er.value-1)
OverflowError: Numerical result of pow(2.5,8376.79 243687) out of range.
>>>
I added some debugging output in
/usr/lib/python-2.4/site-packages/Scientifc/Functions/LeastSquares.py
in the function _chiSquare that prints the fit parameters during the
Levenberg-Marquardt iteration.
The procedure seems do diverge after the first step:
((10, [1]), (-3, [0, 1]))
[(-67402.311817579 117, [1]), (8377.792436871 6158, [0, 1])]
Note that I could easily fit the above data using gnuplots internal
fitting procedure. Any idea what is going wrong here? Is it a known
problem? Are there any work arounds or other packages?
Any help is appreciated!
- harold -
Comment