1#ifndef STAN_MATH_FWD_FUNCTOR_HESSIAN_HPP
2#define STAN_MATH_FWD_FUNCTOR_HESSIAN_HPP
40template <
typename T,
typename F>
41void 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) {
59 fx = fx_fvar.
val_.val_;
64 H(i, j) = fx_fvar.
d_.d_;
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()
Compute the gradient for all variables starting from the end of the AD tape.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Scalar val_
The value of this variable.
Scalar d_
The tangent (derivative) of this variable.
This template class represents scalars used in forward-mode automatic differentiation,...