forum.alglib.net
http://forum.alglib.net/

Linear Fitting: More equations, greater error ?
http://forum.alglib.net/viewtopic.php?f=2&t=308
Page 1 of 1

Author:  marcs [ Wed Feb 23, 2011 3:58 pm ]
Post subject:  Linear Fitting: More equations, greater error ?

Dear Sergey,

first I want to take the opportunity an gratulate you on ALGLIB, a great library, extremely clean coding style, very efficient.
Great work, a good programmer :)

I have only one simple question: when using linear interpolation (it is in fact polynomial regression, most of the values in the function
matrix are powers of >some x<), I encounter the issue that when increasing the number of equations (degrees of freedom in my model) over
a certain limit, often about 5 * 20 equations (means 5 sub-matrices with x^0 - x^20), the overall error starts to increase again.

Is it likely to be related to floating point / IEEE754 issues? I would guess so.

Best Regards :)

Author:  Sergey.Bochkanov [ Wed Feb 23, 2011 4:50 pm ]
Post subject:  Re: Linear Fitting: More equations, greater error ?

Almost surely, it is floating point issue. Polynomial basis is ill-conditioned, and having x^20 as basis function will give you very badly conditioned matrix. You can check fitting report, in particular - rep.taskrcond variable. If it is lower than 10^(-10), than you definitely have problems with condition number.

I recommend you to switch to better basis - for example, to replace x^i with centered Chebyshev polynomials.

Author:  marcs [ Wed Feb 23, 2011 8:18 pm ]
Post subject:  Re: Linear Fitting: More equations, greater error ?

Thank You for your time!

Author:  Doug Jenkins [ Thu Feb 24, 2011 11:08 am ]
Post subject:  Re: Linear Fitting: More equations, greater error ?

The polyfit function seems to give much better results for fitting high order polynomials than the least squares functions.

See an Excel implementation and examples here:

http://newtonexcelbach.wordpress.com/20 ... functions/

Author:  marcs [ Fri Feb 25, 2011 4:11 pm ]
Post subject:  Re: Linear Fitting: More equations, greater error ?

Doug, I'm aware. The polynomial fitting uses a barycentric method. However, not all equations in my model are polynomials.

Author:  Sergey.Bochkanov [ Fri Feb 25, 2011 6:59 pm ]
Post subject:  Re: Linear Fitting: More equations, greater error ?

Quote:
The polynomial fitting uses a barycentric method.

Polynomial fitting uses Chebyshev basis internally, it just converts results into barycentric form before output.

Quote:
However, not all equations in my model are polynomials.

I've recommended you to use Chebyshev polynomials as basis because you can use it with non-polynomial basis functions.

Author:  marcs [ Sat Feb 26, 2011 8:35 pm ]
Post subject:  Re: Linear Fitting: More equations, greater error ?

Thanks again, I have looked at the matrix condition and I'm using now Chebychev Polynomials with -1 <= x <= +1

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/