Stan Math Library
5.0.0
Automatic Differentiation
|
void stan::math::finite_diff_gradient_auto | ( | const F & | f, |
VectorT && | x, | ||
ScalarT & | fx, | ||
GradVectorT & | grad_fx | ||
) |
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>&) const;
Error of derivative in dimension i
should be on the should be on order of epsilon(i)^6
, where epsilon(i) = sqrt(delta) * abs(x(i))
for input x
at dimension i
.
The reference for this algorithm is:
Robert de Levie. 2009. An improved numerical approximation for the first derivative. Journal of Chemical Sciences 121(5), page 3.
The reference for automatically setting the difference is this section of the Wikipedia,
Numerical differentiation: practical considerations using floating point arithmetic.
Evaluating this function involves 6 calls to the function being differentiated for each dimension in the input, plus one global evaluation. All evaluations will be for double-precision inputs.
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 |
Definition at line 51 of file finite_diff_gradient_auto.hpp.