[Rd] feature request: optim() iteration of functions that return multiple values
Sami Tuomivaara
@@m|tuom|v@@r@ @end|ng |rom hotm@||@com
Thu Aug 3 22:21:33 CEST 2023
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 = R2, pval = pval, etc.))
}
During the iteration, optim could utilize just the first value from the myfun return list; all the other values calculated and returned by myfun could be ignored by optim.
After convergence, the other return values of myfun could be finally extracted and appended into the optim return value (which is a list) as additional entry e.g.: $aux <- list(R2, pval, etc.), (without 'minimize.me' as it is already returned as $value).
The usual ways for accessing optim return values, e.g., $par, $value, etc. are not affected. Computational cost may not be prohibitive either. Is this feasible to consider?
[[alternative HTML version deleted]]
More information about the R-devel
mailing list