Thread Subject: LSQCURVEFIT bounds

Subject: LSQCURVEFIT bounds

From: maria

Date: 4 Mar, 2010 13:26:36

Message: 1 of 8

Hi,
I am using lsqcurvefit to solve an optimization problem. I specify upper and lower bounds for the solutuion, how ever, watching ont the parameters evolution, I have noticed that my fourth parameter goes out of the bounds, it is suppose to be smaller that 0.5 and the algorithm is testing in 30!. Problem is that the algorithm might have found a local minimun there and for this reason, it keeps on trying in this region, which is actually physically imposible.

Anybody has any idea about why is the algorithm testing outside the bounds?. My cost function gives a vector of size 2 which should be near to 0.


lb=[0.05, 0.05, 2, 1e-6, 300];
ub=[2 ,3 , 0.1, 0.5, 600];
options=optimset('TolFun',tol);
x2=lsqcurvefit(@costfunction_V1,parameters,0,[0,0],lb,ub,options);

Thanks in advance.

Mary

Subject: LSQCURVEFIT bounds

From: nico cruz

Date: 4 Mar, 2010 13:52:31

Message: 2 of 8

I know it sounds pretty obvious,

but did you check the order of your parameter vector?

also why are xdata and ydata so small and not equal?

coudl you maybe send some more info about your problem?

nico

"maria " <mariaame@gmail.com> wrote in message <hmocec$fkn$1@fred.mathworks.com>...
> Hi,
> I am using lsqcurvefit to solve an optimization problem. I specify upper and lower bounds for the solutuion, how ever, watching ont the parameters evolution, I have noticed that my fourth parameter goes out of the bounds, it is suppose to be smaller that 0.5 and the algorithm is testing in 30!. Problem is that the algorithm might have found a local minimun there and for this reason, it keeps on trying in this region, which is actually physically imposible.
>
> Anybody has any idea about why is the algorithm testing outside the bounds?. My cost function gives a vector of size 2 which should be near to 0.
>
>
> lb=[0.05, 0.05, 2, 1e-6, 300];
> ub=[2 ,3 , 0.1, 0.5, 600];
> options=optimset('TolFun',tol);
> x2=lsqcurvefit(@costfunction_V1,parameters,0,[0,0],lb,ub,options);
>
> Thanks in advance.
>
> Mary

Subject: LSQCURVEFIT Tolfun and Tolx

From: maria

Date: 8 Mar, 2010 13:03:07

Message: 3 of 8

"nico cruz" <m.nicolas.cruz@mailbox.tu-berlin.de> wrote in message <hmoduv$nbh$1@fred.mathworks.com>...
> I know it sounds pretty obvious,
>
> but did you check the order of your parameter vector?
>
> also why are xdata and ydata so small and not equal?
>
> coudl you maybe send some more info about your problem?
>
> nico
>
> "maria " <mariaame@gmail.com> wrote in message <hmocec$fkn$1@fred.mathworks.com>...
> > Hi,
> > I am using lsqcurvefit to solve an optimization problem. I specify upper and lower bounds for the solutuion, how ever, watching ont the parameters evolution, I have noticed that my fourth parameter goes out of the bounds, it is suppose to be smaller that 0.5 and the algorithm is testing in 30!. Problem is that the algorithm might have found a local minimun there and for this reason, it keeps on trying in this region, which is actually physically imposible.
> >
> > Anybody has any idea about why is the algorithm testing outside the bounds?. My cost function gives a vector of size 2 which should be near to 0.
> >
> >
> > lb=[0.05, 0.05, 2, 1e-6, 300];
> > ub=[2 ,3 , 0.1, 0.5, 600];
> > options=optimset('TolFun',tol);
> > x2=lsqcurvefit(@costfunction_V1,parameters,0,[0,0],lb,ub,options);
> >
> > Thanks in advance.
> >
> > Mary

Hi Nico,

Yes I did it, so I guess it was not the problem. Maybe I have a problem on the definiton of the xdata, I will check. the question is that the function I am trying to fit is a measure which comes from a simulink simulation, so I do not need to define an xdata, I defined it as 0 just because to compute lsqcurvefit it is necessary to have a function like F(x,xdata). ydata is small because it is a cost function in time which has to be close form 0...
By now I found a "solution", I redefined my cost function so it is testing inside the boudns, I guess that I reduced somehow the work that the algorithm has to do... however, now I have another problem...

When I try to define the TolFun and TolX parameters, the algorithm ends with this message:

%%%%%%%
Optimization terminated: directional derivative along search direction less than TolFun and infinity-norm of gradient less than 10*(TolFun+TolX).
%%%%%%%

I know that terminated is a synonimum of end, but, I already know one solution for the function parameters (question is that I need to repeat the procedure with 930 more functions..), which is optimal than the one that I have when I get this message, The algorithm is doing changes in the parameters in the 1e-4 magnitude, which is too small, they are not significative for my problem, In order to solve that, I tried with TolX=1e-2, but when I do that, I get the message that I wrote..

Any idea about how to solve that?

Thanks in advance,

Mary

Subject: LSQCURVEFIT Tolfun and Tolx

From: nico cruz

Date: 9 Mar, 2010 09:02:05

Message: 4 of 8


Hi,

I dontknow if I am the best to answer this question :)



regarding the small changes in your parameters:

the optimizer makes one small change on the parameters to calculate the derivatives (gradients) numerically.
Like in math where dx/dt ~ (x2-x1)/(t2-t1)

after this, it moves in the direction where the objective function seems to decrease.

when the optimizer shows this message:
> %%%%%%%
> Optimization terminated: directional derivative along search direction less than TolFun and infinity-norm of gradient less than 10*(TolFun+TolX).
> %%%%%%%

it is trying to tell you that in the point where he is, the derivatives (meaning the change of the objective function when the parameters are changed) is very small.

the optimizer sees in your obj. func. df/dx = 0, a flat surface (in 3-D problems), though he stops because he has no direction where to move.

hope I could help

"maria " <mariaame@gmail.com> wrote in message <hn2sib$ih0$1@fred.mathworks.com>...
> "nico cruz" <m.nicolas.cruz@mailbox.tu-berlin.de> wrote in message <hmoduv$nbh$1@fred.mathworks.com>...
> > I know it sounds pretty obvious,
> >
> > but did you check the order of your parameter vector?
> >
> > also why are xdata and ydata so small and not equal?
> >
> > coudl you maybe send some more info about your problem?
> >
> > nico
> >
> > "maria " <mariaame@gmail.com> wrote in message <hmocec$fkn$1@fred.mathworks.com>...
> > > Hi,
> > > I am using lsqcurvefit to solve an optimization problem. I specify upper and lower bounds for the solutuion, how ever, watching ont the parameters evolution, I have noticed that my fourth parameter goes out of the bounds, it is suppose to be smaller that 0.5 and the algorithm is testing in 30!. Problem is that the algorithm might have found a local minimun there and for this reason, it keeps on trying in this region, which is actually physically imposible.
> > >
> > > Anybody has any idea about why is the algorithm testing outside the bounds?. My cost function gives a vector of size 2 which should be near to 0.
> > >
> > >
> > > lb=[0.05, 0.05, 2, 1e-6, 300];
> > > ub=[2 ,3 , 0.1, 0.5, 600];
> > > options=optimset('TolFun',tol);
> > > x2=lsqcurvefit(@costfunction_V1,parameters,0,[0,0],lb,ub,options);
> > >
> > > Thanks in advance.
> > >
> > > Mary
>
> Hi Nico,
>
> Yes I did it, so I guess it was not the problem. Maybe I have a problem on the definiton of the xdata, I will check. the question is that the function I am trying to fit is a measure which comes from a simulink simulation, so I do not need to define an xdata, I defined it as 0 just because to compute lsqcurvefit it is necessary to have a function like F(x,xdata). ydata is small because it is a cost function in time which has to be close form 0...
> By now I found a "solution", I redefined my cost function so it is testing inside the boudns, I guess that I reduced somehow the work that the algorithm has to do... however, now I have another problem...
>
> When I try to define the TolFun and TolX parameters, the algorithm ends with this message:
>
> %%%%%%%
> Optimization terminated: directional derivative along search direction less than TolFun and infinity-norm of gradient less than 10*(TolFun+TolX).
> %%%%%%%
>
> I know that terminated is a synonimum of end, but, I already know one solution for the function parameters (question is that I need to repeat the procedure with 930 more functions..), which is optimal than the one that I have when I get this message, The algorithm is doing changes in the parameters in the 1e-4 magnitude, which is too small, they are not significative for my problem, In order to solve that, I tried with TolX=1e-2, but when I do that, I get the message that I wrote..
>
> Any idea about how to solve that?
>
> Thanks in advance,
>
> Mary

Subject: LSQCURVEFIT Tolfun and Tolx

From: Paul Kerr-Delworth

Date: 9 Mar, 2010 10:54:03

Message: 5 of 8

Hi Mary,

As Nico says, the exit message is trying to tell you that the objective function gradient is so small that lsqcurvefit determines that no further progress can be made.

Looking at your problem, I notice that the lower bound for the third parameter (2), is larger than the upper bound (0.1). You should ensure that the upper bound is larger than the lower bound.

You also say that you do not need xdata and ydata for lsqcurvefit and you can just replace xdata with 0. The idea behind lsqcurvefit is that you vary the 5 (in your case) parameters of your objective function to try and fit the curve specified by multiple points defined in xdata and ydata. What you appear to be trying to do is minimize (where p denotes your "parameters" vector)

(costfunction_V1(p, 0) - 0)^2 + (costfunction_V1(p, 0) - 0)^2
= 2(costfunction_V1(p, 0)^2

Do you really mean this? The reason I ask is that you mention a SIMULINK model, and a typical optimization problem here is to try to fit the output of a SIMULINK model to a set of (xdata, ydata) points. If this is really what you're trying to do, then there is an example in the Optimization documentation which may help you:

<<http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brn4noo.html#f11160>>

This example uses lsqnonlin, which uses the same underlying algorithm as lsqcurvefit, to fit parameters of a closed loop controller defined in SIMULINK.

Hope this helps

Best regards,

Paul

"nico cruz" <m.nicolas.cruz@mailbox.tu-berlin.de> wrote in message <hn52qd$43$1@fred.mathworks.com>...
>
> Hi,
>
> I dontknow if I am the best to answer this question :)
>
>
>
> regarding the small changes in your parameters:
>
> the optimizer makes one small change on the parameters to calculate the derivatives (gradients) numerically.
> Like in math where dx/dt ~ (x2-x1)/(t2-t1)
>
> after this, it moves in the direction where the objective function seems to decrease.
>
> when the optimizer shows this message:
> > %%%%%%%
> > Optimization terminated: directional derivative along search direction less than TolFun and infinity-norm of gradient less than 10*(TolFun+TolX).
> > %%%%%%%
>
> it is trying to tell you that in the point where he is, the derivatives (meaning the change of the objective function when the parameters are changed) is very small.
>
> the optimizer sees in your obj. func. df/dx = 0, a flat surface (in 3-D problems), though he stops because he has no direction where to move.
>
> hope I could help
>
> "maria " <mariaame@gmail.com> wrote in message <hn2sib$ih0$1@fred.mathworks.com>...
> > "nico cruz" <m.nicolas.cruz@mailbox.tu-berlin.de> wrote in message <hmoduv$nbh$1@fred.mathworks.com>...
> > > I know it sounds pretty obvious,
> > >
> > > but did you check the order of your parameter vector?
> > >
> > > also why are xdata and ydata so small and not equal?
> > >
> > > coudl you maybe send some more info about your problem?
> > >
> > > nico
> > >
> > > "maria " <mariaame@gmail.com> wrote in message <hmocec$fkn$1@fred.mathworks.com>...
> > > > Hi,
> > > > I am using lsqcurvefit to solve an optimization problem. I specify upper and lower bounds for the solutuion, how ever, watching ont the parameters evolution, I have noticed that my fourth parameter goes out of the bounds, it is suppose to be smaller that 0.5 and the algorithm is testing in 30!. Problem is that the algorithm might have found a local minimun there and for this reason, it keeps on trying in this region, which is actually physically imposible.
> > > >
> > > > Anybody has any idea about why is the algorithm testing outside the bounds?. My cost function gives a vector of size 2 which should be near to 0.
> > > >
> > > >
> > > > lb=[0.05, 0.05, 2, 1e-6, 300];
> > > > ub=[2 ,3 , 0.1, 0.5, 600];
> > > > options=optimset('TolFun',tol);
> > > > x2=lsqcurvefit(@costfunction_V1,parameters,0,[0,0],lb,ub,options);
> > > >
> > > > Thanks in advance.
> > > >
> > > > Mary
> >
> > Hi Nico,
> >
> > Yes I did it, so I guess it was not the problem. Maybe I have a problem on the definiton of the xdata, I will check. the question is that the function I am trying to fit is a measure which comes from a simulink simulation, so I do not need to define an xdata, I defined it as 0 just because to compute lsqcurvefit it is necessary to have a function like F(x,xdata). ydata is small because it is a cost function in time which has to be close form 0...
> > By now I found a "solution", I redefined my cost function so it is testing inside the boudns, I guess that I reduced somehow the work that the algorithm has to do... however, now I have another problem...
> >
> > When I try to define the TolFun and TolX parameters, the algorithm ends with this message:
> >
> > %%%%%%%
> > Optimization terminated: directional derivative along search direction less than TolFun and infinity-norm of gradient less than 10*(TolFun+TolX).
> > %%%%%%%
> >
> > I know that terminated is a synonimum of end, but, I already know one solution for the function parameters (question is that I need to repeat the procedure with 930 more functions..), which is optimal than the one that I have when I get this message, The algorithm is doing changes in the parameters in the 1e-4 magnitude, which is too small, they are not significative for my problem, In order to solve that, I tried with TolX=1e-2, but when I do that, I get the message that I wrote..
> >
> > Any idea about how to solve that?
> >
> > Thanks in advance,
> >
> > Mary

Subject: LSQCURVEFIT bounds

From: Stefan

Date: 9 Mar, 2010 11:32:04

Message: 6 of 8

M;aybe I'm missing something, but why is in

lb=[0.05, 0.05, 2, 1e-6, 300];
ub=[2 ,3 , 0.1, 0.5, 600];

at the third position the lower bound greater than the upper bound?

Regards,
Stefan

"maria " <mariaame@gmail.com> wrote in message <hmocec$fkn$1@fred.mathworks.com>...
> Hi,
> I am using lsqcurvefit to solve an optimization problem. I specify upper and lower bounds for the solutuion, how ever, watching ont the parameters evolution, I have noticed that my fourth parameter goes out of the bounds, it is suppose to be smaller that 0.5 and the algorithm is testing in 30!. Problem is that the algorithm might have found a local minimun there and for this reason, it keeps on trying in this region, which is actually physically imposible.
>
> Anybody has any idea about why is the algorithm testing outside the bounds?. My cost function gives a vector of size 2 which should be near to 0.
>
>
> lb=[0.05, 0.05, 2, 1e-6, 300];
> ub=[2 ,3 , 0.1, 0.5, 600];
> options=optimset('TolFun',tol);
> x2=lsqcurvefit(@costfunction_V1,parameters,0,[0,0],lb,ub,options);
>
> Thanks in advance.
>
> Mary

Subject: LSQCURVEFIT bounds

From: Paul Kerr-Delworth

Date: 11 Mar, 2010 10:34:06

Message: 7 of 8

Hi Stefan,

I meant that the third element of lb is greater than the third element of ub. To see this, run the following at the MATLAB command prompt

lb=[0.05, 0.05, 2, 1e-6, 300];
ub=[2 ,3 , 0.1, 0.5, 600];
lb > ub

ans =

     0 0 1 0 0

(Because the third element of lb (2) is greater than the third element of ub (0.1))

Best regards,

Paul

"Stefan" <nospam@yahoo.com> wrote in message <hn5bjk$mer$1@fred.mathworks.com>...
> M;aybe I'm missing something, but why is in
>
> lb=[0.05, 0.05, 2, 1e-6, 300];
> ub=[2 ,3 , 0.1, 0.5, 600];
>
> at the third position the lower bound greater than the upper bound?
>
> Regards,
> Stefan
>
> "maria " <mariaame@gmail.com> wrote in message <hmocec$fkn$1@fred.mathworks.com>...
> > Hi,
> > I am using lsqcurvefit to solve an optimization problem. I specify upper and lower bounds for the solutuion, how ever, watching ont the parameters evolution, I have noticed that my fourth parameter goes out of the bounds, it is suppose to be smaller that 0.5 and the algorithm is testing in 30!. Problem is that the algorithm might have found a local minimun there and for this reason, it keeps on trying in this region, which is actually physically imposible.
> >
> > Anybody has any idea about why is the algorithm testing outside the bounds?. My cost function gives a vector of size 2 which should be near to 0.
> >
> >
> > lb=[0.05, 0.05, 2, 1e-6, 300];
> > ub=[2 ,3 , 0.1, 0.5, 600];
> > options=optimset('TolFun',tol);
> > x2=lsqcurvefit(@costfunction_V1,parameters,0,[0,0],lb,ub,options);
> >
> > Thanks in advance.
> >
> > Mary

Subject: LSQCURVEFIT bounds

From: Stefan

Date: 11 Mar, 2010 12:09:05

Message: 8 of 8

Hi Paul,

my question was directed to Maria. Unfortunately I didn't read your post carefully. ;)

Regards,
Stefan


"Paul Kerr-Delworth" <paul.kerr-delworth@mathworks.co.uk> wrote in message <hnaguu$9v2$1@fred.mathworks.com>...
> Hi Stefan,
>
> I meant that the third element of lb is greater than the third element of ub. To see this, run the following at the MATLAB command prompt
>
> lb=[0.05, 0.05, 2, 1e-6, 300];
> ub=[2 ,3 , 0.1, 0.5, 600];
> lb > ub
>
> ans =
>
> 0 0 1 0 0
>
> (Because the third element of lb (2) is greater than the third element of ub (0.1))
>
> Best regards,
>
> Paul
>
> "Stefan" <nospam@yahoo.com> wrote in message <hn5bjk$mer$1@fred.mathworks.com>...
> > M;aybe I'm missing something, but why is in
> >
> > lb=[0.05, 0.05, 2, 1e-6, 300];
> > ub=[2 ,3 , 0.1, 0.5, 600];
> >
> > at the third position the lower bound greater than the upper bound?
> >
> > Regards,
> > Stefan
> >
> > "maria " <mariaame@gmail.com> wrote in message <hmocec$fkn$1@fred.mathworks.com>...
> > > Hi,
> > > I am using lsqcurvefit to solve an optimization problem. I specify upper and lower bounds for the solutuion, how ever, watching ont the parameters evolution, I have noticed that my fourth parameter goes out of the bounds, it is suppose to be smaller that 0.5 and the algorithm is testing in 30!. Problem is that the algorithm might have found a local minimun there and for this reason, it keeps on trying in this region, which is actually physically imposible.
> > >
> > > Anybody has any idea about why is the algorithm testing outside the bounds?. My cost function gives a vector of size 2 which should be near to 0.
> > >
> > >
> > > lb=[0.05, 0.05, 2, 1e-6, 300];
> > > ub=[2 ,3 , 0.1, 0.5, 600];
> > > options=optimset('TolFun',tol);
> > > x2=lsqcurvefit(@costfunction_V1,parameters,0,[0,0],lb,ub,options);
> > >
> > > Thanks in advance.
> > >
> > > Mary

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
lsqcurvefit tol... maria 8 Mar, 2010 08:04:27
lsqcurvefit bounds maria 4 Mar, 2010 08:29:07
rssFeed for this Thread

Contact us at files@mathworks.com