quadprog 'trust-reg​ion-reflec​tive' algorithm error

8 vues (au cours des 30 derniers jours)
nikio
nikio le 30 Nov 2017
Modifié(e) : nikio le 1 Déc 2017
Hello, I get an error using the "trust region reflective" algorithm for a quadratic problem:
Error using quadprog (line 406)
Option Algorithm = 'trust-region-reflective' but this algorithm does not solve
problems with the constraints you have specified. Run a different algorithm by
setting the Algorithm option. For information on applicable algorithms, see
Choosing the Algorithm in the documentation.
Unfortunately the problem in not convex, so no other algorithms are available, a minimal example code is the following:
H=[1 0;0 -1 ];
f = zeros(2,1);
A=[1 1];
b=1.2;
lb = zeros(2,1);
ub = ones(2,1);
x0=(ub+lb)/2;
options=optimoptions('quadprog','Algorithm','trust-region-reflective');
x = quadprog(H,f,A,b,[],[],[],[],x0,options);
as far as I can understand, the only limit to the use of this algorithm is that only equality constraints or bound constraints can be used but not both.
The only way to make quadprog work is removing the linear bounds (A and b), not very useful. But the problem has no equality constraints (Aeq=[],beq=[]) so I don't understand the error. Thank you for any advice

Réponse acceptée

Matt J
Matt J le 30 Nov 2017
Modifié(e) : Matt J le 30 Nov 2017
Apparently, the structure of your problem is outside the scope of quadprog, but there is always fmincon,
[x,fval,exitflag,output] = fmincon(@(x) x.'*H*x/2+f'*x ,x0,A,b,[],[],lb,ub);
Naturally, I would recommend that you improve the implementation of the objective function, incorporating also the SpecifyObjectiveGradient option.
  1 commentaire
nikio
nikio le 1 Déc 2017
Modifié(e) : nikio le 1 Déc 2017
This solves the problem!
By the way I'm not sure on how to use the objective gradient: is it sufficient to set as true the SpecifyObjectiveGradient option or should I calculate the gradient and give it as an input somewhere?
[EDIT]:
I found an example in fmincon help, at the "include gradient" section:
it is necessary to calculate the gradient and to build a function with two outputs, one for the objective function and one for the gradient

Connectez-vous pour commenter.

Plus de réponses (1)

Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan le 30 Nov 2017
As you said, the only limit to the use of this algorithm is that only equality constraints or bound constraints can be used but not both.
So, you can specify either Aeq & beq, or LB & UB, but not both. In your implementation, you are specifying inequality constraints ( A and b ). These are not the same as bound constraints which is why you're getting the error. If your problem is not convex, you can try this (untested) code: https://github.com/xiawei918/quadprogIP
  1 commentaire
nikio
nikio le 1 Déc 2017
As I needed a quick 'sure' and portable solution, I preferred fmincon, anyway I'll test soon the alternative function you suggested because I suppose it should work better on quadratic functions, thank you.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Quadratic Programming and Cone Programming 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!

Translated by