Hi All,
I'm using numpy.polyfit and it is giving me some really strange results when evaluated near 0.  So I compared it with polyfit in matplotlib and the code and docstrings are nearly identical.  However the slight differences in the code make a huge difference on my data.

Here is the Numpy version with line numbers added:
1    x = NX.asarray(x)+0.
2   y = NX.asarray(y)+0.
3    y = NX.reshape(y, (len(y), 1))
4    X = vander(x, N+1)
5   c, resids, rank, s = _lstsq(X, y)
6    c.shape = (N+1,)
7    return c


And here is the MPL version with line numbers added:
1    x = asarray(x)+0.
2    y = asarray(y)+0.
3    y = reshape(y, (len(y),1))
4    X = Matrix(vander(x, N+1))
5    Xt = Matrix(transpose(X))
6    c = array(linear_algebra.inverse(Xt*X)*Xt*y)  # convert back to array
7    c.shape = (N+1,)
8    return c
  

So lines 1-4 are basically the same.
The MPL version produces a much more stable representation of my data

Can someone please comment on the differences?
Should these two be exactly the same?
If not, what are the advantages to each algorithm?

I'm attaching my x and y points dumped to files. 
Here is the test code using "ipython -pylab"
import numpy
x=numpy.load('x.data')
y=numpy.load('y.data')
semilogy(numpy.polyval(numpy.polyfit(x,y,3),arange(3604)));hold(True)
semilogy(polyval(polyfit(x,y,3),arange(3604))) #Use the MPL versions
scatter(x,y)

Regards,
Greg

Attachment: x.data
Description: Binary data

Attachment: y.data
Description: Binary data

-------------------------------------------------------------------------
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
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion

Reply via email to