1 #ifndef STAN_MATH_PRIM_MAT_FUNCTOR_FINITE_DIFF_HESSIAN_AUTO_HPP 2 #define STAN_MATH_PRIM_MAT_FUNCTOR_FINITE_DIFF_HESSIAN_AUTO_HPP 43 Eigen::VectorXd& grad_fx,
44 Eigen::MatrixXd& hess_fx) {
47 Eigen::VectorXd x_temp(x);
52 for (
int i = 0; i < d; ++i) {
53 for (
int j = i; j < d; ++j) {
55 x_temp(i) += 2 * epsilon;
58 x_temp(i) = x(i) + -2 * epsilon;
60 x_temp(i) = x(i) + epsilon;
62 x_temp(i) = x(i) + -epsilon;
64 f_diff /= 12 * epsilon * 12 * epsilon;
68 x_temp(i) = x(i) + -2 * epsilon;
70 x_temp(i) = x(i) + epsilon;
71 f_diff += 16 * f(x_temp);
72 x_temp(i) = x(i) - epsilon;
73 f_diff += 16 * f(x_temp);
74 f_diff /= 12 * epsilon * epsilon;
77 hess_fx(j, i) = f_diff;
78 hess_fx(i, j) = hess_fx(j, i);
void finite_diff_gradient_auto(const F &f, const Eigen::VectorXd &x, double &fx, Eigen::VectorXd &grad_fx)
Calculate the value and the gradient of the specified function at the specified argument using finite...
void finite_diff_hessian_auto(const F &f, const Eigen::VectorXd &x, double &fx, Eigen::VectorXd &grad_fx, Eigen::MatrixXd &hess_fx)
Calculate the value and the Hessian of the specified function at the specified argument using second-...
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 finite_diff_stepsize(double u)
Return the stepsize for finite difference evaluations at the specified scalar.