1 #ifndef STAN_MATH_MIX_MAT_FUNCTOR_HESSIAN_HPP 2 #define STAN_MATH_MIX_MAT_FUNCTOR_HESSIAN_HPP 42 void hessian(
const F& f,
const Eigen::Matrix<double, Eigen::Dynamic, 1>& x,
43 double& fx, Eigen::Matrix<double, Eigen::Dynamic, 1>&
grad,
44 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>& H) {
45 H.resize(x.size(), x.size());
46 grad.resize(x.size());
54 for (
int i = 0; i < x.size(); ++i) {
56 Eigen::Matrix<fvar<var>, Eigen::Dynamic, 1> x_fvar(x.size());
57 for (
int j = 0; j < x.size(); ++j)
64 for (
int j = 0; j < x.size(); ++j)
65 H(i, j) = x_fvar(j).val_.adj();
68 }
catch (
const std::exception&
e) {
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.
vari * vi_
Pointer to the implementation of this variable.
double e()
Return the base of the natural logarithm.
static void recover_memory_nested()
Recover only the memory used for the top nested call.
static void start_nested()
Record the current position so that recover_memory_nested() can find it.
double val() const
Return 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.