Polyfit

Charles R Harris charlesr.harris at gmail.com
Fri Oct 13 15:50:58 EDT 2006


On 10/12/06, Greg Willden <gregwillden at gmail.com> wrote:
>
> On 10/12/06, Charles R Harris <charlesr.harris at gmail.com> wrote:
> >
> > And here is the location of the problem in numpy/linalg/linalg.py :
> >
> > def lstsq(a, b, rcond=1.e-10):
> >
> > The 1e-10 is a bit conservative. On the other hand, I will note that the
> > condition number of the dot(V^T ,V) matrix is somewhere around 1e22, which
> > means in general terms that you need around 22 digits of accuracy. Inverting
> > it only works sorta by accident in the current case. Generally, using
> > Vandermonde matrices and polynomial fits it a bad idea when the dynamic
> > range of the interval gets large and the degree gets up around 4-5 as it
> > leads to ill conditioned sets of equations. When you really need the best
> > start with chebychev polynomials or, bestest, compute a set of polynomials
> > orthogonal over the sample points. Anyway, I think rcond should be something
> > like 1e-12 or 1e-13 by default and be available as a keyword in the polyfit
> > function. If no one complains I will make this change, although it is just a
> > bandaid and things will fall apart again as soon as you call polyfit(x,y,4).
> >
> >
>
> Hey that's great.  I'm glad you tracked it down.
>
> Pardon my ignorance of polyfit algorithm details.
> Is there a way of choosing rcond based on N that would give sensible
> defaults for a variety of N?
> Greg


You can also get *much* better results if you scale the x interval to [0,1]
as the problem will be better posed. For instance, with your data and a
degree 10 fit I get  a condition number of about 2e7 when x is scaled to
[0,1], as opposed to about 1e36 when left as is. The former yields a
perfectly useable fit while the latter blows up. I suppose this could be
built into the polyfit routine if one were only interested in polynomial
fits of some sort, but the polynomial would have to carry around an offset
and scale factor to make evaluation work.

If Travis is interested in such a thing we could put together some variant
of the polynomials that includes the extra data.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20061013/0e3631a6/attachment.html>
-------------- next part --------------
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
-------------- next part --------------
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


More information about the NumPy-Discussion mailing list