nlmixrGill83: Get the optimal forward difference interval by Gill83 method

View source: R/nlmixrGrad.R

nlmixrGill83R Documentation

Get the optimal forward difference interval by Gill83 method

Description

Get the optimal forward difference interval by Gill83 method

Usage

nlmixrGill83(
  what,
  args,
  envir = parent.frame(),
  which,
  gillRtol = sqrt(.Machine$double.eps),
  gillK = 10L,
  gillStep = 2,
  gillFtol = 0
)

Arguments

what

either a function or a non-empty character string naming the function to be called.

args

a list of arguments to the function call. The names attribute of args gives the argument names.

envir

an environment within which to evaluate the call. This will be most useful if what is a character string and the arguments are symbols or quoted expressions.

which

Which parameters to calculate the forward difference and optimal forward difference interval

gillRtol

The relative tolerance used for Gill 1983 determination of optimal step size.

gillK

The total number of possible steps to determine the optimal forward/central difference step size per parameter (by the Gill 1983 method). If 0, no optimal step size is determined. Otherwise this is the optimal step size determined.

gillStep

When looking for the optimal forward difference step size, this is This is the step size to increase the initial estimate by. So each iteration the new step size = (prior step size)*gillStep

gillFtol

The gillFtol is the gradient error tolerance that is acceptable before issuing a warning/error about the gradient estimates.

Value

A data frame with the following columns:

  • infoGradient evaluation/forward difference information

  • hfForward difference final estimate

  • dfDerivative estimate

  • df22nd Derivative Estimate

  • errError of the final estimate derivative

  • aEpsAbsolute difference for forward numerical differences

  • rEpsRelative Difference for backward numerical differences

  • aEpsCAbsolute difference for central numerical differences

  • rEpsCRelative difference for central numerical differences

The info returns one of the following:

  • Not AssessedGradient wasn't assessed

  • GoodSuccess in Estimating optimal forward difference interval

  • High Grad ErrorLarge error; Derivative estimate error fTol or more of the derivative

  • Constant GradFunction constant or nearly constant for this parameter

  • Odd/Linear GradFunction odd or nearly linear, df = K, df2 ~ 0

  • Grad changes quicklydf2 increases rapidly as h decreases

Author(s)

Matthew Fidler

Examples


## These are taken from the numDeriv::grad examples to show how
## simple gradients are assessed with nlmixrGill83

nlmixrGill83(sin, pi)

nlmixrGill83(sin, (0:10)*2*pi/10)

func0 <- function(x){ sum(sin(x))  }
nlmixrGill83(func0 , (0:10)*2*pi/10)

func1 <- function(x){ sin(10*x) - exp(-x) }
curve(func1,from=0,to=5)

x <- 2.04
numd1 <- nlmixrGill83(func1, x)
exact <- 10*cos(10*x) + exp(-x)
c(numd1$df, exact, (numd1$df - exact)/exact)

x <- c(1:10)
numd1 <- nlmixrGill83(func1, x)
exact <- 10*cos(10*x) + exp(-x)
cbind(numd1=numd1$df, exact, err=(numd1$df - exact)/exact)

sc2.f <- function(x){
  n <- length(x)
   sum((1:n) * (exp(x) - x)) / n
}

sc2.g <- function(x){
  n <- length(x)
  (1:n) * (exp(x) - 1) / n
}

x0 <- rnorm(100)
exact <- sc2.g(x0)

g <- nlmixrGill83(sc2.f, x0)

max(abs(exact - g$df)/(1 + abs(exact)))


nlmixr documentation built on March 27, 2022, 5:05 p.m.

Related to nlmixrGill83 in nlmixr...