@@ -82,7 +82,7 @@ def __init__(
8282 self .target_func = target_func
8383
8484 # Get the name of the parameters
85- self ._keys : list [str ] = sorted (pbounds )
85+ self ._keys : list [str ] = list (pbounds . keys () )
8686
8787 self ._params_config = self .make_params (pbounds )
8888 self ._dim = sum ([self ._params_config [key ].dim for key in self ._keys ])
@@ -180,6 +180,11 @@ def keys(self) -> list[str]:
180180 """
181181 return self ._keys
182182
183+ @property
184+ def params_config (self ) -> dict [str , BayesParameter ]:
185+ """Get the parameters configuration."""
186+ return self ._params_config
187+
183188 @property
184189 def bounds (self ) -> NDArray [Float ]:
185190 """Get the bounds of this TargetSpace.
@@ -210,6 +215,20 @@ def masks(self) -> dict[str, NDArray[np.bool_]]:
210215 """
211216 return self ._masks
212217
218+ @property
219+ def continuous_dimensions (self ) -> NDArray [np .bool_ ]:
220+ """Get the continuous parameters.
221+
222+ Returns
223+ -------
224+ dict
225+ """
226+ result = np .zeros (self .dim , dtype = bool )
227+ masks = self .masks
228+ for key in self .keys :
229+ result [masks [key ]] = self ._params_config [key ].is_continuous
230+ return result
231+
213232 def make_params (self , pbounds : BoundsMapping ) -> dict [str , BayesParameter ]:
214233 """Create a dictionary of parameters from a dictionary of bounds.
215234
@@ -226,7 +245,7 @@ def make_params(self, pbounds: BoundsMapping) -> dict[str, BayesParameter]:
226245 parameter objects as values.
227246 """
228247 params : dict [str , BayesParameter ] = {}
229- for key in sorted ( pbounds ) :
248+ for key in pbounds :
230249 pbound = pbounds [key ]
231250
232251 if isinstance (pbound , BayesParameter ):
@@ -285,8 +304,7 @@ def params_to_array(self, params: Mapping[str, float | NDArray[Float]]) -> NDArr
285304 """
286305 if set (params ) != set (self .keys ):
287306 error_msg = (
288- f"Parameters' keys ({ sorted (params )} ) do "
289- f"not match the expected set of keys ({ self .keys } )."
307+ f"Parameters' keys ({ params } ) do " f"not match the expected set of keys ({ self .keys } )."
290308 )
291309 raise ValueError (error_msg )
292310 return self ._to_float (params )
@@ -337,9 +355,7 @@ def array_to_params(self, x: NDArray[Float]) -> dict[str, float | NDArray[Float]
337355
338356 def _to_float (self , value : Mapping [str , float | NDArray [Float ]]) -> NDArray [Float ]:
339357 if set (value ) != set (self .keys ):
340- msg = (
341- f"Parameters' keys ({ sorted (value )} ) do " f"not match the expected set of keys ({ self .keys } )."
342- )
358+ msg = f"Parameters' keys ({ value } ) do " f"not match the expected set of keys ({ self .keys } )."
343359 raise ValueError (msg )
344360 res = np .zeros (self ._dim )
345361 for key in self ._keys :
@@ -389,8 +405,7 @@ def _as_array(self, x: Any) -> NDArray[Float]:
389405 x = x .ravel ()
390406 if x .size != self .dim :
391407 error_msg = (
392- f"Size of array ({ len (x )} ) is different than the "
393- f"expected number of parameters ({ len (self .keys )} )."
408+ f"Size of array ({ len (x )} ) is different than the " f"expected number of ({ len (self .dim )} )."
394409 )
395410 raise ValueError (error_msg )
396411 return x
@@ -666,8 +681,7 @@ def set_bounds(self, new_bounds: BoundsMapping) -> None:
666681 new_bounds : dict
667682 A dictionary with the parameter name and its new bounds
668683 """
669- print (new_bounds )
670- new__params_config = self .make_params (new_bounds )
684+ new_params_config = self .make_params (new_bounds )
671685
672686 for key in self .keys :
673687 if key in new_bounds :
@@ -676,12 +690,12 @@ def set_bounds(self, new_bounds: BoundsMapping) -> None:
676690 ) == set (new_bounds [key ]):
677691 msg = "Changing bounds of categorical parameters is not supported"
678692 raise NotImplementedError (msg )
679- if not isinstance (new__params_config [key ], type (self ._params_config [key ])):
693+ if not isinstance (new_params_config [key ], type (self ._params_config [key ])):
680694 msg = (
681- f"Parameter type { type (new__params_config [key ])} of"
695+ f"Parameter type { type (new_params_config [key ])} of"
682696 " new bounds does not match parameter type"
683697 f" { type (self ._params_config [key ])} of old bounds"
684698 )
685699 raise ValueError (msg )
686- self ._params_config [key ] = new__params_config [key ]
700+ self ._params_config [key ] = new_params_config [key ]
687701 self ._bounds = self .calculate_bounds ()
0 commit comments