Skip to contents

Function to fit curve via stats::optim

Usage

.fitCurve2(
  par,
  x,
  y,
  fn,
  loss,
  lower = -Inf,
  upper = Inf,
  precision = 1e-04,
  density = c(2, 10, 5),
  step = 0.5/density,
  ...,
  loss_args = list(),
  span = 1,
  optim_only = FALSE,
  control = list(factr = 1e-08, ndeps = rep(1e-04, times = length(par)), trace = 0)
)

Arguments

par

numeric Vector of intial guesses for the parameters. For each index i of par, par[i] must be within the range (lower\[i\], upper\[i\]). If only a single upper or lower value is present, that range is used for all parameters in par.

x

numeric Values to evaluate fn for.

y

numeric Target output values to optimze fn against.

fn

function A function to optimize. Any fn arguments passed via ... will be treated as constant and removed from the optimization. It is assumed that the first argument is the x value to optimize over and any subsequent arguments are free parameters to be optimized. Transformed to be optim compatible via make_optim_function is the first arguement isn't already par.

loss

character(1) or function Either the name of one of the bundled loss functions (see details) or a custom loss function to compute for the output of fn over x.

lower

numeric(1) Lower bound for parameters. Parallel to par.

upper

numeric(1) Upper bound for paramteres. Parallel to par.

precision

numeric smallest step size used in pattern search, once step size drops below this value, the search terminates.

density

numeric how many points in the dimension of each parameter should be evaluated (density of the grid)

step

initial step size for pattern search.

...

pairlist Fall through arguments to fn.

loss_args

list Additional argument to the loss function. These get passed to losss via do.call analagously to using ....

span

numeric Can be safely kept at 1, multiplicative ratio for initial step size in pattern search. Must be larger than precision.

optim_only

logical(1) Should the fall back methods when optim fails be skipped? Default is FALSE.

control

list List of control parameters to pass to optim. See ?optim for details.

Value

numeric Vector of optimal parameters for fn fit against y

on the values of x.

Details

TODO

Examples