fdHess.Rd
Evaluate an approximate Hessian and gradient of a scalar function using finite differences.
fdHess(pars, fun, ...,
.relStep = .Machine$double.eps^(1/3), minAbsPar = 0)
the numeric values of the parameters at which to evaluate the
function fun
and its derivatives.
a function depending on the parameters pars
that
returns a numeric scalar.
Optional additional arguments to fun
The relative step size to use in the finite
differences. It defaults to the cube root of .Machine$double.eps
The minimum magnitude of a parameter value that is considered non-zero. It defaults to zero meaning that any non-zero value will be considered different from zero.
This function uses a second-order response surface design known as a “Koschal design” to determine the parameter values at which the function is evaluated.
A list with components
the value of function fun
evaluated at the
parameter values pars
an approximate gradient (of length length(pars)
).
a matrix whose upper triangle contains an approximate Hessian.
(fdH <- fdHess(c(12.3, 2.34), function(x) x[1]*(1-exp(-0.4*x[2]))))
#> $mean
#> [1] 7.47602
#>
#> $gradient
#> [1] 0.6078065 1.9295919
#>
#> $Hessian
#> [,1] [,2]
#> [1,] 0.0000000 0.1568771
#> [2,] 0.1568771 -0.7718194
#>
stopifnot(length(fdH$ mean) == 1,
length(fdH$ gradient) == 2,
identical(dim(fdH$ Hessian), c(2L, 2L)))