Hessian Output
The fminunc and fmincon solvers return an
approximate Hessian as an optional output.
[x,fval,exitflag,output,grad,hessian] = fminunc(fun,x0)
% or
[x,fval,exitflag,output,lambda,grad,hessian] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)This topic describes the meaning of the returned Hessian, and the accuracy you can expect.
You can also specify the type of Hessian that the solvers use as input Hessian
arguments. For fminunc, see Including Gradients and Hessians.
For fmincon, see Hessian as an Input.
fminunc Hessian
The Hessian for an unconstrained problem is the matrix of second derivatives of the objective function f:
Quasi-Newton Algorithm —
fminuncreturns an estimated Hessian matrix at the solution.fminunccomputes the estimate by finite differences, so the estimate is generally accurate.Trust-Region Algorithm —
fminuncreturns a Hessian matrix at the next-to-last iterate.If you supply a Hessian in the objective function and set the
HessianFcnoption to'objective',fminuncreturns this Hessian.If you supply a
HessianMultiplyFcnfunction,fminuncreturns theHinfomatrix from theHessianMultiplyFcnfunction. For more information, seeHessianMultiplyFcnin thetrust-regionsection of thefminuncoptionstable.Otherwise,
fminuncreturns an approximation from a sparse finite difference algorithm on the gradients.
This Hessian is accurate for the next-to-last iterate. However, the next-to-last iterate might not be close to the final point.
The
trust-regionalgorithm returns the Hessian at the next-to-last iterate for efficiency.fminuncuses the Hessian internally to compute its next step. Whenfminuncreaches a stopping condition, it does not need to compute the next step and, therefore, does not compute the Hessian.
fmincon Hessian
The Hessian for a constrained problem is the Hessian of the Lagrangian. For an objective function f, nonlinear inequality constraint vector c, and nonlinear equality constraint vector ceq, the Lagrangian is
The λi are Lagrange multipliers; see First-Order Optimality Measure and Lagrange Multiplier Structures. The Hessian of the Lagrangian is
fmincon has several algorithms, with
several options for Hessians, as described in fmincon Trust Region Reflective Algorithm, fmincon Active Set Algorithm, and fmincon Interior Point Algorithm.
active-set,sqp, orsqp-legacyAlgorithm —fminconreturns the Hessian approximation it computes at the next-to-last iterate.fminconcomputes a quasi-Newton approximation of the Hessian matrix at the solution in the course of its iterations. In general, this approximation does not match the true Hessian in every component, but only in certain subspaces. Therefore, the Hessian returned byfminconcan be inaccurate. For more details about theactive-setcalculation, see SQP Implementation.trust-region-reflectiveAlgorithm —fminconreturns the Hessian it computes at the next-to-last iterate.If you supply a Hessian in the objective function and set the
HessianFcnoption to'objective',fminconreturns this Hessian.If you supply a
HessianMultiplyFcnfunction,fminconreturns theHinfomatrix from theHessianMultiplyFcnfunction. For more information, see Trust-Region-Reflective Algorithm infminconoptions.Otherwise,
fminconreturns an approximation from a sparse finite difference algorithm on the gradients.
This Hessian is accurate for the next-to-last iterate. However, the next-to-last iterate might not be close to the final point.
The
trust-region-reflectivealgorithm returns the Hessian at the next-to-last iterate for efficiency.fminconuses the Hessian internally to compute its next step. Whenfminconreaches a stopping condition, it does not need to compute the next step and, therefore, does not compute the Hessian.interior-pointAlgorithmIf the
HessianApproximationoption is'lbfgs'or'finite-difference', or if you supply aHessianMultiplyFcnfunction,fminconreturns[]for the Hessian.If the
HessianApproximationoption is'bfgs'(the default),fminconreturns a quasi-Newton approximation to the Hessian at the final point. This Hessian can be inaccurate, similar to theactive-setorsqpalgorithm Hessian.If the
HessianFcnoption is a function handle,fminconreturns this function as the Hessian at the final point.