|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Editing the "..." argument Dear all,
I'd like tweaking the ... arguments that one user can pass in my function for fitting a model. More precisely, my objective function is (really) problematic to optimize using the "optim" function. Consequently, I'd like to add in the "control" argument of the latter function a "ndeps = rep(something, #par)" and/or "parscale = something" if the user has not specified it already. Do you know a way to deal with this point? In advance, thanks. Mathieu -- Institute of Mathematics Ecole Polytechnique Fédérale de Lausanne STAT-IMA-FSB-EPFL, Station 8 CH-1015 Lausanne Switzerland http://stat.epfl.ch/ Tel: + 41 (0)21 693 7907 ______________________________________________ R-devel@... mailing list https://stat.ethz.ch/mailman/listinfo/r-devel |
|
|
Re: Editing the "..." argumentOn 05/07/2008 1:55 PM, Mathieu Ribatet wrote:
> Dear all, > > I'd like tweaking the ... arguments that one user can pass in my > function for fitting a model. More precisely, my objective function is > (really) problematic to optimize using the "optim" function. > Consequently, I'd like to add in the "control" argument of the latter > function a "ndeps = rep(something, #par)" and/or "parscale = something" > if the user has not specified it already. > > Do you know a way to deal with this point? > In advance, thanks. It's generally not necessary to edit the ... args, but one way to do it is like this: dots <- list(...) # do some editing # instead of optim(a, b, ...), now you do do.call(optim, c(list(a, b), dots)) In the particular example you gave, I wouldn't do this; I'd give control as an arg to your function, and just edit that. For example, myoptim <- function(control = list(), ...) { if (is.null(control$ndeps)) control$ndeps <- rep(something, par) if (is.null(control$parscale)) control$parscale <- something optim(control=control, ...) } Duncan Murdoch ______________________________________________ R-devel@... mailing list https://stat.ethz.ch/mailman/listinfo/r-devel |
|
|
Re: Editing the "..." argumentMathieu Ribatet wrote:
> Dear all, > > I'd like tweaking the ... arguments that one user can pass in my > function for fitting a model. More precisely, my objective function is > (really) problematic to optimize using the "optim" function. > Consequently, I'd like to add in the "control" argument of the latter > function a "ndeps = rep(something, #par)" and/or "parscale = something" > if the user has not specified it already. > > Do you know a way to deal with this point? > In advance, thanks. > > Mathieu Package lmom, recently added to CRAN, contains a function 'pelp' that does exactly what you describe. Relevant parts of its code: # Get the user-supplied arguments for the optimization functions dotargs <- list(...) # If user didn't supply a "control" argument, create one if (is.null(dotargs$control)) dotargs<-c(dotargs,list(control=list())) # If user didn't provide "ndeps" or "abstol" elements of the "control" # argument, set them to our own defaults if (is.null(dotargs$control$ndeps)) dotargs$control <- c(dotargs$control,list(ndeps=rep(acc,nshape))) if (method!="L-BFGS-B" && is.null(dotargs$control$abstol)) dotargs$control <- c(dotargs$control,abstol=acc^2) # Call the optimization function, optim() opt <- do.call(optim,c(list(par=start[shape.pos]),fn=critfn, method=method,dotargs)) J. R. M. Hosking ______________________________________________ R-devel@... mailing list https://stat.ethz.ch/mailman/listinfo/r-devel |
|
|
|
| Free Forum Powered by Nabble | Forum Help |