Description Usage Arguments Value Examples

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} =
≤ft[
\begin{array}{ccc}
y_{1} & … & y_{m_{Y}} \\
y_{m_{Y}+1} & … & y_{2m_{Y}} \\
\vdots & \ddots & \vdots \\
y_{(n_{Y}-1)m_{Y}+1} & … & y_{n_{Y}m_{Y}}
\end{array}
\right]
*

and

*
{\bf X} =
≤ft[
\begin{array}{ccc}
x_{1} & … & x_{m_{X}} \\
x_{m_{X}+1} & … & x_{2m_{X}} \\
\vdots & \ddots & \vdots \\
x_{(n_{X}-1)m_{X}+1} & … & x_{n_{X}m_{X}}
\end{array}
\right]
*

then the *n \times nm* blocked Hessian matrix *{\bf H}* is structured as

*
{\bf H} =
≤ft[
\begin{array}{cccc}
{\bf H}_{1} & {\bf H}_{2} & … & {\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} =
≤ft[ \begin{array}{ccc}
\frac{\partial^2 y_{k}}{\partial x_1 \partial x_1} & … & \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} & … & \frac{\partial^2 y_{k}}{\partial x_n \partial x_n}
\end{array} \right]
\endgroup
*

1 | ```
H(f)
``` |

`f` |
A function created using either sourceCppAD or the composition operator %.%. |

A function which computes the Hessian of the function.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ```
library(RcppEigenAD)
# define f as the eigen vectors of its argument x
# calculated using the Eigen library
f<-sourceCppAD('
ADmat f(const ADmat& X)
{
Eigen::EigenSolver<ADmat> es(X);
return es.pseudoEigenvectors();
}
')
Hf<-H(f)
X<-matrix(c(1,2,3,4),2,2)
Hmat<-Hf(X)
Hmat # the Hessian matrices of second derivatives stacked column wise
Hmat[3,9] # the second derivative of f(X)[2,1] with respect to X[2,1] and X[1,2]
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.