Re: [R] Very slow optim(): solved

2021-03-12 Thread Jeff Newmiller
Calculate fewer of them?

If you don't setup your code to save intermediate results, then you cannot see 
intermediate results.

On March 11, 2021 8:32:17 PM PST, "毕芳妮 via R-help"  wrote:
>Dear list, 
>I am using optim() to estimate over 60 thousans of parameters, and use
>the server to run the program.But it took me 5 hours and there was just
>no result coming out.How could I do to show some results that have been
>calculated by optim()?
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Very slow optim(): solved

2021-03-12 Thread 毕芳妮 via R-help
Dear list, 
 I am using optim() to estimate over 60 thousans of parameters, and use the 
server to run the program.But it took me 5 hours and there was just no result 
coming out.How could I do to show some results that have been calculated by 
optim()?
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Very slow optim(): solved

2011-07-14 Thread Hamazaki, Hamachan (DFG)
After Googling and trial and errors, the major cause of optimization was not 
functions, but data setting. 
Originally, I was using data.frame for likelihood calculation. Then, I changed 
data.frame to vector and matrix for the same likelihood calculation.  Now 
convergence takes ~ 14 sec instead of 25 min. Certainly, I didn't know this 
simple change makes huge computational difference.

 

Toshihide Hamachan Hamazaki, 濱崎俊秀PhD
Alaska Department of Fish and Game: アラスカ州漁業野生動物課
Diivision of Commercial Fisheries: 商業漁業部
333 Raspberry Rd.  Anchorage, AK 99518
Phone:  (907)267-2158
Cell:  (907)440-9934

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Ben Bolker
Sent: Wednesday, July 13, 2011 12:21 PM
To: r-h...@stat.math.ethz.ch
Subject: Re: [R] Very slow optim()

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:

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

  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.

  Ben

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Very slow optim(): solved

2011-07-14 Thread Mike Marchywka





 Date: Thu, 14 Jul 2011 12:44:18 -0800
 From: toshihide.hamaz...@alaska.gov
 To: r-h...@stat.math.ethz.ch
 Subject: Re: [R] Very slow optim(): solved

 After Googling and trial and errors, the major cause of optimization was not 
 functions, but data setting.
 Originally, I was using data.frame for likelihood calculation. Then, I 
 changed data.frame to vector and matrix for the same likelihood calculation. 
 Now convergence takes ~ 14 sec instead of 25 min. Certainly, I didn't know 
 this simple change makes huge computational difference.

Thanks, can you pass along any additional details like google links you found 
or comment on
the resulting limitation( were you CPU limited converting data formats or did 
this cause memory
problems leading to VM thrashing?)? I've often had c++ code that turns out to 
be IO limited
when I expected I was doing real complicated computations, it never hurts to go 
beyond
the usual suspects LOL. 







 Toshihide Hamachan Hamazaki, 濱崎俊秀PhD
 Alaska Department of Fish and Game: アラスカ州漁業野生動物課
 Diivision of Commercial Fisheries: 商業漁業部
 333 Raspberry Rd. Anchorage, AK 99518
 Phone: (907)267-2158
 Cell: (907)440-9934

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of Ben Bolker
 Sent: Wednesday, July 13, 2011 12:21 PM
 To: r-h...@stat.math.ethz.ch
 Subject: Re: [R] Very slow optim()

 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:

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

 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.

 Ben

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.