R/grback.R

Defines functions grback

Documented in grback

grback <- function(par, userfn, fbase=NULL, eps=1.e-8, ...) {
   # Backward difference gradient approximation
   if (is.null(fbase)) fbase <- userfn(par, ...)  # ensure we function value at par
   df <- rep(NA, length(par))
   teps <- eps * (abs(par) + eps)
   for (i in 1:length(par)) {
      dx <- par
      dx[i] <- dx[i] - teps[i]
      df[i] <- (fbase - userfn(dx, ...))/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.