j.j.goeman at lumc.nl
2007-Feb-21 09:37 UTC
[Rd] avoiding a needless function evaluation in optimize() (PR#9523)
Full_Name: Jelle Goeman Version: 2.4.0 OS: windows XP Submission from: (NULL) (145.88.209.33) Hi, I like to use optimize() to optimize functions whose evaluation is costly in terms of computation time. The Brent algorithm which is implemented in optimize was designed to optimize a function with as few function evaluations as possible. Therefore it bothers me that optimize() always evaluates the function twice at the optimal value. This can be seen for example by saying: square <- function(x) { print(x) x*x } opt <- optimize(square, c(-5,1), tol=0.1) Looking at the code of optimize(), I see that the extra function evaluation comes when optimize returns list(minimum = val, objective = f(val, ...)) f(val, ...) is calculated, but f(val, ...) has already been calculated at some point during the algorithm. Would it be possible to let optimize() store its previous function evaluations to avoid this unnecessary function evaluation? Kind regards, Jelle
Prof Brian Ripley
2007-Feb-22 23:12 UTC
[Rd] (PR#9523) avoiding a needless function evaluation in optimize()
This is very far from easy, as the C code used does not return the function value. If you would like to rewrite it and the interface and submit a patch it will be considered. It's hard to imagine an application where this would matter, and you have not given one to encourage us to give this more than the lowest priority on the wishlist. On Wed, 21 Feb 2007, j.j.goeman at lumc.nl wrote:> Full_Name: Jelle Goeman > Version: 2.4.0 > OS: windows XP > Submission from: (NULL) (145.88.209.33) > > > Hi, > > I like to use optimize() to optimize functions whose evaluation is costly in > terms of computation time. The Brent algorithm which is implemented in optimize > was designed to optimize a function with as few function evaluations as > possible. Therefore it bothers me that optimize() always evaluates the function > twice at the optimal value. This can be seen for example by saying: > > square <- function(x) { > print(x) > x*x > } > opt <- optimize(square, c(-5,1), tol=0.1) > > Looking at the code of optimize(), I see that the extra function evaluation > comes when optimize returns > > list(minimum = val, objective = f(val, ...)) > > f(val, ...) is calculated, but f(val, ...) has already been calculated at some > point during the algorithm. > > Would it be possible to let optimize() store its previous function evaluations > to avoid this unnecessary function evaluation? > > Kind regards, > > Jelle > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Seemingly Similar Threads
- is.vector() gives error (PR#7288)
- Problem with hasArg and the ... argument (PR#7027)
- Some bugs in Rcmd check ? (PR#2608)
- Puzzling message: "no man files in this package"
- different L2 regularization behavior between lrm, glmnet, and penalized? (original question)