R/grcentral.R

Defines functions grcentral

Documented in grcentral

grcentral <- function(par, userfn, fbase=NULL, eps=1.e-8, ...) {
   # Central difference gradient approximation
   if (is.null(fbase)) fbase <- userfn(par, ...)  # ensure we function value at par
   df <- rep(NA, length(par))
   teps <- 0.5 * eps * (abs(par) + eps)
   for (i in 1:length(par)) {
      dp <- par
      dp[i]<-dp[i]+teps[i]
      dm <- par
      dm[i]<-dm[i]-teps[i]
      df[i] <- 0.5*(userfn(dp, ...) - userfn(dm,...))/teps[i]
   }
   df
}
 

Try the optimz package in your browser

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

optimz documentation built on May 31, 2017, 2:27 a.m.