Constructs a function to calculate the Hessian of a function produced either using sourceCppAD or the composition operator %.% .
The returned function has the same argument signature as f but returns a matrix representing the
blocked Hessians of f evaluated at the functions arguments. The partial
derivatives are formed with respect to the argument specified when f was created with sourceCppAD.
In what follows it is assumed that f has a single matrix argument (the
one with which f is differentiated with respect to). When this is not
the case, the other arguments will be considered constant at the point the
Hessian is evaluated at. Consequently, the structure of the output of
the function produced by H is unchanged by the additional arguments.
The blocked Hessian \({\bf H}\) is organised as follows.
If \(f:{\bf R}^{n} \rightarrow {\bf R}^{m}\) where \({\bf Y}_{n_{Y}
\times m_{Y}} = f({\bf X}_{n_{X} \times m_{X}})\) and
\(n=n_{X}m_{X}\), \(m=n_{Y}m_{Y}\) then by numbering the elements of
the matrices row-wise so that,
$$
{\bf Y} =
\left[
\begin{array}{ccc}
y_{1} & \dots & y_{m_{Y}} \\
y_{m_{Y}+1} & \dots & y_{2m_{Y}} \\
\vdots & \ddots & \vdots \\
y_{(n_{Y}-1)m_{Y}+1} & \dots & y_{n_{Y}m_{Y}}
\end{array}
\right]
$$
and
$$
{\bf X} =
\left[
\begin{array}{ccc}
x_{1} & \dots & x_{m_{X}} \\
x_{m_{X}+1} & \dots & x_{2m_{X}} \\
\vdots & \ddots & \vdots \\
x_{(n_{X}-1)m_{X}+1} & \dots & x_{n_{X}m_{X}}
\end{array}
\right]
$$
then the \(n \times nm\) blocked Hessian matrix \({\bf H}\) is structured as
$$
{\bf H} =
\left[
\begin{array}{cccc}
{\bf H}_{1} & {\bf H}_{2} & \dots & {\bf H}_{m}
\end{array}
\right]
$$
with \({\bf H}_{k}\) the Hessian matrix for \(y_{k}\) i.e.,
$$
\begingroup
\renewcommand*{\arraystretch}{1.5}
{\bf H}_{k} =
\left[ \begin{array}{ccc}
\frac{\partial^2 y_{k}}{\partial x_1 \partial x_1} & \dots & \frac{\partial^2 y_{k}}{\partial x_1 \partial x_n} \\
\vdots & \ddots & \vdots \\
\frac{\partial^2 y_{k}}{\partial x_n \partial x_1} & \dots & \frac{\partial^2 y_{k}}{\partial x_n \partial x_n}
\end{array} \right]
\endgroup
$$