Description Usage Arguments Details Value Note Author(s) Examples
These two functions create Gradient and Hessian matrices by Richardson's central finite difference method of the partial derivatives for any expression.
1 2 | numGrad(expr, envir = .GlobalEnv)
numHess(expr, envir = .GlobalEnv)
|
expr |
an expression, such as |
envir |
the |
Calculates first- and second-order numerical approximation using Richardson's central difference formula:
f'_i(x) \approx \frac{f(x_1, …, x_i + d, …, x_n) - f(x_1, …, x_i - d, …, x_n)}{2d}
f''_i(x) \approx \frac{f(x_1, …, x_i + d, …, x_n) - 2f(x_1, …, x_n) + f(x_1, …, x_i - d, …, x_n)}{d^2}
The numeric Gradient/Hessian matrices.
The two functions are modified versions of the genD
function in the 'numDeriv' package, but a bit more easy to handle because they use expressions and the function's x
value must not be defined as splitted scalar values x[1], x[2], ... x[n]
in the body of the function.
Andrej-Nikolai Spiess
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ## Check for equality of symbolic
## and numerical derivatives.
EXPR <- expression(2^x + sin(2 * y) - cos(z))
x <- 5
y <- 10
z <- 20
symGRAD <- evalDerivs(makeGrad(EXPR))
numGRAD <- numGrad(EXPR)
all.equal(symGRAD, numGRAD)
symHESS <- evalDerivs(makeHess(EXPR))
numHESS <- numHess(EXPR)
all.equal(symHESS, numHESS)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.