Can I disable intermediate calculations for fmincon
5 ビュー (過去 30 日間)
In the optimization fmincon, there is always a lot of the 'intermediate calculations' (can be referred to https://www.mathworks.com/help/optim/ug/iterations-and-function-counts.html#mw_dc044841-a6b6-43c0-8b29-0af2fbbcb66c) that increase the function counts during optimization. In the link it says that the "intermediate calculations can involve evaluating the objective function and any constraints at points near the current iterate x_i. For example, the solver might estimate a gradient by finite differences."
What is the purpose of these intermediate calculations? Since I have provided the gradient calculation for my objective function, why would the optimizer need to calculate the finite difference gradient? My example objective function does not have any constaints.
My example code and the output for optimization are shown below. From the output, the 'Iter' term and 'F-count' term show that there are many intermediate calculations involved.
If the calculations for the objective and the gradient are expensive, the intermediate calculation can take a lot of time.
options = optimoptions('fmincon','SpecifyObjectiveGradient',true,'Display',...
fun = @rosenboth;
x0 = [-1,2];
A = ;
b = ;
Aeq = ;
beq = ;
lb = ;
ub = ;
nonlcon = ;
[x,f] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options);
function [f, g] = rosenboth(x)
f = 100*(x(2) - x(1)^2)^2 + (1-x(1))^2;
if nargout > 1 % gradient required
g = [-400*(x(2)-x(1)^2)*x(1)-2*(1-x(1));
Matt J 2022 年 6 月 24 日
編集済み: Matt J 2022 年 6 月 24 日
Since you are specifying the objective gradient, finite difference calculations will not be executed for that particular piece of the iteration loop. However, if second derivatives are needed and you haven't provided a Hessian calculation, finite differences will still be need for that. Also, multiple function evaluations may still be necessary, depending on the algorithm, for things like line searches.