why does fmincon fain to converge when I just change the constraints

1 view (last 30 days)
Hi guys,
I have a question about how does fmincon work with constraints. Basically I have a function f(p1,p2,p3) that I want to minimize. When I add the constraint p1+p2+p3<=1 and p1>0.001 p2>0.001 p3>0.001, there is no problem for fmincon to converge. Notice I put the constraint that p1>0.001 and p2>0.001 and p3>0.001 because they can not equal to 0. Otherwise there will be NaN for the value of f.
Then I change the constraint to p1+p2+p3=1, still with the constraints that p1>0.001 and p2>0.001 and p3>0.001. Then fmincon fails to converge. I know there is possibility that there is a bug in the function f. But I just want to ask, is there any reason that this would happen when f is absolutely right? Do my constraints violate some sort of principle for fmincon to work properly anyway?
  4 Comments
Matt J
Matt J on 7 Mar 2014
Notice I put the constraint that p1>0.001 and p2>0.001 and p3>0.001 because they can not equal to 0. Otherwise there will be NaN for the value of f.
This will only work if you are using one of FMINCON's algorithms that can enforce bound constraints at all iterations (sqp or interior-point).
Matt J
Matt J on 7 Mar 2014
Note also that with the 'sqp' algorithm, you do not need to supply positivity constraints. If the algorithm strays into a region where the function is non-finite, sqp can recover.

Sign in to comment.

Answers (1)

Matt J
Matt J on 7 Mar 2014
Edited: Matt J on 7 Mar 2014
Different points can be easier to converge to than others. It's possible that the Hessian is singular at the solution under p1+p2+p3=1. One thing you can try is to reformulate the problem in 2D and see if it improves performance:
min g(p1,p2) = f(p1,p2,1-p1-p2)
p1>=0.001
p2>=0.001
p1+p2<=0.999
  4 Comments
xueqi
xueqi on 9 Mar 2014
Edited: Matt J on 9 Mar 2014
I have debug it yesterday and I found the problem comes from here. I use pattersearch before fmincon for a rough search and even I set the constraint as p1+p2+p3=1, it still search a point which let p1+p2+p3=1.08!! The function is definitely has a NaN value when p1+p2+p3>1. Could you tell me how do these optimization treat the constraint anyway?
A follow up question is as follows. If I set the inequality constraint as p1+p2+p3<=1, does fmincon still look for points on p1+p2+p3=1? I optimize f using constraint p1+p2+p3<=1 and also constraint p1+p2+p3=1. But it turns out the second one gives a lower value. It is strange! As the equality constraint is embedded insider the inequality constraint.
Thanks a lot!
Matt J
Matt J on 9 Mar 2014
Edited: Matt J on 9 Mar 2014
The function is definitely has a NaN value when p1+p2+p3>1
If that's true, there is something not legal about your function. FMINCON requires the objective function and constraints to be defined and differentiable on an open superset of the feasible region. In fact, for a function to be differentiable at all, it by definition must be defined on some open set. Since p1+p2+p3<=1 is a closed set, your function violates this.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!