Use R's optim function but pass in a single function
that returns both the function and gradient
together in a list. Useful when the function and
gradient are expensive to calculate and can be
calculated faster together than separate.
Usage
optim_share(par, fngr, ...)
Arguments
par
Initial values for the parameters to be optimized over.
Will be passed to optim as par argument.
fngr
A function that returns a list of two elements:
the function value and the gradient value.
...
Arguments passed to optim, such as method,
lower, upper, control, and hessian.