## see example(DEopt)
algo <- list(nP = 50L,
F = 0.5,
CR = 0.9,
min = c(-10, -10),
max = c( 10, 10),
printDetail = FALSE,
printBar = FALSE)
## choose a larger 'n' when you can afford it
algo$nG <- 100L
res100 <- restartOpt(DEopt, n = 10L, OF = tfTrefethen, algo = algo)
res100F <- sapply(res100, `[[`, "OFvalue")
algo$nG <- 300L
res300 <- restartOpt(DEopt, n = 10, OF = tfTrefethen, algo = algo)
res300F <- sapply(res300, `[[`, "OFvalue")
xx <- pretty(c(res100F, res300F, -3.31))
plot(ecdf(res100F), main = "optimum is -3.306",
xlim = c(xx[1], tail(xx,1)))
abline(v = -3.3069, col = "red") ### optimum
lines(ecdf(res300F), col = "blue")
legend(x = "right", box.lty = 0, , lty = 1,
legend = c("optimum", "100 generations", "300 generations"),
pch = c(NA, 19, 19), col = c("red", "black", "blue"))
## with R >= 2.13.0 and the compiler package
algo$nG <- 100L
system.time(res100 <- restartOpt(DEopt, n = 10L, OF = tfTrefethen, algo = algo))
require(compiler)
enableJIT(3)
system.time(res100 <- restartOpt(DEopt, n = 10L, OF = tfTrefethen, algo = algo))
Run the code above in your browser using DataLab