fmincon; produces different answers against theoretically the same question ...
Show older comments
Hi all, I have a curiosity, I'm optimizing a non-linear function. There are some equality conditions (i.e the sum of the answers must equal 1), and then some boundaries 0 < x_i < 0.2.
There are eight variables. I can imagine two ways to solve the problem;
weights = fmincon(@absexp,x0,A,b,Aeq,beq,[],[],[],options);
weights2 = fmincon(@absexp,x0,[],[],Aeq,beq,lb,ub,[],options);
In the second case, I impose the constraints as bounds which are passed directly to fmincon.
In the first case, A and b represent inequalities which setup the same constraints... by saying that;
- x_i >= 0 and x_i <= 0.2
What's interesting is that the two solutions yield different results from the same starting conditions. Nearly 1% on x_1 ... so it's not negligible, and I believe it's way outside of the default tolerance for a solution that fmincon advertises as it's default (I think?).
Is this reasonable? Is there something here that would cause matlab to wheel in fundamentally different algorithms for the solution?
Any opinion greatly appreciated! Simon
Answers (2)
Alan Weiss
on 21 Sep 2015
0 votes
Bound constraints are indeed handled differently than linear inequality constraints. You are likely to get a faster, more accurate solution using bounds than linear inequalities, but not always. That is one reason why the documentation recommends using bounds when possible instead of linear or nonlinear constraints.
As the documentation describes, several fmincon algorithms can satisfy bounds at every iteration. There is no such guarantee for linear constraints.
Alan Weiss
MATLAB mathematical toolbox documentation
4 Comments
several fmincon algorithms can satisfy bounds at every iteration. There is no such guarantee for linear constraints.
Further to Alan's point, if your objective function is differentiable only in the interior of the region where the bounds are satisfied, then confining the algorithm's iterations to that interior region is the only way to ensure that the algorithm will converge properly.
I don't know what your @absexp function looks like, but if it looks something like this,
f(x)=exp(abs(x))
then it is an example of what I'm talking about. If you specify explicit positivity bounds lb=0, then fmincon's default interior-point algorithm should ensure that x>0 at all iterations and avoid the non-differentiability (except asymptotically) at x=0. You might also need to use GradObj='on' to avoid finite differencing samples being chosen from the bad region x<=0.
John D'Errico
on 12 Jan 2022
It is surely still a good idea.
I could have sworn seeing an indication in the code that the toolbox now pre-processes A,b to see if any of the general linear inequality constraints are bound constraints. The following test indicates, though, that that is not the case,
A=[-eye(2);eye(2)]; b=[0; 0; 1 ;1];
opts=optimoptions('fmincon','Display','iter');
fmincon(@(x) norm(x)^2,[10,5],A,b,[],[],[0,0],[1,1],[],opts)
fmincon(@(x) norm(x)^2,[10,5],A,b,[],[],[],[],[],opts)
I thought the Optimization Toolbox solvers now preprocess the linear constraints in A,b, Aeq,beq to see if any can be re-expressed as pure bounds, but apparently not.
In any case, the separateBounds() function from,
will do so, e.g.,
A=[-eye(2);
eye(2);
1 1];
b=[0 0 1 1 1]';
Aeq=[0 1];
beq=[0.5];
[A,b,Aeq,beq,lb,ub]=separateBounds(A,b,Aeq,beq)
1 Comment
Nick
on 12 Jan 2022
Oh ok I see. Thank you so much!
Categories
Find more on Choose a Solver in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!