What is the difference between flag 1 and flag 2?
14 views (last 30 days)
Show older comments
Deepshikha Acharya
on 29 Oct 2020
Commented: Deepshikha Acharya
on 30 Oct 2020
Hi,
I am using the interior-point (default) method to minimize my optimization function using fmincon. I am a little confused about which flag truly represents "solution found". Especially confused about the difference in a flag 2 and a flag 1 answer.
Thanks for the help :)
0 Comments
Accepted Answer
Walter Roberson
on 30 Oct 2020
Exit flag 1: stopped because the optimality was low enough, and the constraints are not too badly violated
Exit flag 2: stopped because the step size was low enough, and the constraints are not too badly violated
fmincon does not know how small the function value can get, or how "bumpy" the surface is (the more bumpy a surface is, the more likely you got stuck in a local minimum that is not the best available in the area.) So fmincon has algorithms to guess how well it is doing on the optimization, with it creating a statistic that it calls "first-order optimality". It measures factors such as relative change in function values. It does not try to find the absolute best it can find in the area: it stops when it figures that the change is "not very much" -- because a lot of time, getting the absolute best possible value is a waste of time (and not justified by the accuracy of the inputs.) When it stops because it figures it has done a "good enough" job, the exit flag is 1.
But sometimes it can think there is still room for improvement, but it has reached the limit of how small of a step that has been configured to take. When it stops for this reason, the exit flag is 2.
Imagine two functions that have the same minimum, but in one case the function is broad and locally shallow: then it might be time to give up with exit flag 1 "because this is getting boring, not much is changing." Compare to a function that is locally steep by comparison, where fmincon is stopping because you asked it not to bother with changing the positions by too little, the exit flag 2 case.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!