% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/optim.R
\name{crit_EI}
\alias{crit_EI}
\title{Expected Improvement criterion}
\usage{
crit_EI(x, model, cst = NULL, preds = NULL)
}
\arguments{
\item{x}{matrix of new designs, one point per row (size n x d)}

\item{model}{\code{homGP} or \code{hetGP} model, or their TP equivalents, including inverse matrices}

\item{cst}{optional plugin value used in the EI, see details}

\item{preds}{optional predictions at \code{x} to avoid recomputing if already done}
}
\description{
Computes EI for minimization
}
\details{
\code{cst} is classically the observed minimum in the deterministic case. 
In the noisy case, the min of the predictive mean works fine.
}
\note{
This is a beta version at this point.
}
\examples{
## Optimization example
set.seed(42)


## Noise field via standard deviation
noiseFun <- function(x, coef = 1.1, scale = 1){
if(is.null(nrow(x)))
 x <- matrix(x, nrow = 1)
   return(scale*(coef + cos(x * 2 * pi)))
}

## Test function defined in [0,1]
ftest <- function(x){
if(is.null(nrow(x)))
x <- matrix(x, ncol = 1)
return(f1d(x) + rnorm(nrow(x), mean = 0, sd = noiseFun(x)))
}

n_init <- 10 # number of unique designs
N_init <- 100 # total number of points
X <- seq(0, 1, length.out = n_init)
X <- matrix(X[sample(1:n_init, N_init, replace = TRUE)], ncol = 1)
Z <- ftest(X)

## Predictive grid
ngrid <- 51
xgrid <- seq(0,1, length.out = ngrid)
Xgrid <- matrix(xgrid, ncol = 1)

model <- mleHetGP(X = X, Z = Z, lower = 0.001, upper = 1)

EIgrid <- crit_EI(Xgrid, model)
preds <- predict(x = Xgrid, model)

par(mar = c(3,3,2,3)+0.1)
plot(xgrid, f1d(xgrid), type = 'l', lwd = 1, col = "blue", lty = 3,
xlab = '', ylab = '', ylim = c(-8,16))
points(X, Z)
lines(Xgrid, preds$mean, col = 'red', lwd = 2)
lines(Xgrid, qnorm(0.05, preds$mean, sqrt(preds$sd2)), col = 2, lty = 2)
lines(Xgrid, qnorm(0.95, preds$mean, sqrt(preds$sd2)), col = 2, lty = 2)
lines(Xgrid, qnorm(0.05, preds$mean, sqrt(preds$sd2 + preds$nugs)), col = 3, lty = 2)
lines(Xgrid, qnorm(0.95, preds$mean, sqrt(preds$sd2 + preds$nugs)), col = 3, lty = 2)
par(new = TRUE)
plot(NA, NA, xlim = c(0, 1), ylim = c(0,max(EIgrid)), axes = FALSE, ylab = "", xlab = "")
lines(xgrid, EIgrid, lwd = 2, col = 'cyan')
axis(side = 4)
mtext(side = 4, line = 2, expression(EI(x)), cex = 0.8)
mtext(side = 2, line = 2, expression(f(x)), cex = 0.8)
}
\references{
Mockus, J.; Tiesis, V. & Zilinskas, A. (1978).
The application of Bayesian methods for seeking the extremum Towards Global Optimization, Amsterdam: Elsevier, 2, 2.\cr \cr

Vazquez E, Villemonteix J, Sidorkiewicz M, Walter E (2008). 
Global Optimization Based on Noisy Evaluations: An Empirical Study of Two Statistical Approaches, 
Journal of Physics: Conference Series, 135, IOP Publishing.\cr \cr

A. Shah, A. Wilson, Z. Ghahramani (2014), Student-t processes as alternatives to Gaussian processes, Artificial Intelligence and Statistics, 877--885.
}
