Set hessian function only once for fmincon

3 visualizaciones (últimos 30 días)
Steradiant
Steradiant el 25 de Sept. de 2020
Comentada: Steradiant el 26 de Sept. de 2020
I'm calculating the analytic hessian for the interior-point algorithm of fmincon like described here: https://de.mathworks.com/help/optim/ug/fmincon-interior-point-algorithm-with-analytic-hessian.html
I have to solve a non-linear optimization problem repeatedly with different values. Hence, inside the calculation of the hessian, a model is evaluated. Here is a pseudocode example:
for i=1:maxIter
z = ones(Elements,1)*i;
hess = @(x,lambda) analyticHessian(x,lambda,z);
options = optimoptions('fmincon','Algorithm','interior-point','SpecifyConstraintGradient',true,'SpecifyObjectiveGradient',true,'HessianFcn',hess);
x = fmincon(costfun,x_0,[],[],[],[],[],[],@constraints,options);
end
Inside the analyticHessian-Function, the model is evaluated with the different values of z. To account that, I have to set the options again in every iteration. I've tried to only set them once but then the values of z, and therefore the model, doesn't get evaluated with the new values. Is there any possibility to set the options only once to save time?

Respuesta aceptada

Alan Weiss
Alan Weiss el 25 de Sept. de 2020
It seems to me that if you are changing the problem Hessian at each iteration then you will have to change the fmincon Hessian at each iteration. You can save time by simply updating the options instead of creating all-new options:
options = optimoptions('fmincon','Algorithm','interior-point','SpecifyConstraintGradient',true,'SpecifyObjectiveGradient',true);
for i=1:maxIter
z = ones(Elements,1)*i;
hess = @(x,lambda) analyticHessian(x,lambda,z);
options.HessianFcn = hess;
x = fmincon(costfun,x_0,[],[],[],[],[],[],@constraints,options);
end
Or you could use a nested function instead of an anonymous function for carrying the extra parameter. See Passing Extra Parameters.
Alan Weiss
MATLAB mathematical toolbox documentation
  1 comentario
Steradiant
Steradiant el 26 de Sept. de 2020
Thanks, that did the trick. Using the options-structure was the solution. Thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by