Fmincon question:1.contraint violation but with no warning/error; 2. difference between the final output of Fmincon (the X in X=fmincon()) and the intermediate x

1 view (last 30 days)
Hi All,
I found 2 pretty wired "features" of fmincon function when I was using fmincon to solve constrained optimization problems. First, it is very wired to have the difference between the final output of Fmincon (the X in X=fmincon()) and the intermediate x.
Second, I could see the nonlinear constraint is active meaning constraint is met but for the final result X outputted by X=fmicon(...) it does violate my nonlinear constraint. However, there is no error/warning at all.
I suppose that for the very last intermediate x and final output X should be the same theoretically. However, what I saw was not the case. They are very different.
I used active-set method in Fmincon. The document does mention that the active set method may violate the constraint in intermediate step. Sometimes I even saw the following case:
This is my last iterated u which is a function of my intermediate x (my upper limit for each element in vector u is 2 and you can see the third one from the bottom is way beyond 2):
u =
2.0000
2.0000
2.0000
2.0000
2.0000
2.0000
2.0000
188.7080
-0.0000
0.7391
This is the u I calculated by fmicon output X = fmincon and you can see how different they are compared to above intermediate u:
2.0000
22.9268
2.0000
15.7579
2.0000
16.2252
2.0000
2.0000
2.0000
996.8367
And here is what Matlab showed:
Local minimum possible. Constraints satisfied.
fmincon stopped because the size of the current search direction is less than
twice the default value of the step size tolerance and constraints are
satisfied to within the default value of the constraint tolerance.
Here is how I can tell my 11th to 20th constraints (the ones corresponds to my u) are active
Active inequalities (to within options.TolCon = 1e-06):
lower upper ineqlin ineqnonlin
11
12
13
14
15
16
17
18
19
20
Here is what I mean by saying Final output and intermediate x:
Final output: the X in X=fmincon(),that is the final result generated outputted by fmincon function.
Intermediate x:the x used in cost function, nonlinear constraints function in fmincon. For example,
X = fmincon(@cost_function,X0, [],[],[],[],[],[], @nonlinear_constraint);
% X is the final output
For the nonlinear constraint, I have
function [c,ceq]=nonlinear_constraint(x)
...
x % this is the intermediate x and this is how I can see the intermediate variable
end
Cut long story short: 1.why does the results outputted by fmincon violate the constraints? 2.why are intermediate x and Fmincon output different? I was totally confused on this since these are not how things should work.
Thanks a lot! :)
Ji

Answers (1)

Alan Weiss
Alan Weiss on 2 Mar 2015
It depends on how you are giving the upper bound. Is
ub = 2*ones(size(x0))
or is
ub = 2 ?
You need to give an upper bound for ever component of the solution. Clearly, from the exit message fmincon believes that the constraints are satisfied, so it does not know that you want all the elements to be bounded above by 2.
There is something else that might be going on. It seems that there might be a difference between your variable u that is larger than 2 and the control variable x (the one that fmincon is optimizing).
In any case, I suggest that you put a break point in fmincon and step through the program so that you can see if fmincon thinks that ub is a vector of all 2.
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Comments
JI LIU
JI LIU on 2 Mar 2015
Edited: JI LIU on 2 Mar 2015
Hi Alan,
Thanks for answering my question! And I am sorry for the confusion.
For my problem, I do not have any bounds on the control variable. The u in my question is a nonlinear function of x and I constrained u using nonlinear constraint.
X = fmincon(@costfunction,X0, [],[],[],[],[],[], @nonlinear_constraint);
I did try to add a break point in fmincon but I did not see any wired thing. Sometimes in the fmincon function very thing works just fine, but due to the output X given by fmicon is different from the x I saw inside fmincon I can see the output X violate the constraint.
Do you have any other thoughts on the difference between the control variable x (intermediate variable x) in fmincon and the output X outputted by fmincon? Thank you so much!
Alan Weiss
Alan Weiss on 3 Mar 2015
I am sorry, but I have a very hard time understanding you. So please be patient if my comment is not on point, because I get quite confused by your terminology.
In Optimization Toolbox, the control variables are typically called x. This is a vector or array that fmincon tries to change to minimize the objective function fun(x). Any intermediate values, which you seem to variously call u or X, are functions that your own program calculates.
Nonlinear constraints in fmincon have to be passed a particular way. I don't know how your nonlinear constraint function works or doesn't work. It seems to be allowing at least one component of your "u" (whatever that is) to take a value larger than you want. But fmincon doesn't see a constraint violation. Therefore I conclude that your nonlinear constraint does not restrict "u" the way you want it to. Check that function again.
Sorry, that is the best advice I can give you with the information you have provided.
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!