R/numerical_Hessian_partial.R

Defines functions numerical_Hessian_partial

Documented in numerical_Hessian_partial

## File Name: numerical_Hessian_partial.R
## File Version: 0.15

numerical_Hessian_partial <- function(par, FUN, h=1E-5, coordinate=1, ... )
{
    ii <- coordinate
    f0 <- FUN( x=par, ... )

    #** select h parameters according to size of parameters
    abs_par <- abs(par)
    hvec <- h * ifelse( abs_par > 1, abs_par, 1 )

    #--- for computing f(x+h)
    par1 <- par
    par1[ii] <- par[ii] + hvec[ii]
    f1 <- FUN( x=par1, ...)
    #--- computation x-h
    par1[ii] <- par[ii] - hvec[ii]
    f2 <- FUN( x=par1, ...)
    #--- gradient and Hessian
    grad <- (f1 - f2 ) / (2*hvec[ii])
    hessian <- (f1 + f2 - 2*f0) / hvec[ii]^2
    #--- output
    res <- list( f0=f0, f1=f1, f2=f2, grad=grad, hessian=hessian)
    return(res)
}

Try the CDM package in your browser

Any scripts or data that you put into this service are public.

CDM documentation built on Aug. 25, 2022, 5:08 p.m.