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

Home » Public Forums » archive » Challenging question - array curve fitting
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Challenging question - array curve fitting [message #53739 is a reply to message #53320] Sun, 22 April 2007 20:50 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Here's a late follow-up to your questions.

JD Smith <jdsmith@as.arizona.edu> writes:
> Just an unrelated followup question for Craig... MPFIT is (I hate to
> say it) quite slow, in particular for problems like this, where you
> want to simultaneously fit hundreds or thousands of things to complex
> models. I know it wasn't designed for speed, and the things it does
> are amazing (I particularly like arbitrary constraint expressions),
> but I wonder, what do you think the chances of improving the speed
> are? Would it require a fundamental rewrite, or is it more sensible
> to fall back on a C or FORTRAN version of the library (I actually
> don't know how the speed compares)? Should we lobby ITTVIS to throw
> out their non-linear fitters, and incorporate MPFIT into compiled
> code? Just want to get your perspectives. Thanks again for such a
> wonderfully useful tool.

JD, at some point early on, I tried to squeeze as much performance out
of MPFIT as I could. I imagine that today's processors are not the
same as then, but the difference is not likely to be huge.

I did a simple test of fitting a random vector with a polynomial,
yy = randomn(seed,1024L*1024L)
profiler
p = mpfitfun('quad', dindgen(1024L*1024L), yy, 1d, [1d,1d,1d], perror=dp)
profiler, /report

and the results were 30% of the time was spent evaluating the
polynomial function, 38% spent factoring the jacobian, 15% calculating
vector norms. Even if we could make MPFIT run infinitely fast, it
could only ever be three times faster. The factorization is the
biggest proportion of time spent, but then it needs to be.

I think there are several factors to consider.

* If your function is very complicated and time consuming, then it
won't matter how fast MPFIT is. My example shows that even a very
simple quadratic model function with few parameters, already takes
30% of the total execution time to evaluate.

* The function evaluation speed can be significantly improved if you
can compute analytical derivatives.

* If your fit takes too many iterations to converge, then you can
relax the convergence criteria (ftol, xtol, gtol).

* If you're someone like the original poster that has many fits to
perform, with a small number of points per fit, then it might
indeed pay off to group multiple fits together, so you don't incur
the setup and teardown costs of each MPFIT call.

In the meantime I have developed a C library version of the fitter. I
have never tested whether it was faster, since that wasn't the point
(C was a delivery requirement to a larger project).

Happy fitting!
Craig

P.S.
function quad, x, p
return, p[0] + p[1]*x + p[2]*x*x
end


--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: problem with widget_draw and draw_button_events under windows
Next Topic: Re: surface vs. shade_surf

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

Current Time: Wed Oct 08 17:38:26 PDT 2025

Total time taken to generate the page: 0.00426 seconds