@@ -68,6 +68,9 @@ def initialize(self, target_space: TargetSpace) -> None:
6868
6969 self .r = self .contraction_rate * self .r
7070
71+ # check if the minimum window fits in the orignal bounds
72+ self ._window_bounds_compatiblity (self .original_bounds )
73+
7174 def _update (self , target_space : TargetSpace ) -> None :
7275
7376 # setting the previous
@@ -105,11 +108,27 @@ def _trim(self, new_bounds: np.array, global_bounds: np.array) -> np.array:
105108 new_bounds [i , 1 ] = entry [0 ]
106109 window_width = abs (entry [0 ] - entry [1 ])
107110 if window_width < self .minimum_window [i ]:
108- new_bounds [i , 0 ] -= (self .minimum_window [i ] - window_width ) / 2.0
109- new_bounds [i , 1 ] += (self .minimum_window [i ] - window_width ) / 2.0
110-
111+ dw = (self .minimum_window [i ] - window_width ) / 2.0
112+ left_expansion_space = abs (global_bounds [i , 0 ] - entry [0 ]) # should be non-positive
113+ right_expansion_space = abs (global_bounds [i , 1 ] - entry [1 ]) # should be non-negative
114+ # conservative
115+ dw_l = min (dw , left_expansion_space )
116+ dw_r = min (dw , right_expansion_space )
117+ # this crawls towards the edge
118+ ddw_r = dw_r + max (dw - dw_l , 0 )
119+ ddw_l = dw_l + max (dw - dw_r , 0 )
120+ new_bounds [i , 0 ] -= ddw_l
121+ new_bounds [i , 1 ] += ddw_r
111122 return new_bounds
112123
124+ def _window_bounds_compatiblity (self , global_bounds : np .array ) -> bool :
125+ """Checks if global bounds are compatible with the minimum window sizes."""
126+ for i , entry in enumerate (global_bounds ):
127+ global_window_width = abs (entry [1 ] - entry [0 ])
128+ if global_window_width < self .minimum_window [i ]:
129+ raise ValueError (
130+ "Global bounds are not compatible with the minimum window size." )
131+
113132 def _create_bounds (self , parameters : dict , bounds : np .array ) -> dict :
114133 return {param : bounds [i , :] for i , param in enumerate (parameters )}
115134
0 commit comments