[R] r's optim vs. matlab's fminsearch
Spencer Graves
spencer.graves at pdf.com
Mon Jun 12 20:29:01 CEST 2006
Have you also tried 'nlminb'? A year or so ago, Doug Bates switched
from optim to nlminb for mixed-effects estimation. I'm not certain I
know why, but I think 'nlminb' may automatically adjust the 'scale'
parameter by default, while "optim" does not automatically adjust the
comparable 'control$parscale'. If Matlab does reasonable auto-scaling,
that might explain the difference. Others (e.g., Professors Ripley and
Bates) might be able to add more.
There might be more information on this in 'RSiteSearch', but I think
it's temporarily off line right now. And, of course, you can always
read the R code. Both 'nlminb' and 'optim' call compiled code, but the
source should be available.
Hope this helps,
Spencer Graves
Prof Brian Ripley wrote:
> Unless you know the function to be non-smooth, I suggest you use
> method="BFGS" in R.
>
> BTW, all such algorithms are only designed to find local minima, and so
> the choice of starting point may be crucial.
>
> On Mon, 12 Jun 2006, Anthony Bishara wrote:
>
>> Hi,
>> I'm having a problem converting a Matlab program into R. The R code works
>> almost all the time, but about 4% of the time R's optim function gets stuck
>> on a local minimum whereas matlab's fminsearch function does not (or at
>> least fminsearch finds a better minimum than optim). My understanding is
>> that both functions default to Nelder-Mead optimization, but what's
>> different about the two functions? Below, I've pasted the relevant default
>> options I could find. Are there other options I should to consider? Does
>> Matlab have default settings for reflection, contraction, and expansion, and
>> if so what are they? Are there other reasons optim and fminsearch might
>> work differently?
>> Thanks.
>>
>> ***Matlab's fminsearch defaults***
>> MaxFunEvals: '200*numberofvariables'
>> MaxIter: '200*numberofvariables'
>> TolFun: 1.0000e-004 #Termination tolerance on the function
>> value.
>> TolX: 1.0000e-004 #Termination tolerance on x.
>>
>> ***R's optim defaults (for Nelder-Mead)***
>> maxit=500
>> reltol=1e-8
>> alpha=1.0 #Reflection
>> beta=.5 #Contraction
>> gamma=2.0 #Expansion
>>
>>
>> Anthony J. Bishara
>> Post-Doctoral Fellow
>> Department of Psychological & Brain Sciences
>> Indiana University
>> 1101 E. Tenth St.
>> Bloomington, IN 47405
>> (812)856-4678
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>>
>
More information about the R-help
mailing list