set.seed(123)
##########################################################
### "ONE-SHOT" EI-MAXIMIZATION OF THE BRANIN FUNCTION ####
### KNOWN AT 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 one step
library(rgenoud)
lower <- rep(0,d)
upper <- rep(1,d) # domain for Branin function
oEGO <- max_EI(fitted.model1, lower=lower, upper=upper,
control=list(pop.size=20, BFGSburnin=2))
print(oEGO)
# graphics
n.grid <- 20
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[1], oEGO$par[2], pch=19, col="red")
#############################################################
### "ONE-SHOT" EI-MAXIMIZATION OF THE CAMELBACK FUNCTION ####
### KNOWN AT A 16-POINTS FACTORIAL DESIGN ####
#############################################################
## Not run:
# # a 16-points factorial design, and the corresponding response
# d <- 2
# n <- 16
# design.fact <- expand.grid(seq(0,1,length=4), seq(0,1,length=4))
# names(design.fact)<-c("x1", "x2")
# design.fact <- data.frame(design.fact)
# names(design.fact) <- c("x1", "x2")
# response.camelback <- apply(design.fact, 1, camelback)
# response.camelback <- data.frame(response.camelback)
# names(response.camelback) <- "y"
#
# # model identification
# fitted.model1 <- km(~1, design=design.fact, response=response.camelback,
# covtype="gauss", control=list(pop.size=50,trace=FALSE), parinit=c(0.5, 0.5))
#
# # EI maximization
# library(rgenoud)
# lower <- rep(0,d)
# upper <- rep(1,d)
# oEGO <- max_EI(fitted.model1, lower=lower, upper=upper,
# control=list(pop.size=20, BFGSburnin=2))
# print(oEGO)
#
# # graphics
# n.grid <- 20
# x.grid <- y.grid <- seq(0,1,length=n.grid)
# design.grid <- expand.grid(x.grid, y.grid)
# response.grid <- apply(design.grid, 1, camelback)
# z.grid <- matrix(response.grid, n.grid, n.grid)
# contour(x.grid,y.grid,z.grid,40)
# title("Camelback Function")
# points(design.fact[,1], design.fact[,2], pch=17, col="blue")
# points(oEGO$par[1], oEGO$par[2], pch=19, col="red")
# ## End(Not run)
####################################################################
### "ONE-SHOT" EI-MAXIMIZATION OF THE GOLDSTEIN-PRICE FUNCTION #####
### KNOWN AT 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="gen")
#
# # EI maximization
# library(rgenoud)
# lower <- rep(0,d); upper <- rep(1,d); # domain for Branin function
# oEGO <- max_EI(fitted.model1, lower=lower, upper=upper, control
# =list(pop.size=50, max.generations=50, wait.generations=5, BFGSburnin=10))
# print(oEGO)
#
# # graphics
# n.grid <- 20
# 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[1], oEGO$par[2], pch=19, col="red")
# ## End(Not run)
Run the code above in your browser using DataLab