#max_futureVol_parallel
set.seed(9)
N <- 20 #number of observations
T <- 80 #threshold
testfun <- branin
lower <- c(0,0)
upper <- c(1,1)
#a 20 points initial design
design <- data.frame( matrix(runif(2*N),ncol=2) )
response <- testfun(design)
#km object with matern3_2 covariance
#params estimated by ML from the observations
model <- km(formula=~., design = design,
response = response,covtype="matern3_2")
optimcontrol <- list(method="genoud",pop.size=200,optim.option=2)
integcontrol <- list(distrib="timse",n.points=400,init.distrib="MC")
integration.param <- integration_design(integcontrol=integcontrol,d=2,
lower=lower,upper=upper,model=model,
T=T)
batchsize <- 5 #number of new points
if (FALSE) {
obj <- max_futureVol_parallel(lower=lower,upper=upper,optimcontrol=optimcontrol,
batchsize=batchsize,T=T,model=model,
integration.param=integration.param)
#5 optims in dimension 2 !
obj$par;obj$value #optimum in 5 new points
new.model <- update(object=model,newX=obj$par,newy=apply(obj$par,1,testfun),
cov.reestim=TRUE)
consLevel = 0.95; n_discrete_design=500*new.model@d
CE_design=as.matrix (randtoolbox::sobol (n = n_discrete_design,
dim = new.model@d))
colnames(CE_design) <- colnames(new.model@X)
current.pred = predict.km(object = new.model,
newdata = CE_design,
type = "UK",cov.compute = TRUE)
current.pred$cov <- current.pred$cov +1e-7*diag(nrow = nrow(current.pred$cov),
ncol = ncol(current.pred$cov))
current.CE = anMC::conservativeEstimate(alpha = consLevel, pred=current.pred,
design=CE_design, threshold=T, pn = NULL,
type = ">", verb = 1,
lightReturn = TRUE, algo = "GANMC")
par(mfrow=c(1,2))
print_uncertainty(model=model,T=T,type="pn",lower=lower,upper=upper,
cex.points=2.5,main="probability of excursion",consQuantile=obj$alpha)
print_uncertainty(model=new.model,T=T,type="pn",lower=lower,upper=upper,
new.points=batchsize,col.points.end="red",cex.points=2.5,
main="updated probability of excursion",consQuantile=current.CE$lvs)
}
Run the code above in your browser using DataLab