Package: python-scientific
Version: 2.4.9-2
Severity: important
leastSquaresFit have a serious problems fitting some sort of data.
See example:
---------- fit.py begin -----------------------
#!/usr/bin/python
import math
import Numeric
import Gnuplot
from Scientific.Functions.LeastSquares import leastSquaresFit
def func(params,x): # y=ax^2+bx+c
return params[0]*x*x + params[1]*x + params[2]
y = [0.024534584403990638, 0.024268139468029117, 0.024327174254079119,
0.023987418341212714, 0.024193310299944572, 0.024205986364944539,
0.024362896651579858, 0.02423512221973911, 0.024474275622143011,
0.024560514763826952, 0.024200400064391291, 0.024905882963317118,
0.024341957057204804, 0.024858910677267834, 0.02456561695534765,
0.024486185747873021, 0.024849803534167346, 0.02494169514520066,
0.024830224580372567, 0.024924391234288964, 0.024829432926425379,
0.025084227371413314, 0.024920185549166675, 0.024966063512280281,
0.024976124021682811, 0.024937318918899908, 0.025227082507185663,
0.024855946039654016, 0.024749003062764331, 0.024932169370634406,
0.02506660192339695, 0.02494286917136742, 0.02496622327396187,
0.024958945781895937, 0.025422296259554999, 0.025131910308544132,
0.025359726223181406, 0.025166614713359344, 0.02518719660684356,
0.02483155872573857, 0.024708002738975152, 0.024874566784538119,
0.025060911568896765, 0.024619622497772997, 0.024873415963445222,
0.024264834096079206, 0.024614531032652768, 0.024399247042373475,
0.024863916814417391, 0.024766917482409959, 0.024219429877820539,
0.024638125836536767, 0.024541418698712448, 0.024317146507352321,
0.024536888767789325, 0.024200295665299014, 0.024433616218483001,
0.024424434856681668, 0.023599470793024137, 0.023744196289889611,
0.024244459897969299, 0.023766126573895086, 0.022880253808965877,
0.02402953850052976, 0.023752884424688276, 0.02356658316651471,
0.023732425193155302, 0.024136862451918019]
x = [9007708.75, 9007710.625, 9007712.5, 9007714.375, 9007716.25, 9007718.125,
9007720.0, 9007721.875, 9007723.75, 9007725.625, 9007727.5, 9007729.375,
9007731.25, 9007733.125, 9007735.0, 9007736.875, 9007738.75, 9007740.625,
9007742.5, 9007744.375, 9007746.25, 9007748.125, 9007750.0, 9007751.875,
9007753.75, 9007755.625, 9007757.5, 9007759.375, 9007761.25, 9007763.125,
9007765.0, 9007766.875, 9007768.75, 9007770.625, 9007772.5, 9007774.375,
9007776.25, 9007778.125, 9007780.0, 9007781.875, 9007783.75, 9007785.625,
9007787.5, 9007789.375, 9007791.25, 9007793.125, 9007795.0, 9007796.875,
9007798.75, 9007800.625, 9007802.5, 9007804.375, 9007806.25, 9007808.125,
9007810.0, 9007811.875, 9007813.75, 9007815.625, 9007817.5, 9007819.375,
9007821.25, 9007823.125, 9007825.0, 9007826.875, 9007828.75, 9007830.625,
9007832.5, 9007834.375]
datafit = []
for i in range(len(x)):
datafit.append((x[i], y[i]))
guess = (-1.0, 1.0, 1.0)
fit_params, fit_error = leastSquaresFit(func, guess, datafit)
print fit_params, fit_error
xf = []
yf = []
for i in range(len(x)):
xf.append(x[i])
yf.append(func(fit_params, x[i]))
gnuplot = Gnuplot.Gnuplot()
gnuplot.clear()
gnuplot('set data style linespoints')
gnuplot('set title "bad fit"')
#self.gnuplot('set xrange [%f:%f]' % (self.frequency['start']-100,
self.frequency['stop']+100))
gnuplot.plot(
Gnuplot.Data(
x,
y,
title='data',
axes='x1y1',
inline=1
),
Gnuplot.Data(
xf,
yf,
title='fit',
axes='x1y1',
inline=1
)
)
raw_input('Press enter')
x = range(len(x))
datafit = []
for i in range(len(x)):
datafit.append((x[i], y[i]))
guess = (-1.0, 1.0, 1.0)
fit_params, fit_error = leastSquaresFit(func, guess, datafit)
print fit_params, fit_error
xf = []
yf = []
for i in range(len(x)):
xf.append(x[i])
yf.append(func(fit_params, x[i]))
gnuplot = Gnuplot.Gnuplot()
gnuplot.clear()
gnuplot('set data style linespoints')
gnuplot('set title "good fit"')
#self.gnuplot('set xrange [%f:%f]' % (self.frequency['start']-100,
self.frequency['stop']+100))
gnuplot.plot(
Gnuplot.Data(
x,
y,
title='data',
axes='x1y1',
inline=1
),
Gnuplot.Data(
xf,
yf,
title='fit',
axes='x1y1',
inline=1
)
)
raw_input('Press enter')
---------- fit.py end -----------------------
-- System Information:
Debian Release: 3.1
APT prefers experimental
APT policy: (1, 'experimental')
Architecture: i386 (i686)
Kernel: Linux 2.6.8-2-k7
Locale: LANG=C, LC_CTYPE=sk_SK (charmap=ISO-8859-2)
Versions of packages python-scientific depends on:
ii python 2.3.5-2 An interactive high-level object-o
ii python-netcdf 2.4.9-2 A netCDF interface for Python
ii python-numeric-ext 23.8-1 Extension modules for Numeric Pyth
-- no debconf information
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]