[R] Schwefel Function Optimization

Vartanian, Ara aravart at indiana.edu
Fri Feb 10 19:02:31 CET 2012


All,

I am looking for an optimization library that does well on something as chaotic as the Schwefel function:

schwefel <- function(x) sum(-x * sin(sqrt(abs(x))))

With these guys, not much luck:

> optim(c(1,1), schwefel)$value
[1] -7.890603
> optim(c(1,1), schwefel, method="SANN", control=list(maxit=10000))$value
[1] -28.02825
> optim(c(1,1), schwefel, lower=c(-500,-500), upper=c(500,500), method="L-BFGS-B")$value
[1] -7.890603
> optim(c(1,1), schwefel, method="BFGS")$value
[1] -7.890603
> optim(c(1,1), schwefel, method="CG")$value
[1] -7.890603

All trapped in local minima. I get the right answer when I pick a starting point that's close:

> optim(c(400,400), schwefel, lower=c(-500,-500), upper=c(500,500), method="L-BFGS-B")$value
[1] -837.9658

Of course I can always roll my own:

r <- vector()
for(i in 1:1000) {
  x <- runif(2, -500,500)
  m <- optim(x, schwefel, lower=c(-500,-500), upper=c(500,500), method="L-BFGS-B")
  r <- rbind(r, c(m$par, m$value))
}

And this does fine. I'm just wondering if this is the right approach, or if there is some other package that wraps this kind of multi-start up so that the user doesn't have to think about it.

Best,

Ara




More information about the R-help mailing list