####################################################################
#a 8 points initial design (a LHS in 2d)
design.fact <- maximinLHS(8,k=2) #dimension = 2
design.fact <- data.frame(design.fact)
names(design.fact) <- c ( "x1","x2")
testfun <- camelback2 #our test function
#the response
response <- testfun(design.fact)
#the initial km model
model <- km(formula=~., design = design.fact, response = response, covtype="matern5_2")
#the integration points
intpoints <- expand.grid(seq(0,1,length=20), seq(0,1,length=20))
#the inversion threshold
T <- 0
#the number of iterations
iter <- 1
#inversion
res1 <- EGI(T=T,model=model,iter=iter,sampling.method="sur",
lower=c(0,0),upper=c(1,1),fun=testfun,discrete.X=intpoints)
res2 <- EGI(T=T,model=model,iter=iter,sampling.method="sur",
lower=c(0,0),upper=c(1,1),fun=testfun)
res3 <- EGI(T=T,model=model,iter=iter,sampling.method="timse",
lower=c(0,0),upper=c(1,1),fun=testfun,discrete.X=intpoints)
res4 <- EGI(T=T,model=model,iter=iter,sampling.method="ranjan",
lower=c(0,0),upper=c(1,1),fun=testfun,method.param=0.5)
res5 <- EGI(T=T,model=model,iter=iter,sampling.method="bichon",
lower=c(0,0),upper=c(1,1),fun=testfun,method.param=0.5)
#plot of the function on a 50 x 50 grid
resolution <- 50
s <- seq(0,1,,resolution)
full_design <- expand.grid(s,s)
resp <- testfun(full_design)
par(mfrow=c(1,1))
contour(s,s,matrix(resp, nrow=resolution),20)
#initial points
points(design.fact, col="black", pch=20, lwd=4)
#new points
points(res1$par, col="red", pch=20, lwd=4)
text( res1$par[,1],res1$par[,2], seq(1,nrow(res1$par)), pos=3)
#new points
points(res2$par, col="blue", pch=20, lwd=4)
text( res2$par[,1],res2$par[,2], seq(1,nrow(res2$par)), pos=3)
#new points
points(res3$par, col="grey", pch=20, lwd=4)
text( res3$par[,1],res3$par[,2], seq(1,nrow(res3$par)), pos=3)
#new points
points(res4$par, col="green", pch=20, lwd=4)
text( res4$par[,1],res4$par[,2], seq(1,nrow(res4$par)), pos=3)
#new points
points(res5$par, col="purple", pch=20, lwd=4)
text( res5$par[,1],res5$par[,2], seq(1,nrow(res5$par)), pos=3)
##################################################################
#same example with noisy initial observations and noisy new
#observations:
#library("lhs")
#a 8 points initial design (a LHS in 2d)
design.fact <- maximinLHS(8,k=2) #dimension = 2
design.fact <- data.frame(design.fact)
names(design.fact) <- c ( "x1","x2")
testfun <- camelback2 #our test function
#the response
response <- testfun(design.fact)+rnorm(n=8,mean=0,sd=0.25)
#the noise variance vector
noise.var <- rep(x=0.05,times=8)
#the initial km model
model <- km(formula=~1, design = design.fact, response = response,noise.var = noise.var )
#the integration points
intpoints <- expand.grid(seq(0,1,length=20), seq(0,1,length=20))
#the inversion threshold
T <- -1
#the number of iterations
iter <- 1
#the new observations variance
new.var <- 0.01
#EGI call
res <- EGI(T=T,model=model,iter=iter,sampling.method="timse",
lower=c(0,0),upper=c(1,1),fun=testfun,discrete.X=intpoints,
new.noise.var = new.var)
#plot of the function on a 50 x 50 grid
resolution <- 50
s <- seq(0,1,,resolution)
full_design <- expand.grid(s,s)
resp <- testfun(full_design)
par(mfrow=c(1,1))
contour(s,s,matrix(resp, nrow=resolution),20)
#initial points
points(design.fact, col="black", pch=20, lwd=4)
#new points
points(res$par, col="red", pch=20, lwd=4)
text( res$par[,1],res$par[,2], seq(1,nrow(res$par)), pos=3)
##################################################################
Run the code above in your browser using DataLab