code: def _expected_improvement(
      x,
      fun_prediction,
      fun_prediction_args,
      x_bounds,
      x_types,
      samples_y_aggregation,
      minimize_constraints_fun,
  ):
      # This is only for step-wise optimization
      x = lib_data.match_val_type(x, x_bounds, x_types)
  
      expected_improvement = sys.maxsize
      if (minimize_constraints_fun is None) or (
          minimize_constraints_fun(x) is True
      ):
          mu, sigma = fun_prediction(x, *fun_prediction_args)
  
          loss_optimum = min(samples_y_aggregation)
          scaling_factor = -1
  
          # In case sigma equals zero
          with numpy.errstate(divide="ignore"):
              Z = scaling_factor * (mu - loss_optimum) / sigma
              expected_improvement = scaling_factor * (
                  mu - loss_optimum
              ) * norm.cdf(Z) + sigma * norm.pdf(Z)
              expected_improvement = (
                  0.0 if sigma == 0.0 else expected_improvement
              )
  
          # We want expected_improvement to be as large as possible
          # (i.e., as small as possible for minimize(...))
          expected_improvement = -1 * expected_improvement
      return expected_improvement
  
file_path: nni/nni/algorithms/hpo/metis_tuner/lib_acquisition_function.py
imports: import sys
  import numpy
  from scipy.stats import norm
  from scipy.optimize import minimize
  from .None import lib_data
label_desc: Use image node_id 2 for calling a global function with example usage: _expected_improvement(x, fun_prediction, fun_prediction_args, x_bounds, x_types, samples_y_aggregation, minimize_constraints_fun) and returns: expected_improvement