set.seed(123)
###############################################################
### 10 ITERATIONS OF EGO ON THE BRANIN FUNCTION, ####
### STARTING FROM A 9-POINTS FACTORIAL DESIGN ####
###############################################################
# a 9-points factorial design, and the corresponding response
d <- 2
n <- 9
design.fact <- expand.grid(seq(0,1,length=3), seq(0,1,length=3))
names(design.fact)<-c("x1", "x2")
design.fact <- data.frame(design.fact)
names(design.fact)<-c("x1", "x2")
response.branin <- apply(design.fact, 1, branin)
response.branin <- data.frame(response.branin)
names(response.branin) <- "y"
# model identification
fitted.model1 <- km(~1, design=design.fact, response=response.branin,
covtype="gauss", control=list(pop.size=50,trace=FALSE), parinit=c(0.5, 0.5))
# EGO n steps
library(rgenoud)
nsteps <- 5 # Was 10, reduced to 5 for speeding up compilation
lower <- rep(0,d)
upper <- rep(1,d)
oEGO <- EGO.nsteps(model=fitted.model1, fun=branin, nsteps=nsteps,
lower=lower, upper=upper, control=list(pop.size=20, BFGSburnin=2))
print(oEGO$par)
print(oEGO$value)
# graphics
n.grid <- 15 # Was 20, reduced to 15 for speeding up compilation
x.grid <- y.grid <- seq(0,1,length=n.grid)
design.grid <- expand.grid(x.grid, y.grid)
response.grid <- apply(design.grid, 1, branin)
z.grid <- matrix(response.grid, n.grid, n.grid)
contour(x.grid, y.grid, z.grid, 40)
title("Branin function")
points(design.fact[,1], design.fact[,2], pch=17, col="blue")
points(oEGO$par, pch=19, col="red")
text(oEGO$par[,1], oEGO$par[,2], labels=1:nsteps, pos=3)
###############################################################
### 20 ITERATIONS OF EGO ON THE GOLDSTEIN-PRICE, ####
### STARTING FROM A 9-POINTS FACTORIAL DESIGN ####
###############################################################
## Not run:
# # a 9-points factorial design, and the corresponding response
# d <- 2
# n <- 9
# design.fact <- expand.grid(seq(0,1,length=3), seq(0,1,length=3))
# names(design.fact)<-c("x1", "x2")
# design.fact <- data.frame(design.fact)
# names(design.fact)<-c("x1", "x2")
# response.goldsteinPrice <- apply(design.fact, 1, goldsteinPrice)
# response.goldsteinPrice <- data.frame(response.goldsteinPrice)
# names(response.goldsteinPrice) <- "y"
#
# # model identification
# fitted.model1 <- km(~1, design=design.fact, response=response.goldsteinPrice,
# covtype="gauss", control=list(pop.size=50, max.generations=50,
# wait.generations=5, BFGSburnin=10,trace=FALSE), parinit=c(0.5, 0.5), optim.method="BFGS")
#
# # EGO n steps
# library(rgenoud)
# nsteps <- 10 # Was 20, reduced to 10 for speeding up compilation
# lower <- rep(0,d)
# upper <- rep(1,d)
# oEGO <- EGO.nsteps(model=fitted.model1, fun=goldsteinPrice, nsteps=nsteps,
# lower, upper, control=list(pop.size=20, BFGSburnin=2))
# print(oEGO$par)
# print(oEGO$value)
#
# # graphics
# n.grid <- 15 # Was 20, reduced to 15 for speeding up compilation
# x.grid <- y.grid <- seq(0,1,length=n.grid)
# design.grid <- expand.grid(x.grid, y.grid)
# response.grid <- apply(design.grid, 1, goldsteinPrice)
# z.grid <- matrix(response.grid, n.grid, n.grid)
# contour(x.grid, y.grid, z.grid, 40)
# title("Goldstein-Price Function")
# points(design.fact[,1], design.fact[,2], pch=17, col="blue")
# points(oEGO$par, pch=19, col="red")
# text(oEGO$par[,1], oEGO$par[,2], labels=1:nsteps, pos=3)
# ## End(Not run)
#######################################################################
### nsteps ITERATIONS OF EGO ON THE HARTMAN6 FUNCTION, ####
### STARTING FROM A 10-POINTS UNIFORM DESIGN ####
#######################################################################
## Not run:
# fonction<-hartman6
# data(mydata)
# a <- mydata
# nb<-10
# nsteps <- 3 # Maybe be changed to a larger value
# x1<-a[[1]][1:nb];x2<-a[[2]][1:nb];x3<-a[[3]][1:nb]
# x4<-a[[4]][1:nb];x5<-a[[5]][1:nb];x6<-a[[6]][1:nb]
# design <- data.frame(cbind(x1,x2,x3,x4,x5,x6))
# names(design)<-c("x1", "x2","x3","x4","x5","x6")
# n <- nrow(design)
#
# response <- data.frame(q=apply(design,1,fonction))
# names(response) <- "y"
# fitted.model1 <- km(~1, design=design, response=response, covtype="gauss",
# control=list(pop.size=50, max.generations=20, wait.generations=5, BFGSburnin=5,
# trace=FALSE), optim.method="gen", parinit=rep(0.8,6))
#
# res.nsteps <- EGO.nsteps(model=fitted.model1, fun=fonction, nsteps=nsteps,
# lower=rep(0,6), upper=rep(1,6), parinit=rep(0.5,6), control=list(pop.size=50,
# max.generations=20, wait.generations=5, BFGSburnin=5), kmcontrol=NULL)
# print(res.nsteps)
# plot(res.nsteps$value,type="l")
# ## End(Not run)
Run the code above in your browser using DataLab