Stan Math Library  2.20.0
reverse mode automatic differentiation
finite_diff_hessian_helper.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUNCTOR_FINITE_DIFF_HESSIAN_HELPER_HPP
2 #define STAN_MATH_PRIM_MAT_FUNCTOR_FINITE_DIFF_HESSIAN_HELPER_HPP
3 
5 
6 namespace stan {
7 namespace math {
8 
29 template <typename F>
30 double finite_diff_hessian_helper(const F& f, const Eigen::VectorXd& x, int i,
31  double epsilon = 1e-03) {
32  Eigen::VectorXd x_temp(x);
33 
34  x_temp(i) = x(i) + 2 * epsilon;
35  double grad = -f(x_temp);
36 
37  x_temp(i) = x(i) + -2 * epsilon;
38  grad += f(x_temp);
39 
40  x_temp(i) = x(i) + epsilon;
41  grad += 8 * f(x_temp);
42 
43  x_temp(i) = x(i) + -epsilon;
44  grad -= 8 * f(x_temp);
45 
46  return grad;
47 }
48 } // namespace math
49 } // namespace stan
50 #endif
static void grad(vari *vi)
Compute the gradient for all variables starting from the specified root variable implementation.
Definition: grad.hpp:30
double finite_diff_hessian_helper(const F &f, const Eigen::VectorXd &x, int i, double epsilon=1e-03)
Return the subcalculation required by finite_diff_hessian and finite_diff_hessian_auto.
double e()
Return the base of the natural logarithm.
Definition: constants.hpp:87

     [ Stan Home Page ] © 2011–2018, Stan Development Team.