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

Home » Public Forums » archive » Re: What is the difference between 'curvefit', 'lmfit' and 'svdfit' procudure?
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: What is the difference between 'curvefit', 'lmfit' and 'svdfit' procudure? [message #52883] Thu, 08 March 2007 07:53
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Wox wrote:
> On 07 Mar 2007 21:07:36 -0500, Craig Markwardt
> <craigmnet@REMOVEcow.physics.wisc.edu> wrote:
>
> <snip>
>> CURVEFIT - poor man's non-linear least squares original to IDL, based
>> on gradient expansion and not really robust.
> <snip>
>
> I always thought CURVEFIT was using Levenberg-Marquardt. Check the use
> of lambda, which allows the alternation between gradient and expansion
> method (which is the Levenberg-Marquardt as far as I know).

Regardless, CURVEFIT is nowhere near as robust as Craig's replacement for it. A while back
I used CURVEFIT on some data I was trying to fit (infrared sea surface emissivity that
depended on frequency, wind speed, and view angle) and, when I did get convergence, it
took forever. Using MPFIT (not changing anything else related to the data I was fitting),
I *always* got convergence and it ran orders of magnitude faster.

Single data point anecdotal evidence I know, but there you go.

cheers,

paulv

--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx
Re: What is the difference between 'curvefit', 'lmfit' and 'svdfit' procudure? [message #52893 is a reply to message #52883] Thu, 08 March 2007 01:53 Go to previous message
Wox is currently offline  Wox
Messages: 184
Registered: August 2006
Senior Member
On 07 Mar 2007 21:07:36 -0500, Craig Markwardt
<craigmnet@REMOVEcow.physics.wisc.edu> wrote:

<snip>
> CURVEFIT - poor man's non-linear least squares original to IDL, based
> on gradient expansion and not really robust.
<snip>

I always thought CURVEFIT was using Levenberg-Marquardt. Check the use
of lambda, which allows the alternation between gradient and expansion
method (which is the Levenberg-Marquardt as far as I know).
Re: What is the difference between 'curvefit', 'lmfit' and 'svdfit' procudure? [message #52897 is a reply to message #52893] Wed, 07 March 2007 18:07 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
"duxiyu@gmail.com" <duxiyu@gmail.com> writes:
> Thank you very much!
> I have download the MPFIT package.
> Now I'm studying it. ^_^
> But in your package there is not procedure named 'MPEVALEXPR' which is
> in the sentence 'yfit = MPEVALEXPR(expr, x, p) Expression named expr'.

It's hidden inside mpfitexpr.pro, and only needed if you want to
evaluate a user expression for parameter values *other* than the best
fit values. Given that most people would use MPFITEXPR()
interactively from the command line, this is not a problem. (You can
also use 'forward_function mpevalexpr' to make sure it is available in
canned a script.) This is of course not an issue with MPFITFUN(),
which I recommended.

> By the way, I wonder the difference between LMFIT and CURVEFIT very
> much.
> Are their function the same as each other?

CURVEFIT - poor man's non-linear least squares original to IDL, based
on gradient expansion and not really robust.
LMFIT - probably more robust non-linear least squares with
Levenberg-Marquardt technique. It still has some fatal
flaws, like evaluating the user function one point at a time.
This routine was released after MPFIT.
LINFIT - for fitting a straight line to XY data only.
POLY_FIT - for fitting a polynomial to XY data.
SVDFIT - for fitting a linear combination of any basis functions.
LADFIT - for fitting a straight line, but *not* least squares
(more robust against outliers)

Good luck,
Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: What is the difference between 'curvefit', 'lmfit' and 'svdfit' procudure? [message #52898 is a reply to message #52897] Wed, 07 March 2007 17:19 Go to previous message
duxiyu@gmail.com is currently offline  duxiyu@gmail.com
Messages: 88
Registered: March 2007
Member
On Mar 7, 11:02 pm, "R.G. Stockwell" <n...@email.please> wrote:
> <dux...@gmail.com> wrote in message
>
> news:1173260085.952428.100150@q40g2000cwq.googlegroups.com.. .
>
>> I have a set of 'x' and 'y', and want to use a special function 'f(x)'
>> to fit it.
>
>> The function 'f(x)' contains three parameters.
>
>> But I'm confused by the three different procudure 'curvefit', 'lmfit'
>> and 'svdfit'.
>
> The difference is essentially between 1) linear least square error fits,
> and 2) non-linear least square error fit.
>
> In 1) you directly calculate the resulting fit.
> You start with the matrix equation
> Ax = b
>
> where x is the unknown. 'A 'is a matrix where your
> fitting function is evaluated at each point (and is usually
> not square).
>
> The LSF solution is:
>
> A^tAx = A^tb
> x = (A^tA)A^tb
>
> The svd routines solve this matrix equation.
>
> For 2) you make an error function
> error = data - nonlinear function(x)
>
> and you search around parameter space to try to
> find the minimum error. This may not converge, it probably
> depends on an initial guess, and can be very time consuming.
> This is what curvefit and the others do.
>
> If you can create a linear fit, then 1) is the way to go.
> If it is non-linear, google fpr mpfit, widely hailed as a superior
> non-linear fitting routine.
> (i'll google: http://cow.physics.wisc.edu/~craigm/idl/idl.html)
>
> Cheers,
> bob

Thanks for your explaination.
In your statement 1) means SVDFIT and 2) means LMFIT and CURVEFIT,
doesn't it?
When I want to create a linear fit, there are many choices like
LINFIT, LADFIT and SVDFIT.
But I'm confused which one I should select.

Best regards,
Du Jian
Re: What is the difference between 'curvefit', 'lmfit' and 'svdfit' procudure? [message #52899 is a reply to message #52898] Wed, 07 March 2007 17:08 Go to previous message
duxiyu@gmail.com is currently offline  duxiyu@gmail.com
Messages: 88
Registered: March 2007
Member
On Mar 7, 10:20 pm, Craig Markwardt
<craigm...@REMOVEcow.physics.wisc.edu> wrote:
> "dux...@gmail.com" <dux...@gmail.com> writes:
>> I have a set of 'x' and 'y', and want to use a special function 'f(x)'
>> to fit it.
>> The function 'f(x)' contains three parameters.
>> But I'm confused by the three different procudure 'curvefit', 'lmfit'
>> and 'svdfit'.
>> It seems that all of them can meet my request, but I don't know the
>> difference between them.
>
> SVDFIT is for fitting linear combinations of basis functions, probably
> not what you wanted. You could use LMFIT or CURVEFIT.
>
> You can also graduate straight to MPFIT and MPFITFUN which are both
> easier to use, and give you more options when you need them.
>
> Good luck!
> Craig
>
> Seehttp://cow.physics.wisc.edu/~craigm/idl/idl.html (under Curve Fitting)
> --
> ------------------------------------------------------------ --------------
> Craig B. Markwardt, Ph.D. EMAIL: craigm...@REMOVEcow.physics.wisc.edu
> Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
> ------------------------------------------------------------ --------------

Thank you very much!
I have download the MPFIT package.
Now I'm studying it. ^_^
But in your package there is not procedure named 'MPEVALEXPR' which is
in the sentence 'yfit = MPEVALEXPR(expr, x, p) Expression named expr'.

By the way, I wonder the difference between LMFIT and CURVEFIT very
much.
Are their function the same as each other?

Best regards,
Du Jian
Re: What is the difference between 'curvefit', 'lmfit' and 'svdfit' procudure? [message #52910 is a reply to message #52899] Wed, 07 March 2007 07:02 Go to previous message
news.qwest.net is currently offline  news.qwest.net
Messages: 137
Registered: September 2005
Senior Member
<duxiyu@gmail.com> wrote in message
news:1173260085.952428.100150@q40g2000cwq.googlegroups.com.. .
> I have a set of 'x' and 'y', and want to use a special function 'f(x)'
> to fit it.
>
> The function 'f(x)' contains three parameters.
>
> But I'm confused by the three different procudure 'curvefit', 'lmfit'
> and 'svdfit'.

The difference is essentially between 1) linear least square error fits,
and 2) non-linear least square error fit.


In 1) you directly calculate the resulting fit.
You start with the matrix equation
Ax = b

where x is the unknown. 'A 'is a matrix where your
fitting function is evaluated at each point (and is usually
not square).

The LSF solution is:

A^tAx = A^tb
x = (A^tA)A^tb

The svd routines solve this matrix equation.

For 2) you make an error function
error = data - nonlinear function(x)

and you search around parameter space to try to
find the minimum error. This may not converge, it probably
depends on an initial guess, and can be very time consuming.
This is what curvefit and the others do.


If you can create a linear fit, then 1) is the way to go.
If it is non-linear, google fpr mpfit, widely hailed as a superior
non-linear fitting routine.
(i'll google: http://cow.physics.wisc.edu/~craigm/idl/idl.html)


Cheers,
bob
Re: What is the difference between 'curvefit', 'lmfit' and 'svdfit' procudure? [message #52913 is a reply to message #52910] Wed, 07 March 2007 06:20 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
"duxiyu@gmail.com" <duxiyu@gmail.com> writes:

> I have a set of 'x' and 'y', and want to use a special function 'f(x)'
> to fit it.
> The function 'f(x)' contains three parameters.
> But I'm confused by the three different procudure 'curvefit', 'lmfit'
> and 'svdfit'.
> It seems that all of them can meet my request, but I don't know the
> difference between them.

SVDFIT is for fitting linear combinations of basis functions, probably
not what you wanted. You could use LMFIT or CURVEFIT.

You can also graduate straight to MPFIT and MPFITFUN which are both
easier to use, and give you more options when you need them.

Good luck!
Craig

See http://cow.physics.wisc.edu/~craigm/idl/idl.html (under Curve Fitting)
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: strange behaviour of ladfit - known?
Next Topic: using Container object for Strings?

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

Current Time: Thu Oct 09 14:23:18 PDT 2025

Total time taken to generate the page: 0.08059 seconds