Automatic Differentiation
 
Loading...
Searching...
No Matches

◆ finite_diff_gradient_auto()

template<typename F , typename VectorT , typename GradVectorT , typename ScalarT = return_type_t<VectorT>>
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.

Template Parameters
FType of function
Parameters
[in]ffunction
[in]xargument to function
[out]fxfunction applied to argument
[out]grad_fxgradient of function at argument

Definition at line 51 of file finite_diff_gradient_auto.hpp.