gradient() computes a numerical approximation to the gradient of a scalar
objective function at a given parameter vector. It provides several
finite-difference schemes and can distribute the underlying function
evaluations across a registered foreach backend when parallel = TRUE.
Usage
gradient(fn, x, method, control, parallel, ...)
# Default S3 method
gradient(fn, x, method = NULL, control = list(), parallel = FALSE, ...)Arguments
- fn
Function whose gradient is to be approximated.
- x
Numeric vector giving the point at which the gradient is evaluated.
- method
Numerical differentiation scheme. If
NULL, the default method used bygradient.default()is"forward".- control
A list of control arguments governing step-size construction and, for Richardson extrapolation, the extrapolation sequence.
- parallel
Logical. Should the function evaluations needed for the numerical derivative be carried out in parallel via
foreach?- ...
Additional arguments passed to
fn.
Details
The currently implemented methods are:
"forward"(default): one-sided forward finite differences."backward": one-sided backward finite differences."central": central finite differences."richardson": central differences with Richardson extrapolation.
Step sizes are controlled through control. Common entries are:
step_method: how the initial step size is computed. Implemented values are"simple","optextras", and"start".eps: base perturbation size.zero.tol: threshold used to decide when a parameter value is treated as effectively zero for step-size construction.d: starting fraction ofxused bystep_method = "start".randv: Richardson iteration depth and reduction factor formethod = "richardson".
When parallel = TRUE, a suitable foreach backend must already be
registered by the user. This function does not itself create or manage a
parallel backend.
