Balance between values of cost function and constraint tolerance in fmincon

7 views (last 30 days)
Dear all, I am optimizing a trajectory using fmincon with ODE. My code includes cost function and one equality constraint. Both values can be obtained after numerical integration of ODE.
My question is: Is it necessary to scale the magnitude of the values of cost function and constraint tolerance when using fmincon? If my cost function is scaled in the similar order of my constraint tolerance (~10^-10), cost function becomes small and first order optimality value also becomes small around acceptable order in my problem. As information, my code can find a feasible solution which meets the equality constraint, and the remaining problem is the first order optimality value.
Regards, Kenta

Accepted Answer

Matt J
Matt J on 8 Sep 2014
Edited: Matt J on 8 Sep 2014
I think what you're seeing is unrelated to TolCon. I think that by scaling your objective function smaller, you are simply scaling down its derivatives, and hence also the first order optimality measure, in a proportionate way. The smaller value of the first order optimality measure isn't an indication that you've gotten closer to the ideal minimum.
For example when I run as below,
[x,~,~,s]=fmincon(@(x) x^2,3,[],[],[],[],-10,10,[],optimset('TolFun',1e-10));
I get a solution of x=-1.9868e-08 and a first order optimality measure of s.firstorderopt=5.4638e-08. However, when I put a large scaling weight on the objective,
[x,~,~,s]=fmincon(@(x) 1e6*x^2,3,[],[],[],[],-10,10,[],optimset('TolFun',1e-10));
I get a solution even closer to the ideal one x=5.1583e-09, but a much larger first order optimality measure of 0.0252.
  2 Comments
Kenta
Kenta on 8 Sep 2014
Thanks again for your kind answer. I now understand my wrong point. Then, it seems to be very difficult to be confident whether one's result is optimal or not because the exitflag after convergence cannot be 1 if scaling of cost function is bad. If you know, could you tell how we can comfirm the optimality?
Matt J
Matt J on 8 Sep 2014
Edited: Matt J on 9 Sep 2014
I think what most people do is they run simulations of the problem in which they know what the result of fmincon should be. Then you can directly observe how small the optimality measure will typically be near a true or useful solution.
The rigorous, but not always practical thing, would probably be to compute the gradient g and Hessian H of the Lagrangian L(x,lambda ) at the final solution with respect to x. The Newton direction -H\g is invariant to the scaling of the objective function and should be small near the solution if H is non-singular there. That won't be the case for all solutions, of course. Only for solutions satisfying second order sufficient optimality conditions, etc... But for nicely behaved problems, this should be the case. Computing H and g could also be difficult. Note that they are not the same as the gradient and Hessian output args of fmincon
[x,fval,exitflag,output,lambda,grad,hessian] = fmincon(...)
but you could use the lambda output arg to facilitate your own calculation.

Sign in to comment.

More Answers (1)

Matt J
Matt J on 8 Sep 2014
Edited: Matt J on 8 Sep 2014
The scaling of your objective function (and constraints) definitely interacts with the tolerance values. For example,
>> x=fmincon(@(x) x^2,3,[],[],[],[],-10,10,[],optimset('TolFun',10e-10))
x =
-1.9868e-08
but,
>> x=fmincon(@(x) 1e-6*x^2,3,[],[],[],[],-10,10,[],optimset('TolFun',10e-10));
x =
3
but then again,
>> x=fmincon(@(x) 1e-6*x^2,3,[],[],[],[],-10,10,[],optimset('TolFun',10e-15));
x =
-1.1850e-05
  1 Comment
Kenta
Kenta on 8 Sep 2014
Dear Matt J, I think your comment is exactly true. Indeed, I have changed the values of coefficients of my cost function 1000,1,10^-3,10^-6,10^-9,10^-12 and confirmed that solutions were always similar value, but first order optimality values were 20000,20,2*10^-2,2*10^-5,2*10^-8,2*10^-11. Thus, I guess they may all converge to optimal solutions, but the 'looks' , i.e., the first order optimality, just different. Regards, Kenta.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!