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

Bob Reilly rjreilly at starband.net
Wed Apr 16 00:59:12 CEST 2008


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



More information about the R-help mailing list