f <- function(x) {
10 * sin(pi * x[,1] * x[,2]) + 20 * (x[,3] - 0.5)^2 +
10 * x[,4] + 5 * x[,5]
}
set.seed(99)
sigma <- 1.0
n <- 100
x <- matrix(runif(n * 10), n, 10)
Ey <- f(x)
y <- rnorm(n, Ey, sigma)
mad <- function(y.train, y.train.hat, weights) {
# note, weights are ignored
mean(abs(y.train - apply(y.train.hat, 1L, mean)))
}
## low iteration numbers to to run quickly
xval <- xbart(x, y, n.samples = 15L, n.reps = 4L, n.burn = c(10L, 3L, 1L),
n.trees = c(5L, 7L),
k = c(1, 2, 4),
power = c(1.5, 2),
base = c(0.75, 0.8, 0.95), n.threads = 1L,
loss = mad)
Run the code above in your browser using DataLab