set.seed(2)
# Generating 80 observations, with a changepoint (in our case a change in
# kernel) at observation 40
n <- 80
k0 <- 40
T <- 30
t <- seq(0, 1, length.out = T)
# Both kernels K1 and K2 are Gaussian (or squared exponential) kernels but
# with different lengthscale values, and thus we hope to detect it.
K_se <- function(s, t, ell) exp(- ( (s - t)^2 ) / (2 * ell^2))
K1 <- outer(t, t, function(a,b) K_se(a,b, ell = 0.20))
K2 <- outer(t, t, function(a,b) K_se(a,b, ell = 0.07))
L1 <- chol(K1 + 1e-8 * diag(T))
L2 <- chol(K2 + 1e-8 * diag(T))
Z1 <- matrix(rnorm(k0 * T), k0, T)
Z2 <- matrix(rnorm((n-k0) * T), n - k0, T)
# We finally have an 80 x 30 matrix where the rows are the observations and
# the columns are the grid points.
X <- rbind(Z1 %*% t(L1), Z2 %*% t(L2))
fkwc(X)
Run the code above in your browser using DataLab