class_docstr: A sequential domain reduction transformer based on the work by Stander, N. and Craig, K:
  "On the robustness of a simple domain reduction scheme for simulation‐based optimization"
class_docstr_tok: ["A","sequential","domain","reduction","transformer","based","on","the","work","by","Stander",",","N.","and","Craig",",","K",":","''","On","the","robustness","of","a","simple","domain","reduction","scheme","for","simulation\u2010based","optimization","''"]
docstr: Adjust the new_bounds and verify that they adhere to global_bounds and minimum_window.
  
  Parameters:
  -----------
  new_bounds : np.array
      The proposed new_bounds that (may) need adjustment.
  
  global_bounds : np.array
      The maximum allowable bounds for each parameter.
  
  Returns:
  --------
  new_bounds : np.array
      The adjusted bounds after enforcing constraints.
docstr_tok: ["Adjust","the","new_bounds","and","verify","that","they","adhere","to","global_bounds","and","minimum_window",".","Parameters",":","--","--","--","--","--","-","new_bounds",":","np.array","The","proposed","new_bounds","that","(","may",")","need","adjustment",".","global_bounds",":","np.array","The","maximum","allowable","bounds","for","each","parameter",".","Returns",":","--","--","--","--","new_bounds",":","np.array","The","adjusted","bounds","after","enforcing","constraints","."]
code: def _trim(
      self, new_bounds: np.array, global_bounds: np.array
  ) -> np.array:
      """
      Adjust the new_bounds and verify that they adhere to global_bounds and minimum_window.
  
      Parameters:
      -----------
      new_bounds : np.array
          The proposed new_bounds that (may) need adjustment.
  
      global_bounds : np.array
          The maximum allowable bounds for each parameter.
  
      Returns:
      --------
      new_bounds : np.array
          The adjusted bounds after enforcing constraints.
      """
  
      # sort bounds
      new_bounds = np.sort(new_bounds)
  
      # Validate each parameter's bounds against the global_bounds
      for i, pbounds in enumerate(new_bounds):
          # If the one of the bounds is outside the global bounds, reset the bound to the global bound
          # This is expected to happen when the window is near the global bounds, no warning is issued
          if pbounds[0] < global_bounds[i, 0]:
              pbounds[0] = global_bounds[i, 0]
  
          if pbounds[1] > global_bounds[i, 1]:
              pbounds[1] = global_bounds[i, 1]
  
          # If a lower bound is greater than the associated global upper bound, reset it to the global lower bound
          if pbounds[0] > global_bounds[i, 1]:
              pbounds[0] = global_bounds[i, 0]
              warn(
                  "\nDomain Reduction Warning:\n"
                  + "A parameter's lower bound is greater than the global upper bound."
                  + "The offensive boundary has been reset."
                  + "Be cautious of subsequent reductions.",
                  stacklevel=2,
              )
  
          # If an upper bound is less than the associated global lower bound, reset it to the global upper bound
          if pbounds[1] < global_bounds[i, 0]:
              pbounds[1] = global_bounds[i, 1]
              warn(
                  "\nDomain Reduction Warning:\n"
                  + "A parameter's lower bound is greater than the global upper bound."
                  + "The offensive boundary has been reset."
                  + "Be cautious of subsequent reductions.",
                  stacklevel=2,
              )
  
      # Adjust new_bounds to ensure they respect the minimum window width for each parameter
      for i, pbounds in enumerate(new_bounds):
          current_window_width = abs(pbounds[0] - pbounds[1])
  
          # If the window width is less than the minimum allowable width, adjust it
          # Note that when minimum_window < width of the global bounds one side always has more space than required
          if current_window_width < self.minimum_window[i]:
              width_deficit = (
                  self.minimum_window[i] - current_window_width
              ) / 2.0
              available_left_space = abs(
                  global_bounds[i, 0] - pbounds[0]
              )
              available_right_space = abs(
                  global_bounds[i, 1] - pbounds[1]
              )
  
              # determine how much to expand on the left and right
              expand_left = min(width_deficit, available_left_space)
              expand_right = min(width_deficit, available_right_space)
  
              # calculate the deficit on each side
              expand_left_deficit = width_deficit - expand_left
              expand_right_deficit = width_deficit - expand_right
  
              # shift the deficit to the side with more space
              adjust_left = expand_left + max(expand_right_deficit, 0)
              adjust_right = expand_right + max(expand_left_deficit, 0)
  
              # adjust the bounds
              pbounds[0] -= adjust_left
              pbounds[1] += adjust_right
  
      return new_bounds
  
file_path: BayesianOptimization/bayes_opt/domain_reduction.py
imports: from typing import Optional, Union, List
  import numpy
  from .target_space import TargetSpace
  from warnings import warn
label_desc: Use image node_id 4 for calling the SequentialDomainReductionTransformer obj's underlying member method code with example usage: obj._trim(new_bounds, global_bounds) and returns: new_bounds