nlmixr2GradFun: Create a gradient function based on gill numerical...

View source: R/nlmixrGrad.R

nlmixr2Eval_R Documentation

Create a gradient function based on gill numerical differences

Description

Create a gradient function based on gill numerical differences

Usage

nlmixr2Eval_(theta, md5)

nlmixr2Unscaled_(theta, md5)

nlmixr2Grad_(theta, md5)

nlmixr2ParHist_(md5)

nlmixr2GradFun(
  what,
  envir = parent.frame(),
  which,
  thetaNames,
  gillRtol = sqrt(.Machine$double.eps),
  gillK = 10L,
  gillStep = 2,
  gillFtol = 0,
  useColor = crayon::has_color(),
  printNcol = floor((getOption("width") - 23)/12),
  print = 1
)

Arguments

theta

for the internal functions theta is the parameter values

md5

the md5 identifier for the internal gradient function information.

what

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

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

thetaNames

Names for the theta parameters

gillRtol

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

gillK

Max steps to determine the optimal forward/central difference step size per parameter (Gill 1983). '0' = no 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.

useColor

Logical (or 'NULL') emit ANSI bold/color escapes in the iteration print. 'NULL' (default) defers to [crayon::has_color()].

printNcol

Integer (or 'NULL') parameter columns per row before wrapping. 'NULL' (default) uses 'floor((getOption("width") - 23) / 12)'.

print

Either a scalar print-frequency ('0' = suppress, '1' (default) = every evaluation, 'N' = every Nth), OR a pre-built [iterPrintControl()] object. Equivalent to 'iterPrintControl(every = print, ncol = printNcol, useColor = useColor)'.

Value

A list with 'eval', 'grad', 'hist' and 'unscaled' functions. This is an internal module used with dynmodel

Examples


func0 <- function(x){ sum(sin(x))  }

## This will printout every interation or when print=X
gf <- nlmixr2GradFun(func0)

## x
x <- (0:10)*2*pi/10;
gf$eval(x)
gf$grad(x)

## x2
x2 <- x+0.1
gf$eval(x2)
gf$grad(x2)

## Gives the parameter history as a data frame
gf$hist()


nlmixr2est documentation built on Aug. 5, 2026, 1:11 a.m.