collect_fn_params: Collects all function arguments other than the first into a...

View source: R/utils-optimization.R

collect_fn_paramsR Documentation

Collects all function arguments other than the first into a single list parameter.

Description

Useful for converting a regular function into a function amenable to optimization via stats::optim, which requires all free parameters be passed as a single vector par.

Usage

collect_fn_params(fn)

Arguments

fn

function A non-primitive function to refactor such that the first argument becomes the second argument and all other parameters must be passed as a vector to the first argument of the new function via the par parameter.

Details

Takes a function of the form f(x, ...), where ... is any number of additional function parameters (bot not literal ...!) and parses it to a function of the form f(par, x) where par is a vector of values for ... in the same order as the arguments appear in fn.

Value

function A new non-primitive function where the first argument is par, which takes a vector of parameters being optimized, and the second argument is the old first argument to fn (usually x since this is the independent variable to optimize the function over).


bhklab/CoreGx documentation built on March 14, 2024, 3:04 a.m.