Professional Documents
Culture Documents
2023-01-14
set.seed(2023)
f <- function(x){
a <- 0.75*exp(-((9*x[1]-2)ˆ2)/4 - ((9*x[2]-2)ˆ2)/4)
b <- 0.75*exp(-((9*x[1]+1)ˆ2)/49 - (9*x[2]+1)/10)
c <- 0.5*exp(-((9*x[1]-7)ˆ2)/4 - ((9*x[2]-3)ˆ2)/4)
d <- 0.2*exp(-((9*x[1]-4)ˆ2) - ((9*x[2]-7)ˆ2))
a + b + c - d
}
## draw the random uniforms and turn the hypercube into a sample
U <- matrix(runif(n*m), ncol=m)
X <- (L + (n - 1)/2 + U)/n
colnames(X) <- paste0("x", 1:m)
#Random Design
X.ran <- matrix(runif(n*m), ncol=m)
colnames(X.ran) <- paste0("x", 1:m)
y.ran <- apply(X.ran, 1, f)
1
1.0
1.0
0.8
0.8
0.6
0.6
x2
x2
0.4
0.4
0.2
0.2
0.0
0.0 0.2 0.4 0.6 0.8 1.0 0.0 0.0 0.2 0.4 0.6 0.8 1.0
x1 x1
library(DiceKriging)
model.lhs <- km(formula=~1, design = X.lhs, response = y.lhs, covtype="gauss", nugget = 10ˆ(-11), contro
model.ran <- km(formula=~1, design = X.ran, response = y.ran, covtype="gauss", nugget = 10ˆ(-11), contro
library(randtoolbox)
testing=sobol(1000,2)
colnames(testing) <- c("x1", "x2")
y.test <- apply(testing, 1, f)
c(mspe.lhs, mspe.ran)
2
## [1] 0.02868812 0.03060818
model.1 <- km(formula=~1, design = X.lhs, response = y.lhs, covtype="gauss", nugget = 10ˆ(-11), control
pred.1 <- predict(model.1, testing, type = "SK")
mspe.1 <- sqrt(mean((y.test - pred.1$mean)ˆ2))
model.2 <- km(formula=~1+x1, design = X.lhs, response = y.lhs, covtype="gauss", nugget = 10ˆ(-11), contr
pred.2 <- predict(model.2, testing, type = "SK")
mspe.2 <- sqrt(mean((y.test - pred.2$mean)ˆ2))
model.3 <- km(formula=~1+x1+x2, design = X.lhs, response = y.lhs, covtype="gauss", nugget = 10ˆ(-11), co
pred.3 <- predict(model.3, testing, type = "SK")
mspe.3 <- sqrt(mean((y.test - pred.3$mean)ˆ2))
model.4 <- km(formula=~1+I(x2ˆ2), design = X.lhs, response = y.lhs, covtype="gauss", nugget = 10ˆ(-11),
pred.4 <- predict(model.4, testing, type = "SK")
mspe.4 <- sqrt(mean((y.test - pred.4$mean)ˆ2))