num_grad {rhmc} | R Documentation |
Numerical Gradient
Description
Performs numerical differentiation of a function at a specific point. Uses some numerical tricks to always achieve a reliable, though not necessarily optimal, error.
Usage
num_grad(f, x)
Arguments
f |
The function for which the gradient is desired. |
x |
The point at which the gradient should be approximated. |
Value
The gradient of the function 'f' at 'x'.
Examples
func = function(x) exp(-0.5 * x ^ 2) / sqrt(2 * pi)
grad = function(x) -x * exp(-0.5 * x ^ 2) / sqrt(2 * pi)
num_grad(func, -2)
abs(num_grad(func, -2) - grad(-2))
[Package rhmc version 1.0.0 Index]