Stan Math Library
4.9.0
Automatic Differentiation
|
void stan::math::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 difference.
The functor must implement
double operator()(const Eigen::Matrix<double, -1, 1>&) const;
If epsilon is chosen to be near the square root of the machine precision and the input vector elements are all roughly unit scale, and if the function has reasonable limits on variation, error should be on the order of epsilon^6.
The reference for the algorithm is:
Robert de Levie. 2009. An improved numerical approximation for the first derivative. Journal of Chemical Sciences 121(5), page 3.
Evaluating this function involves 6 calls to f for each dimension of the input.
F | Type of function |
[in] | f | Function |
[in] | x | Argument to function |
[out] | fx | Function applied to argument |
[out] | grad_fx | Gradient of function at argument |
[in] | epsilon | perturbation size |
Definition at line 43 of file finite_diff_gradient.hpp.