R/grfwd.R

Defines functions grfwd

Documented in grfwd

grfwd <- function(par, userfn, fbase=NULL, eps=1.0e-8, ...) {
   # Forward different gradient approximation
   if (is.null(fbase)) fbase <- userfn(par, ...)  # ensure we have 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] <- (userfn(dx, ...) - fbase)/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.