Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

robust fitting using lsqcurvefit

511 views
Skip to first unread message

Ture VP

unread,
May 12, 2008, 6:48:03 AM5/12/08
to
Hi,

I am fitting my data with 'lsqcurvefit'. This works fine.
But now I would like to include a robust fitting procedure.

It was not clear to me from the help function whether or not
this is possible. In the section about robust fitting it is
written that on can use it for non-linear least square
problems. However I cannot find how to turn it on for my
function (here the options have to be set using 'optimset'
which does not like the option 'robust','on')

Ture


John D'Errico

unread,
May 12, 2008, 7:10:19 AM5/12/08
to
"Ture VP" <tur...@gmail.com> wrote in message
<g09793$4mc$1...@fred.mathworks.com>...

How can it be not clear in the help?

No place in the help for lsqcurvefit is the word
"robust" ever used. At least, find never located
the word, nor did quick a search I find that
word in any function in the entire optimization
toolbox. There is absolutely no implication that
this code is or can be used for anything but a
standard nonlinear least squares solution.

As far as using a non-existent 'robust' option
in optimset, you cannot simply make up an
option and pretend that it now is valid in
optimset. It is Monday. Can I now change the
day to last Thursday by setting

options = optimset('DayOfWeek','lastthursday');

While I admit that I've not tried this simple test,
it seems highly likely to fail.

You can find robustfit in the statistics toolbox.

John

Peter Perkins

unread,
May 12, 2008, 10:04:18 AM5/12/08
to
Ture VP wrote:

> I am fitting my data with 'lsqcurvefit'. This works fine.
> But now I would like to include a robust fitting procedure.

Ture, depending on what toolboxes you have access to, you may be able to use
NLINFIT or ROBUSTFIT from the Statistics Toolbox, or FIT from the Curve Fitting
Toolbox.

Hope this helps.

- Peter Perkins
The MathWorks, Inc.

Ture VP

unread,
May 14, 2008, 3:41:01 PM5/14/08
to
"John D'Errico" <wood...@rochester.rr.com> wrote in
message <g098ir$i7v$1...@fred.mathworks.com>...

Dear John,

There is absolutely no need here to become sarcastic. In
fact, your answer is not helping anything.

First of all I am of course aware that the robust fitting is
not part of the optimization toolbox. However my question
concerned 'lsqcurvefit' which is part of the curve fitting
toolbox. In this toolbox you do have options for robust
fitting (e.g. the function 'fit', as also mentioned by Peter
Perkins).

I like 'lsqcurvefit' because it is extremely fast, has upper
and lower bounds and allows me to play with gradients and
hessians. The function 'fit' on the other hand is much
slower and if you want to fit a few ten thousand spectra you
do want to optimize the speed of the fitting routine.
'robustfit' and nlinfit are absolutely not suitable for my
purposes.

Concerning your comment about the help: maybe I am not a
genius as you are and yes, I do get sometimes lost in the
help functions of all these toolboxes (I have access to most
of them).

In the past I was actually using 'fminunc' and 'fminsearch'
from the optimization toolbox where I added myself the
robust part. But again here these routines are not really
fast and not optimized for complex curve fitting (e.g. no
upper and lower bounds).

I could somehow live with the 'fit' function but it is not
clear to me how to e.g. use a split pearsonVII (where the
function is defined by two separate equations).

So to cut long story short: what is actually the fundamental
reason that some functions have the option for robust
fitting and others don't?

Cheers!

Ture

Steven


Tom Lane

unread,
May 14, 2008, 3:56:07 PM5/14/08
to
> First of all I am of course aware that the robust fitting is
> not part of the optimization toolbox. However my question
> concerned 'lsqcurvefit' which is part of the curve fitting
> toolbox.

Ture, part of the confusion is that lsqcurvefit is actually in the
Optimization Toolbox, even though its name sounds like it might be in the
Curve Fitting Toolbox.

The lsqcurvefit function has no built-in robust support, and I don't see a
good way to trick it into doing a robust fit. You might want to try the
lsqnonlin function instead. It expects your function to return a vector of
residuals directly (rather than fitted values). You could perhaps write
your function to return weighted residuals, with the weights chosen to
downweight outliers.

-- Tom


Nicolas

unread,
May 16, 2008, 8:55:05 AM5/16/08
to
"Ture VP" <tur...@gmail.com> wrote in message
<g0ff8d$kda$1...@fred.mathworks.com>...

Dear Steven,

I read that you used fminunc to do robust fitting. If you
have the R2008A of the optimization toolbox, you might also
try ktrlink that uses the knitro solver.
If needed, I can provide you with a one-month trial license
of knitro for matlab.

Nicolas Omont

Marcus M. Edvall

unread,
May 18, 2008, 11:42:24 PM5/18/08
to
The best is normally to use NLSSOL (for dense problems) and slsSolve
for sparse problems since the sparsity can be transferred to the
constraints.

You can get a demo from here as needed: http://tomopt.com/scripts/register.php

Of course you can also use TOMLAB /KNITRO with slsSolve and MAD
(automatic differentiation) to get good results as well.

Best wishes, Marcus
Tomlab Optimization Inc.
http://tomopt.com/tomlab/

0 new messages