1 #ifndef STAN_MATH_PRIM_MAT_FUNCTOR_FINITE_DIFF_HESSIAN_HPP 2 #define STAN_MATH_PRIM_MAT_FUNCTOR_FINITE_DIFF_HESSIAN_HPP 37 Eigen::VectorXd& grad_fx, Eigen::MatrixXd& hess_fx,
38 double epsilon = 1
e-03) {
40 Eigen::VectorXd x_temp(x);
43 for (
int i = 0; i < d; ++i) {
44 for (
int j = i; j < d; ++j) {
46 x_temp(i) += 2 * epsilon;
49 x_temp(i) = x(i) + -2 * epsilon;
51 x_temp(i) = x(i) + epsilon;
53 x_temp(i) = x(i) + -epsilon;
55 f_diff /= 12 * epsilon * 12 * epsilon;
59 x_temp(i) = x(i) + -2 * epsilon;
61 x_temp(i) = x(i) + epsilon;
62 f_diff += 16 * f(x_temp);
63 x_temp(i) = x(i) - epsilon;
64 f_diff += 16 * f(x_temp);
65 f_diff /= 12 * epsilon * epsilon;
68 hess_fx(j, i) = f_diff;
69 hess_fx(i, j) = hess_fx(j, i);
void finite_diff_hessian(const F &f, const Eigen::VectorXd &x, double &fx, Eigen::VectorXd &grad_fx, Eigen::MatrixXd &hess_fx, double epsilon=1e-03)
Calculate the value and the Hessian of the specified function at the specified argument using second-...
void finite_diff_gradient(const F &f, const Eigen::VectorXd &x, double &fx, Eigen::VectorXd &grad_fx, double epsilon=1e-03)
Calculate the value and the gradient of the specified function at the specified argument using finite...
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.