code: def gaussian_ei(X, model, y_opt=0.0, xi=0.01, return_grad=False):
      """
      Use the expected improvement to calculate the acquisition values.
  
      The conditional probability `P(y=f(x) | x)` form a gaussian with a certain
      mean and standard deviation approximated by the model.
  
      The EI condition is derived by computing ``E[u(f(x))]``
      where ``u(f(x)) = 0``, if ``f(x) > y_opt`` and ``u(f(x)) = y_opt - f(x)``,
      if``f(x) < y_opt``.
  
      This solves one of the issues of the PI condition by giving a reward
      proportional to the amount of improvement got.
  
      Note that the value returned by this function should be maximized to
      obtain the ``X`` with maximum improvement.
  
      Parameters
      ----------
      X : array-like, shape=(n_samples, n_features)
          Values where the acquisition function should be computed.
  
      model : sklearn estimator that implements predict with ``return_std``
          The fit estimator that approximates the function through the
          method ``predict``.
          It should have a ``return_std`` parameter that returns the standard
          deviation.
  
      y_opt : float, default 0
          Previous minimum value which we would like to improve upon.
  
      xi : float, default=0.01
          Controls how much improvement one wants over the previous best
          values. Useful only when ``method`` is set to "EI"
  
      return_grad : boolean, optional
          Whether or not to return the grad. Implemented only for the case where
          ``X`` is a single sample.
  
      Returns
      -------
      values : array-like, shape=(X.shape[0],)
          Acquisition function values computed at X.
      """
      with warnings.catch_warnings():
          warnings.simplefilter("ignore")
  
          if return_grad:
              mu, std, mu_grad, std_grad = model.predict(
                  X,
                  return_std=True,
                  return_mean_grad=True,
                  return_std_grad=True,
              )
  
          else:
              mu, std = model.predict(X, return_std=True)
  
      # check dimensionality of mu, std so we can divide them below
      if (mu.ndim != 1) or (std.ndim != 1):
          raise ValueError(
              "mu and std are {}-dimensional and {}-dimensional, "
              "however both must be 1-dimensional. Did you train "
              "your model with an (N, 1) vector instead of an "
              "(N,) vector?".format(mu.ndim, std.ndim)
          )
  
      values = np.zeros_like(mu)
      mask = std > 0
      improve = y_opt - xi - mu[mask]
      scaled = improve / std[mask]
      cdf = norm.cdf(scaled)
      pdf = norm.pdf(scaled)
      exploit = improve * cdf
      explore = std[mask] * pdf
      values[mask] = exploit + explore
  
      if return_grad:
          if not np.all(mask):
              return values, np.zeros_like(std_grad)
  
          # Substitute (y_opt - xi - mu) / sigma = t and apply chain rule.
          # improve_grad is the gradient of t wrt x.
          improve_grad = -mu_grad * std - std_grad * improve
          improve_grad /= std**2
          cdf_grad = improve_grad * pdf
          pdf_grad = -improve * cdf_grad
          exploit_grad = -mu_grad * cdf - pdf_grad
          explore_grad = std_grad * pdf + pdf_grad
  
          grad = exploit_grad + explore_grad
          return values, grad
  
      return values
  
file_path: scikit-optimize/skopt/acquisition.py
imports: import numpy
  import warnings
  from scipy.stats import norm
label_desc: Use image node_id 5 for calling a global function with example usage: gaussian_ei(X, model, y_opt, xi, return_grad) and returns: values, values,  grad, values,  np