1#ifndef STAN_MATH_PRIM_FUNCTOR_FINITE_DIFF_GRADIENT_HPP
2#define STAN_MATH_PRIM_FUNCTOR_FINITE_DIFF_GRADIENT_HPP
44 Eigen::VectorXd& grad_fx,
double epsilon = 1
e-03) {
45 Eigen::VectorXd x_temp(x);
51 for (
int i = 0; i < d; ++i) {
54 x_temp(i) = x(i) + 3.0 * epsilon;
57 x_temp(i) = x(i) + 2.0 * epsilon;
58 delta_f -= 9.0 * f(x_temp);
60 x_temp(i) = x(i) + epsilon;
61 delta_f += 45.0 * f(x_temp);
63 x_temp(i) = x(i) + -3.0 * epsilon;
66 x_temp(i) = x(i) + -2.0 * epsilon;
67 delta_f += 9.0 * f(x_temp);
69 x_temp(i) = x(i) + -epsilon;
70 delta_f -= 45.0 * f(x_temp);
72 delta_f /= 60 * epsilon;
static constexpr double e()
Return the base of the natural logarithm.
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...
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...