Hi Ilai,

after you sent this message I tried your code as well and it worked. As a 
result, I reconsidered the code written by me and of course also found the 
error in my function simulateEKOP. So for other people assuming errors or ill 
behavior in base functions: Forget it: these functions are tested this often, 
that the probabilitty is almost 1, the error is in your own code. 

Thanks for the help

Simon


On Jun 3, 2013, at 10:53 PM, ilai <ke...@math.montana.edu> wrote:

> On Mon, Jun 3, 2013 at 11:37 AM, Simon Zehnder <szehn...@uni-bonn.de>
> 
> ... [Some not minimal, self contained, reproducible code]...
>    
> Data simulation and thecreation of startpar works fine, but the parameters in 
> res$par are always the start parameters. If I run the same commands directly 
> on the shell I get in res$par the optimized parameters - only inside the 
> foreach loop optim seems not to work. What could that be?
> 
> Don't know, but but this makes me doubt it has anything to do with optim 
> being inside foreach:   
> 
> fr <- function(x) { 
>          x1 <- x[1] ; x2 <- x[2] 
>          100 * (x2 - x1 * x1)^2 + (1 - x1)^2
>      }
> grr <- function(x) {
>          x1 <- x[1] ; x2 <- x[2]
>          c(-400 * x1 * (x2 - x1 * x1) - 2 * (1 - x1) , 200 * (x2 - x1 * x1))
>      }
> library("doMC") 
> registerDoMC(2)
> RNGkind("L'Ecuyer")
> set.seed(54321)
> foreach(i = 1:2) %do% {
>   ret <- foreach(j = 1:2) %do%{
>            strtpar <- c(-2,2)+rnorm(2) 
>            optim(strtpar, fr, grr, method = 
> "L-BFGS-B",control=list(trace=TRUE))$par
>           } 
>   ret 
> } 
> 
> Also, wouldn't you want to register 4 cores by default if nesting 2 loops of 
> 2 ? (to comment on the wisdom of doing so in terms of overhead is beyond my 
> expertise)  
>  
> HTH 
> 
> 
> 
> Best
> 
> Simon
> 
> ______________________________________________
> 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.
> 


        [[alternative HTML version deleted]]

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

Reply via email to