fmincon check Hessian (in DerivativeCheck)

24 次查看(过去 30 天)
When I set opts.DerivativeCheck='on' in fmincon, it checks only the gradient. How do I tell it to check the Hessian as well?
EDIT: My options
opts = optimset();
opts.MaxIter = 1e4;
opts.MaxFunEvals = 1e6;
opts.TolFun = 1e-4;
opts.Algorithm = 'interior-point'; % 'trust-region-reflective'
opts.GradObj = 'on';
opts.GradConstr = 'on';
opts.DerivativeCheck = 'on';
opts.Diagnostics = 'on';
opts.Display = 'iter';
%opts.Display = 'none';
opts.FinDiffType = 'central';
if 1
opts.HessMult = fH;
opts.Hessian = 'user-supplied';
%opts.Hessian = 'fin-diff-grads';
opts.SubproblemAlgorithm = 'cg';
else
opts.Hessian = 'lbfgs';
end

采纳的回答

Matt J
Matt J 2014-7-6
编辑:Matt J 2014-7-8
I don't think you can, but an indirect way would be to run like below with MaxIter=1 and have fmincon return the Hessian with the 'Hessian' option turned both on and off. Then you can check the Hessian error manually.
I agree it is counter-intuitive, but I think it might be deliberate that the DerivativeCheck does not test the Hessian. Often, minimization algorithms will work with fairly crude approximations to the Hessian, so maybe it is expected that your user-supplied Hessian will not always be exact. Or, maybe it is with large dimensional problems in mind, where finite difference derived Hessians are too expensive to compute, even for testing purposes, but you still might want to use DerivativeCheck to verify the gradient.
Q=[2 1;1,2];
Q=Q+Q.';
opts=optimoptions(@fmincon,'DerivativeCheck','on',...
'GradObj','on','Hessian','off','MaxIter',1);
[x,fval,exitflag,output,lambda,grad,H_off]=...
fmincon(@(x)objfun(x,Q),[1,2],[],[],[],[],[-1,-1],[1,1],[],opts)
opts=optimoptions(@fmincon,'DerivativeCheck','on',...
'GradObj','on','Hessian','on','MaxIter',1);
[x,fval,exitflag,output,lambda,grad,H_on]=...
fmincon(@(x)objfun(x,Q),[1,2],[],[],[],[],[-1,-1],[1,1],[],opts)
HessianError=H_on-H_off
keyboard
function [f,g,H]=objfun(x,Q)
x=x(:);
f=x.'*Q*x/2;
g=Q*x;
H=eye(2);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by