1 #ifndef STAN_MATH_FWD_MAT_FUNCTOR_HESSIAN_HPP 2 #define STAN_MATH_FWD_MAT_FUNCTOR_HESSIAN_HPP 40 template <
typename T,
typename F>
41 void hessian(
const F& f,
const Eigen::Matrix<T, Eigen::Dynamic, 1>& x, T& fx,
42 Eigen::Matrix<T, Eigen::Dynamic, 1>&
grad,
43 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& H) {
44 H.resize(x.size(), x.size());
45 grad.resize(x.size());
51 Eigen::Matrix<fvar<fvar<T> >, Eigen::Dynamic, 1> x_fvar(x.size());
52 for (
int i = 0; i < x.size(); ++i) {
53 for (
int j = i; j < x.size(); ++j) {
54 for (
int k = 0; k < x.size(); ++k)
58 fx = fx_fvar.
val_.val_;
61 H(i, j) = fx_fvar.
d_.d_;
T d_
The tangent (derivative) of this variable.
void hessian(const F &f, const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, T &fx, Eigen::Matrix< T, Eigen::Dynamic, 1 > &grad, Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &H)
Calculate the value, the gradient, and the Hessian, of the specified function at the specified argume...
static void grad(vari *vi)
Compute the gradient for all variables starting from the specified root variable implementation.
T val_
The value of this variable.
This template class represents scalars used in forward-mode automatic differentiation, which consist of values and directional derivatives of the specified template type.