fmincon; produces different answers against theoretically the same question ...
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (2)
Alan Weiss
le 21 Sep 2015
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 commentaires
Matt J
le 12 Jan 2022
Modifié(e) : Matt J
le 12 Jan 2022
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)
Matt J
le 12 Jan 2022
Modifié(e) : Matt J
le 12 Jan 2022
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)
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!