set.seed(1224)
traindat = list()
traindat$x = GP.generate.grids(d=2,num_grids=30,random=TRUE)
testdat = list()
testdat$x = GP.generate.grids(d=2,num_grids=30,random=FALSE)
curve = GP.simulate.curve.fast(rbind(traindat$x,testdat$x),a=0.01,b=0.5,poly_degree=20L)
train_curve = list(f=curve$f[1:nrow(traindat$x)],x=traindat$x)
test_curve = list(f=curve$f[nrow(traindat$x)+1:nrow(testdat$x)],x=testdat$x)
traindat$f = train_curve$f + rnorm(length(train_curve$f),sd=1)
testdat$f = test_curve$f + rnorm(length(test_curve$f),sd=1)
fast_fit = GP.fast.Bayes.fit(traindat$f,traindat$x,a=0.01,b=0.5,poly_degree=20L,progress_bar = TRUE)
reg_fit = GP.Bayes.fit(traindat$f,traindat$x,a=0.01,b=0.5,poly_degree=20L,progress_bar = TRUE)
fast_pred = GP.predict(fast_fit,testdat$x,CI=TRUE)
reg_pred = GP.predict(reg_fit,testdat$x,CI=TRUE)
pmse = c(fast = mean((fast_pred$mean$f-test_curve$f)^2),
reg = mean((reg_pred$mean$f-test_curve$f)^2))
print(pmse)
curves = list(true = test_curve,
Bayes = reg_pred$mean,
fast = fast_pred$mean)
GP.plot.curves(curves,main="Posterior predictive mean")
Run the code above in your browser using DataLab