[R] disturbing seed dependence in optim L-BFGS-B method

Duncan Murdoch murdoch at stats.uwo.ca
Wed Apr 16 03:58:50 CEST 2008


On 15/04/2008 6:59 PM, Bob Reilly wrote:
> The the use of optim with the L-BFGS-B method for the following simple 
> function gives erroneous results.  Any help appreciated!
> 
> Best,
> Bob Reilly
> 
> # Code:
> 
> V=function(p){
> p1=p[1];p2=p[2]
> y=p1*p2-.4*(p1+p2)
> return(-y)}
> 
> p=c(.2,.2) # p=c(.8,.8)
> 
> max=optim(p,V,method = "L-BFGS-B",lower=c(0,0),upper=c(1,1))
> max1=optim(max$par,V,method = "L-BFGS-B",lower=c(0,0),upper=c(1,1))
> max2=optim(max1$par,V,method = "L-BFGS-B",lower=c(0,0),upper=c(1,1))
> 
> max$par
> max1$par
> max2$par
> 
> -max2$value
> 
> -V(c(1,1)) # true maximum occurs at c(1,1)
> # setting the seed to p=c(.8,.8) will find it

The other starting value finds c(0,0) instead, and it's locally optimal. 
   optim() can't find global optima, only local ones.  When there are 
several local ones, the one it finds depends on where it starts.

Duncan Murdoch



More information about the R-help mailing list