[R] Very slow optim()
marchywka at hotmail.com
Wed Jul 13 22:39:11 CEST 2011
> Hamazaki, Hamachan (DFG <toshihide.hamazaki <at> alaska.gov> writes:
> > Dear list,
> > I am using optim() function to MLE ~55 parameters, but it is very slow to
> converge (~ 25 min), whereas I can do
> > the same in ~1 sec. using ADMB, and ~10 sec using MS EXCEL Solver.
> > Are there any tricks to speed up?
> > Are there better optimization functions?
> There's absolutely no way to tell without knowing more about your code. You
> might try method="CG":
I guess the first thing to do is look at task manager and see if it is memory
or CPU limited. In the absence of gross algorithmic differences, the "other stuff"
that you may be doing could be a big deal. I saw similar performance issues
in my own c++ code where the fast result was obtained just by sorting the input
data to stop VM thrashing. A sort on large data is noramlly considered slow
and wastful if later algorithm doesn't require that but memory coherence can be
a big deal.
> Method ‘"CG"’ is a conjugate gradients method based on that by
> Fletcher and Reeves (1964) (but with the option of Polak-Ribiere
> or Beale-Sorenson updates). Conjugate gradient methods will
> generally be more fragile than the BFGS method, but as they do not
> store a matrix they may be successful in much larger optimization
> If ADMB works better, why not use it? You can use the R2admb
> package (on R forge) to wrap your ADMB calls in R code, if you
> prefer that workflow.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help