comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: efficient polynomial fitting
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: efficient polynomial fitting [message #36684] Thu, 16 October 2003 07:55
mvukovic is currently offline  mvukovic
Messages: 63
Registered: July 1998
Member
mperrin+news@cymric.berkeley.edu (Marshall Perrin) wrote in message news:<bmlf39$1tnc$1@agate.berkeley.edu>...
> What's the most efficient way to fit a polynomial of low order ( ~ 3) to several
> hundred thousand data points? I feel there has to be a more IDL-ish, matrix based
> solution than a for loop calling poly_fit 300,000 times (which is of course sloooow).
>
> My first approach was to code up a straightforward linear-least-squares polynomial
> fitter and append an extra dimension to everything to do the fit for all my points
> in parallel, but this fails, due to the behavior of the matrix multiply operator.
>
> Let "deg" be the degree of the polynomial I'm trying to fit, and let's consider
> my data to be an array of size [nt,nx]. I want to do the polynomial fit over the
> t dimension, while the points are completely independent in the x direction. That is,
> I'm *not* trying to do a two-D least squares - I just want to do least squares on
> tons of point simultaneously. So here goes:
>
>
> ; basic setup for least squares fit, with the nx dimension tacked on...
> pow = indgen(deg+1)
> powarr = rebin(transpose(pow),nt,deg+1,nx)
>
> ti = rebin(reform(double(data),nt,1,nx),nt,deg+1,nx)
> tarr = t^powarr
> tarr_transpose = transpose(tarr,[1,0,2])
>
> ; here's where we get into trouble
> alpha = tarr ## tarr_transpose ; alpha should be (d+1)*(d+1)*nx, but is just (d+1)*(d+1)
>
> In other words, I want to matrix multply a [nt,d+1,nx] * [d+1,nt,dx] and only have the multiply
> operate over the first two dimensions, leaving the third alone. Is there any way to do this in IDL,
> *without* resorting to a for loop of some kind?
>
> - Marshall


My suggestion would be to get the explicit formulae for the
coefficient of the polynomial, and vectorise those.

Good luck,

Mirko
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: efficient polynomial fitting
Next Topic: Project: Emulating Dataminer with JDBC/Java-Bridge

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:26:57 PDT 2025

Total time taken to generate the page: 0.00432 seconds