code: def estimate_L(model, bounds, storehistory=True):
      """
      Estimate the Lipschitz constant of f by taking maximizing the norm of the expectation of the gradient of *f*.
      """
  
      def df(x, model, x0):
          x = np.atleast_2d(x)
          dmdx, _ = model.predictive_gradients(x)
          if dmdx.ndim > 2:
              dmdx = dmdx.reshape(dmdx.shape[:2])
          res = np.sqrt(
              (dmdx * dmdx).sum(1)
          )  # simply take the norm of the expectation of the gradient
          return -res
  
      samples = samples_multidimensional_uniform(bounds, 500)
      samples = np.vstack([samples, model.X])
      pred_samples = df(samples, model, 0)
      x0 = samples[np.argmin(pred_samples)]
      res = scipy.optimize.minimize(
          df,
          x0,
          method="L-BFGS-B",
          bounds=bounds,
          args=(model, x0),
          options={"maxiter": 200},
      )
      minusL = float(res.fun)
      L = -minusL
      if L < 1e-7:
          L = 10  ## to avoid problems in cases in which the model is flat.
      return L
  
file_path: GPyOpt/GPyOpt/core/evaluators/batch_local_penalization.py
imports: from .base import EvaluatorBase
  import scipy
  from ...util.general import samples_multidimensional_uniform
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: estimate_L(model, bounds, storehistory) and returns: L, unknown