1#ifndef STAN_MATH_REV_FUNCTOR_HESSIAN_TIMES_VECTOR_HPP
2#define STAN_MATH_REV_FUNCTOR_HESSIAN_TIMES_VECTOR_HPP
45 const Eigen::VectorXd& v,
double& fx,
46 Eigen::VectorXd& hvp) {
49 double epsilon = std::sqrt(
EPSILON) * (1 + x.norm()) / v.norm();
51 Eigen::VectorXd v_eps = epsilon * v;
55 Eigen::VectorXd grad_forward(d);
56 gradient(f, x + v_eps, tmp, grad_forward);
58 Eigen::VectorXd grad_backward(d);
59 gradient(f, x - v_eps, tmp, grad_backward);
62 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 ...