n <- 1500; nNew <- 100; d <- 4
fTest <- function(x)((x[1] + 2 * x[2] + 3 * x[3] + 4 * x[4]) / 12)^2
set.seed(12345)
X <- matrix(runif(n*d), nrow = n, ncol = d)
y <- apply(X, 1, FUN = fTest)
XNew <- matrix(runif(nNew * d), nrow = nNew, ncol = d)
yNew <- apply(XNew, 1, FUN = fTest)
system.time(res <- qsheppInt(X = X, XNew = XNew, y = y, nQ = 40,
checkX = FALSE))
## check errors
max(abs(res$yNew - yNew))
##=========================================================================
## Use SHEPPACK test functions see Thacker et al. section 7 'PERFORMANCE'
##=========================================================================
set.seed(1234)
d <- 3
k <- 0:4; n0 <- 100 * 2^k; n1 <- 4
GD <- Grid(nlevels = rep(n1, d))
XNew <- as.matrix(GD)
RMSE <- array(NA, dim = c(5, length(k)),
dimnames = list(fun = 1:5, k = k))
for (iFun in 1:5) {
yNew <- apply(XNew, 1, ShepFuns[[iFun]])
for (iN in 1:length(n0)) {
X <- matrix(runif(n0[iN] * d), ncol = d)
y <- apply(X, 1, ShepFuns[[iFun]])
res <- qsheppInt(X = X, XNew = XNew, y = y, nQ = 40, checkX = FALSE)
RMSE[iFun, iN] <- mean((res$yNew - yNew)^2)
}
}
cols <- c("black", "SteelBlue2", "orangered", "SpringGreen3", "purple")
pchs <- c(16, 21, 22, 23, 24)
matplot(k, t(RMSE), type = "o", lwd = 2, lty = 1,
col = cols, xaxt = "n", pch = pchs, cex = 1.4,
bg = "white",
main = sprintf("dim = %d SHEPPACK test functions", d),
xlab = "number of nodes", ylab = "RMSE")
axis(side = 1, at = k, labels = n0)
legend("topright", legend = paste("shepFun", 1:5),
col = cols, pch = pchs, lwd = 2, pt.lwd = 2, pt.bg = "white")
Run the code above in your browser using DataLab