search for: returnfirst

Displaying 2 results from an estimated 2 matches for "returnfirst".

2023 Aug 05
1
feature request: optim() iteration of functions that return multiple values
For a solution that does not require any change to the original function being optimized, the following one-liner could be used, which converts existing functions to functions that return only the first element: returnFirst <- function(fun) function(...) do.call(fun,list(...))[[1]] Example: fr <- function(x) { ## Rosenbrock Banana function x1 <- x[1] x2 <- x[2] ans <- 100 * (x2 - x1 * x1)^2 + (1 - x1)^2 list(ans=ans, extra1 = 1:10, extra2 = letters) } fr2 <- returnFirst(fr) tmp <-...
2023 Aug 03
3
feature request: optim() iteration of functions that return multiple values
Dear all, I have used optim a lot in contexts where it would useful to be able to iterate function myfun that, in addition to the primary objective to be minimized ('minimize.me'), could return other values such as alternative metrics of the minimization, informative intermediate values from the calculations, etc. myfun <- function() { ... return(list(minimize.me = minimize.me, R2 =