fmincon; produces different answers against theoretically the same question ...
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
Alan Weiss
il 21 Set 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 Commenti
Matt J
il 12 Gen 2022
Modificato: Matt J
il 12 Gen 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
il 12 Gen 2022
Modificato: Matt J
il 12 Gen 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)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!