3030 es , # pyright: ignore[reportMissingModuleSource]
3131)
3232
33- from .cmaescpp .parameters import ( # pyright: ignore[reportMissingModuleSource]
33+ from .cmaescpp .parameters import ( # pyright: ignore[reportMissingModuleSource]
3434 Settings ,
3535 Modules ,
3636) # pyright: ignore[reportMissingModuleSource]
@@ -47,8 +47,7 @@ def _get_module_options(name: str) -> tuple:
4747 module_class = default_value .__class__
4848 if issubclass (module_class , Enum ):
4949 other_values = [
50- x .name for x in module_class .__members__ .values ()
51- if x is not default_value
50+ x .name for x in module_class .__members__ .values () if x is not default_value
5251 ]
5352 return tuple ([default_value .name ] + other_values )
5453 raise TypeError (f"{ name } has a unparsable type { type (default_value )} " )
@@ -85,10 +84,10 @@ def _make_numeric_parameter(
8584
8685
8786def get_configspace (
88- dim : int = None ,
89- add_popsize : bool = True ,
90- add_sigma : bool = True ,
91- add_learning_rates : bool = True
87+ dim : int = None ,
88+ add_popsize : bool = True ,
89+ add_sigma : bool = True ,
90+ add_learning_rates : bool = True ,
9291) -> ConfigurationSpace :
9392 cspace = ConfigurationSpace ()
9493 for name , options in get_all_module_options ().items ():
@@ -105,17 +104,17 @@ def get_configspace(
105104 cspace .add (_make_numeric_parameter ("lambda0" , dim , 1 , 50 * dim ))
106105 cspace .add (_make_numeric_parameter ("mu0" , dim , 1 , 50 * dim ))
107106 cspace .add (ForbiddenGreaterThanRelation (cspace ["mu0" ], cspace ["lambda0" ]))
108-
107+
109108 if add_sigma :
110109 cspace .add (_make_numeric_parameter ("sigma0" , dim , 1e-15 , 1e15 ))
111-
110+
112111 if add_learning_rates :
113112 cspace .add (_make_numeric_parameter ("cs" , dim , 0 , 1.0 ))
114113 cspace .add (_make_numeric_parameter ("cc" , dim , 0 , 1.0 ))
115114 cspace .add (_make_numeric_parameter ("cmu" , dim , 0 , 1.0 ))
116115 cspace .add (_make_numeric_parameter ("c1" , dim , 0 , 1.0 ))
117116 cspace .add (_make_numeric_parameter ("damps" , dim , 0 , 10.0 ))
118-
117+
119118 return cspace
120119
121120
@@ -126,7 +125,7 @@ def set_module(modules: Modules, name: str, value: Enum) -> bool:
126125 value = getattr (attr_class , value )
127126 setattr (modules , name , value )
128127 return True
129- return False
128+ return False
130129
131130
132131def settings_from_dict (dim : int , ** config : dict ) -> Settings :
@@ -140,11 +139,7 @@ def settings_from_dict(dim: int, **config: dict) -> Settings:
140139 return settings
141140
142141
143- def settings_from_config (
144- dim : int ,
145- config : Configuration ,
146- ** kwargs
147- ) -> Settings :
142+ def settings_from_config (dim : int , config : Configuration , ** kwargs ) -> Settings :
148143 via_settings = kwargs
149144 default_config = get_configspace (dim ).get_default_configuration ()
150145 modules = Modules ()
@@ -157,14 +152,15 @@ def settings_from_config(
157152 settings = Settings (dim , modules , ** via_settings )
158153 return settings
159154
155+
160156def fmin (func : callable , x0 : np .ndarray , sigma0 : float , budget : int , ** kwargs ):
161157 """Minimize a function using the modular CMA-ES.
162158
163159 Parameters
164160 ----------
165161 func: callable
166162 The objective function to be minimized.
167- x0 np.ndarray:
163+ x0 np.ndarray:
168164 The first solution estimate
169165 sigma0: float
170166 The estimate of the stepsize (rule of thumb: 0.3 * (ub - lb))
@@ -187,9 +183,15 @@ def fmin(func: callable, x0: np.ndarray, sigma0: float, budget: int, **kwargs):
187183 settings = settings_from_dict (len (x0 ), sigma0 = sigma0 , budget = budget , ** kwargs )
188184 es = ModularCMAES (settings )
189185 es (func )
190-
191- return es .p .stats .global_best .x , es .p .stats .global_best .y , es .p .stats .evaluations , es
192-
186+
187+ return (
188+ es .p .stats .global_best .x ,
189+ es .p .stats .global_best .y ,
190+ es .p .stats .evaluations ,
191+ es ,
192+ )
193+
194+
193195__all__ = (
194196 "settings_from_config" ,
195197 "get_configspace" ,
0 commit comments