# NOT RUN {
#We apply a shift to the function
testFn = function(x){
y = sin(2*pi*x*2+0.2)
}
#Get data
X = seq(0,1,0.1)
Y = testFn(X)
#Call gpHist function
#gp_hist = gpHist(matrix(X),matrix(Y),sigma=0.01)
#add a positive shift to the data
transform= function(X,p){
X+p
}
##estimate hyperparameters
res = estimateHyperParameters(matrix(X),matrix(Y),paramLower = c(0.001,0.0001),
paramUpper = c(0.01,1),datatransform = transform,nParams = 1)
##data need to be trannsformed for the training
X_trans = matrix(transform(X,res[2] ) )
gp_hist = gpHist(X_trans,matrix(Y),sigma=res[1])
##new data to be predicted has also be to transformed
x_pred = matrix(seq(0,1,0.01))
x_pred_trans = transform(x_pred,res[2])
prediction = gpHistPredict(gp_hist,X_trans, x_pred_trans)
plot(X,Y)
## note that we need to use the data before transformation for real x values
lines(x_pred, prediction,col='red')
legend('topleft',legend=c('Data', 'Approximation'), col=c('black','red'),
lty=c(NA,1),pch=c(1,NA))
# }
Run the code above in your browser using DataLab