Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: robust fitting using lsqcurvefit

Subject: robust fitting using lsqcurvefit

From: ture vp

Date: 12 May, 2008 10:48:03

Message: 1 of 7

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


Subject: Re: robust fitting using lsqcurvefit

From: John D'Errico

Date: 12 May, 2008 11:10:19

Message: 2 of 7

"Ture VP" <turevp@gmail.com> wrote in message
<g09793$4mc$1@fred.mathworks.com>...
> 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

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

Subject: Re: robust fitting using lsqcurvefit

From: Peter Perkins

Date: 12 May, 2008 14:04:18

Message: 3 of 7

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.

Subject: Re: robust fitting using lsqcurvefit

From: ture vp

Date: 14 May, 2008 19:41:01

Message: 4 of 7

"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <g098ir$i7v$1@fred.mathworks.com>...
> "Ture VP" <turevp@gmail.com> wrote in message
> <g09793$4mc$1@fred.mathworks.com>...
> > 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
>
> 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

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




Subject: Re: robust fitting using lsqcurvefit

From: Tom Lane

Date: 14 May, 2008 19:56:07

Message: 5 of 7

> 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


Subject: Re: robust fitting using lsqcurvefit

From: Nicolas

Date: 16 May, 2008 12:55:05

Message: 6 of 7

"Ture VP" <turevp@gmail.com> wrote in message
<g0ff8d$kda$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in
> message <g098ir$i7v$1@fred.mathworks.com>...
> > "Ture VP" <turevp@gmail.com> wrote in message
> > <g09793$4mc$1@fred.mathworks.com>...
> > > 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
> >
> > 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
>
> 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
>
>
>
>

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

Subject: Re: robust fitting using lsqcurvefit

From: Marcus M. Edvall

Date: 19 May, 2008 03:42:24

Message: 7 of 7

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/

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
curve fitting toolbox Ture VP 12 May, 2008 06:50:05
lsqcurvefit Ture VP 12 May, 2008 06:50:05
robust Ture VP 12 May, 2008 06:50:05
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics