[R] .Internal(optim)

Spencer Graves spencer.graves at pdf.com
Wed Jul 9 22:44:20 CEST 2003


I haven't used optim enough to know, but simular functions ostensibly 
with box constraints would still test values outside the box and quite 
if it got an NA or possibly Inf.  I've had good luck transforming the 
inputs to remove constraints.  For example, if you need x > 0, then 
parameterize the function in terms of log.x, then compute "x <- 
exp(log.x)" as a first step of the function.  Then 0 will never be 
tested by the function minimizer.  When I do this, the log(likelihood) 
surface is often more nearly parabolic in terms of log.x than in terms 
of x.  This means that any normal approximation theory is more likely to 
work better in terms of log.x than in terms of x.

hope this helps.  spencer graves

Duncan Murdoch wrote:
> On Wed, 9 Jul 2003 15:33:12 -0400, Edoardo Airoldi
> <eairoldi at stat.cmu.edu> wrote :
> 
> 
>>>hi all,
>>> I am using optim.  I am getting the following error message:
>>>
>>>Error in optim(par = start.vals[, h], fn = post.func.pois, gr = post.grad.
>>>pois,  :
>>>        L-BFGS-B needs finite values of fn
>>>
>>>If I look at optim typing '> optim' it seems that the error comes from 
>>>inside .Internal(optim), so I wonder how can I see the code for .Internal(
>>>optim)?
>>
> 
> Anything that's called by .Internal is C or Fortran code.  You need to
> download the R source package, decompress it somewhere, and start
> looking around the src directory.
> 
> Internal functions are all listed in a big array declared in the
> src/main/names.c file.  For example, this line is in that file:
> 
> {"optim",	do_optim,	0,	11,	7,	{PP_FUNCALL,
> PREC_FN,	0}},
> 
> This says that "do_optim" is the function that does all the work.  The
> other numbers describe things like how many arguments it takes, how to
> deparse it, etc.  You then need to search through all the source to
> find do_optim; it's in the file src/main/optim.c.  Reading C code that
> works with R objects (declared as SEXP) is not easy, but that's where
> you'll need to look.
> 
> In the end, I don't think all that work is going to be very fruitful.
> You'll just find out that your objective function needs to return
> finite values.  You should try to figure out why it doesn't.  Perhaps
> if you set the bounds on the region a little smaller you'll fix
> things?
> 
> Duncan Murdoch
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list