Editing the "..." argument

View: New views
4 Messages — Rating Filter:   Alert me  

Editing the "..." argument

by Mathieu Ribatet :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

    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 "..." argument

by Duncan Murdoch-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 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 "..." argument

by J. R. M. Hosking :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.
>
> 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

Parent Message unknown Re: Editing the "..." argument

by Enrique Bengoechea :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The 'modifyList' function on package Utils allows to do that in a very compact way:

do.call("optim", modifyList(list(<your default values>), list(...)))

Regards,

Enrique

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.
>
> Mathieu

______________________________________________
R-devel@... mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
LightInTheBox - Buy quality products at wholesale price