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 —
fminunc
returns an estimated Hessian matrix at the solution.fminunc
computes the estimate by finite differences, so the estimate is generally accurate.Trust-Region Algorithm —
fminunc
returns a Hessian matrix at the next-to-last iterate.If you supply a Hessian in the objective function and set the
HessianFcn
option to'objective'
,fminunc
returns this Hessian.If you supply a
HessianMultiplyFcn
function,fminunc
returns theHinfo
matrix from theHessianMultiplyFcn
function. For more information, seeHessianMultiplyFcn
in thetrust-region
section of thefminunc
options
table.Otherwise,
fminunc
returns 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
algorithm returns the Hessian at the next-to-last iterate for efficiency.fminunc
uses the Hessian internally to compute its next step. Whenfminunc
reaches 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-legacy
Algorithm —fmincon
returns the Hessian approximation it computes at the next-to-last iterate.fmincon
computes 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 byfmincon
can be inaccurate. For more details about theactive-set
calculation, see SQP Implementation.trust-region-reflective
Algorithm —fmincon
returns the Hessian it computes at the next-to-last iterate.If you supply a Hessian in the objective function and set the
HessianFcn
option to'objective'
,fmincon
returns this Hessian.If you supply a
HessianMultiplyFcn
function,fmincon
returns theHinfo
matrix from theHessianMultiplyFcn
function. For more information, see Trust-Region-Reflective Algorithm infmincon
options
.Otherwise,
fmincon
returns 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-reflective
algorithm returns the Hessian at the next-to-last iterate for efficiency.fmincon
uses the Hessian internally to compute its next step. Whenfmincon
reaches a stopping condition, it does not need to compute the next step and, therefore, does not compute the Hessian.interior-point
AlgorithmIf the
HessianApproximation
option is'lbfgs'
or'finite-difference'
, or if you supply aHessianMultiplyFcn
function,fmincon
returns[]
for the Hessian.If the
HessianApproximation
option is'bfgs'
(the default),fmincon
returns a quasi-Newton approximation to the Hessian at the final point. This Hessian can be inaccurate, similar to theactive-set
orsqp
algorithm Hessian.If the
HessianFcn
option is a function handle,fmincon
returns this function as the Hessian at the final point.