# NOT RUN {
## 1) without noise
x <- NULL
xnew <- matrix(1:10, ncol=2)
fun <- funSphere
control <- spotControl(dim(xnew)[2])
control$verbosity <- 0
objectiveFunctionEvaluation(x=x, xnew=xnew, fun=fun, control=control)
##
fun <- funMoo
objectiveFunctionEvaluation(x=x, xnew=xnew, fun=fun, control=control)
## 2) with noise
fun = function(x){funSphere(x) + rnorm(nrow(x))}
control$noise <- TRUE
objectiveFunctionEvaluation(x=x, xnew=xnew, fun=fun, control=control)
## 3) known solutions
x <- matrix(11:20, ncol=2)
xnew <- matrix(1:10, ncol=2)
fun <- funSphere
objectiveFunctionEvaluation(x=x, xnew=xnew, fun=fun, control=control)
## 4) known solutions with noise and repeats
x <- matrix(1:20, ncol=2, byrow=TRUE)
xnew <- matrix(1:10, ncol=2, byrow=TRUE)
fun = function(x){funSphere(x) + rnorm(nrow(x))}
objectiveFunctionEvaluation(x=x, xnew=xnew, fun=fun, control=control)
## 5) identical solutions with noise and repeats
x <- matrix(1:10, ncol=2, byrow=TRUE)
xnew <- x
fun = function(x){funSphere(x) + rnorm(nrow(x))}
y <- objectiveFunctionEvaluation(x=NULL, xnew=x, fun=fun, control=control)
y1 <- objectiveFunctionEvaluation(x=x, xnew=xnew, fun=fun, control=control)
y2 <- objectiveFunctionEvaluation(x=NULL, xnew=xnew, fun=fun, control=control)
print(cbind(x, y))
print(cbind(xnew, y1))
print(cbind(xnew, y2))
identical(y, y1) # FALSE
identical(y, y2) # TRUE
## 6) known solutions with noise and repeats. function sets seed
x <- matrix(1:20, ncol=2, byrow=TRUE)
xnew <- matrix(1:10, ncol=2, byrow=TRUE)
fun <- function(x,seed){
set.seed(seed)
funSphere(x)+rnorm(nrow(x))}
control$seedFun <- 1
y1 <- objectiveFunctionEvaluation(x=x, xnew=xnew, fun=fun, control=control)
y2 <- objectiveFunctionEvaluation(x=x, xnew=xnew, fun=fun, control=control)
identical(y1, y2) # TRUE
control$seedFun <- 2
y3 <- objectiveFunctionEvaluation(x=x, xnew=xnew, fun=fun, control=control)
identical(y1,y3) # FALSE
## 7) spot examples:
res1a <- spot(,function(x,seed){set.seed(seed);funSphere(x)+rnorm(nrow(x))},
c(-2,-3),c(1,2),control=list(funEvals=25,noise=TRUE,seedFun=1))
res1b <- spot(,function(x,seed){set.seed(seed);funSphere(x)+rnorm(nrow(x))},
c(-2,-3),c(1,2),control=list(funEvals=25,noise=TRUE,seedFun=1))
res2 <- spot(,function(x,seed){set.seed(seed);funSphere(x)+rnorm(nrow(x))},
c(-2,-3),c(1,2),control=list(funEvals=25,noise=TRUE,seedFun=2))
sprintf("Should be equal: %f = %f. Should be different: %f", res1a$ybest,
res1b$ybest, res2$ybest)
# }
Run the code above in your browser using DataLab