View source: R/generateBenchmarkSet.R
generateCOBBS | R Documentation |
Based on provided data and parameters, this function trains a GPR model, then generates the corresponding simulations, and returns them as a set of functions to the user. For the sake of comparison, the predictor (estimation) of the GPR model is also returned
generateCOBBS(x, y, control = list())
x |
matrix of sample locations |
y |
vector of observations at sample locations x |
control |
(list), specifying the options for model training and simulation:
|
fit
object/fit produced by gaussianProcessRegression
estimation
a function, GPR predictor
simulation
a list of one or more test functions to be used for benchmarking (based on GPR simulation)
## generate some data
seed <- 1234
groundtruth <- function(x){
x=matrix(x,,1)
apply(x,1,smoof::makeDeflectedCorrugatedSpringFunction(1))
}
lower = 0
upper = 10
set.seed(seed)
x <- matrix(c(runif(8,lower,upper)),,1)
y <- matrix(groundtruth(x),,1)
## specify some model configuration
mc <- list(useLambda=FALSE,budgetAlgTheta=200,thetaUpper=1e4)
## and some configuration details for the simulation
cntrl <- list(modelControl=mc,
nsim=1,
seed=seed,
method="spectral",
#method="decompose",xsim=matrix(c(runif(200,-32,32)),,1),
conditionalSimulation=TRUE
)
## generate model and functions
cobbsResult <- generateCOBBS(x,y,cntrl)
cobbsResult$fit
## plot the functions
require(ggplot2)
xseq <- seq(from=lower,by=0.001,to=upper)
p <- ggplot()
## plot trained model (predictor, estimatation)
df <- data.frame(x=xseq,y=cobbsResult$estimation(xseq))
p <- p + geom_line(aes(x=x,y=y),df,size=1,color="darkgray")
## plot true function
df <- data.frame(x=xseq,y=groundtruth(xseq))
p <- p + geom_line(aes(x=x,y=y),df,size=1,linetype=2)
## plot training data
df <- data.frame(x=x,y=y)
p <- p + geom_point(aes(x=x,y=y),df,size=2,fill="white",shape = 21)
## plot simulation
df <- data.frame(x=xseq,y=cobbsResult$simulation[[1]](xseq))
p <- p + geom_line(aes(x=x,y=y),df,size=1,color="red")
## some stuff for good looks
p <- p + theme_classic()
p <- p + xlab("x") + ylab("f(x)")
print(p)
## prepare an expression that will be run during the experiments
## here: L-BFGS-B with random initial guess
require(nloptr)
expr <- expression(
res <- lbfgs(x0=matrix(runif(1,lower,upper),1,1),fn = fnlog,
lower=lower,upper=upper)
)
## run the experiments, with logging
## with each objective function produced by COBBS
resgt <- loggedExperiment(expr, groundtruth, 1:10)
reses <- loggedExperiment(expr, cobbsResult$estimation, 1:10)
ressi <- loggedExperiment(expr, cobbsResult$simulation[[1]], 1:10)
## plot results
print(plotBenchmarkPerformance(list(resgt,reses)))
print(plotBenchmarkPerformance(list(resgt,reses,ressi),c("groundtruth","estimation","simulation")))
## plot error, comparing against groundtruth
print(plotBenchmarkValidation(resgt,list(reses),c("estimation")))
print(plotBenchmarkValidation(resgt,list(reses,ressi),c("estimation","simulation")))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.