1#ifndef STAN_MATH_REV_FUNCTOR_HESSIAN_TIMES_VECTOR_HPP
2#define STAN_MATH_REV_FUNCTOR_HESSIAN_TIMES_VECTOR_HPP
45 const Eigen::VectorXd& x,
46 const Eigen::VectorXd& v,
48 Eigen::VectorXd& hvp) {
51 double epsilon = std::sqrt(
EPSILON) * (1 + x.norm()) / v.norm();
53 Eigen::VectorXd v_eps = epsilon * v;
57 Eigen::VectorXd grad_forward(d);
58 gradient(f, x + v_eps, tmp, grad_forward);
60 Eigen::VectorXd grad_backward(d);
61 gradient(f, x - v_eps, tmp, grad_backward);
64 hvp = (grad_forward - grad_backward) / (2 * epsilon);
void finite_diff_hessian_times_vector_auto(const F &f, const Eigen::VectorXd &x, const Eigen::VectorXd &v, double &fx, Eigen::VectorXd &hvp)
Calculate the value and the product of the Hessian and the specified vector of the specified function...
static constexpr double EPSILON
Smallest positive value.
void gradient(const F &f, const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, T &fx, Eigen::Matrix< T, Eigen::Dynamic, 1 > &grad_fx)
Calculate the value and the gradient of the specified function at the specified argument.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...