@@ -96,9 +96,9 @@ def __init__(
9696 ):
9797 assert sigma > 0 , "sigma must be non-zero positive value"
9898
99- assert np .all (
100- np . abs ( mean ) < _MEAN_MAX
101- ), f"Abs of all elements of mean vector must be less than { _MEAN_MAX } "
99+ assert np .all (np . abs ( mean ) < _MEAN_MAX ), (
100+ f"Abs of all elements of mean vector must be less than { _MEAN_MAX } "
101+ )
102102
103103 self ._n_co = len (mean )
104104 self ._n_ca = len (cat_num )
@@ -141,12 +141,8 @@ def __init__(
141141
142142 # learning rate for the cumulation for the step-size control
143143 c_sigma = (mu_eff + 2 ) / (self ._n_co + mu_eff + 5 )
144- d_sigma = (
145- 1 + 2 * max (0 , math .sqrt ((mu_eff - 1 ) / (self ._n_co + 1 )) - 1 ) + c_sigma
146- )
147- assert (
148- c_sigma < 1
149- ), "invalid learning rate for cumulation for the step-size control"
144+ d_sigma = 1 + 2 * max (0 , math .sqrt ((mu_eff - 1 ) / (self ._n_co + 1 )) - 1 ) + c_sigma
145+ assert c_sigma < 1 , "invalid learning rate for cumulation for the step-size control"
150146
151147 # learning rate for cumulation for the rank-one update
152148 cc = (4 + mu_eff / self ._n_co ) / (self ._n_co + 4 + 2 * mu_eff / self ._n_co )
@@ -208,18 +204,16 @@ def __init__(
208204 "Parameters in categorical distribution with fewer categories "
209205 "must be zero-padded at the end"
210206 )
211- assert np .all (
212- ( cat_param >= 0 ) & ( cat_param <= 1 )
213- ), "All elements in categorical distribution parameter must be between 0 and 1"
214- assert np .allclose (
215- np . sum ( cat_param , axis = 1 ), 1
216- ), "Each row in categorical distribution parameter must sum to 1"
207+ assert np .all (( cat_param >= 0 ) & ( cat_param <= 1 )), (
208+ "All elements in categorical distribution parameter must be between 0 and 1"
209+ )
210+ assert np .allclose (np . sum ( cat_param , axis = 1 ), 1 ), (
211+ "Each row in categorical distribution parameter must sum to 1"
212+ )
217213 self ._q = cat_param
218214
219215 self ._q_min = (
220- margin
221- if margin is not None
222- else (1 - 0.73 ** (1 / self ._n_ca )) / (self ._K - 1 )
216+ margin if margin is not None else (1 - 0.73 ** (1 / self ._n_ca )) / (self ._K - 1 )
223217 )
224218 self ._min_eigenvalue = min_eigenvalue if min_eigenvalue is not None else 1e-30
225219
@@ -367,16 +361,14 @@ def _repair_infeasible_params(self, param: np.ndarray) -> np.ndarray:
367361 param = np .where (param > self ._bounds [:, 1 ], self ._bounds [:, 1 ], param )
368362 return param
369363
370- def tell (
371- self , solutions : list [tuple [tuple [np .ndarray , np .ndarray ], float ]]
372- ) -> None :
364+ def tell (self , solutions : list [tuple [tuple [np .ndarray , np .ndarray ], float ]]) -> None :
373365 """Tell evaluation values"""
374366
375367 assert len (solutions ) == self ._popsize , "Must tell popsize-length solutions."
376368 for s in solutions :
377- assert np .all (
378- np . abs ( s [ 0 ][ 0 ]) < _MEAN_MAX
379- ), f"Abs of all param values must be less than { _MEAN_MAX } to avoid overflow errors"
369+ assert np .all (np . abs ( s [ 0 ][ 0 ]) < _MEAN_MAX ), (
370+ f"Abs of all param values must be less than { _MEAN_MAX } to avoid overflow errors"
371+ )
380372
381373 self ._g += 1
382374 solutions .sort (key = lambda s : s [1 ])
@@ -406,9 +398,7 @@ def tell(
406398 ) * C_2 .dot (y_w )
407399
408400 norm_p_sigma = np .linalg .norm (self ._p_sigma )
409- self ._sigma *= np .exp (
410- (self ._c_sigma / self ._d_sigma ) * (norm_p_sigma / self ._chi_n - 1 )
411- )
401+ self ._sigma *= np .exp ((self ._c_sigma / self ._d_sigma ) * (norm_p_sigma / self ._chi_n - 1 ))
412402 self ._sigma = min (self ._sigma , _SIGMA_MAX )
413403
414404 # Covariance matrix adaption
@@ -430,13 +420,7 @@ def tell(
430420 np .array ([w * np .outer (y , y ) for w , y in zip (self ._weights , y_k )]), axis = 0
431421 )
432422 self ._C = (
433- (
434- 1
435- + self ._c1 * delta_h_sigma
436- - self ._c1
437- - self ._cmu * np .sum (self ._weights )
438- )
439- * self ._C
423+ (1 + self ._c1 * delta_h_sigma - self ._c1 - self ._cmu * np .sum (self ._weights )) * self ._C
440424 + self ._c1 * rank_one
441425 + self ._cmu * rank_mu
442426 )
@@ -470,9 +454,7 @@ def tell(
470454 beta = self ._delta / (self ._param_sum ** 0.5 )
471455 self ._s = (1 - beta ) * self ._s + np .sqrt (beta * (2 - beta )) * ngrad_sqF / pnorm
472456 self ._gamma = (1 - beta ) ** 2 * self ._gamma + beta * (2 - beta )
473- self ._Delta *= np .exp (
474- beta * (self ._gamma - np .dot (self ._s , self ._s ) / self ._alpha )
475- )
457+ self ._Delta *= np .exp (beta * (self ._gamma - np .dot (self ._s , self ._s ) / self ._alpha ))
476458 self ._Delta = min (self ._Delta , self ._Delta_max )
477459
478460 # Margin Correction
@@ -490,8 +472,7 @@ def should_stop(self) -> bool:
490472 # Stop if the range of function values of the recent generation is below tolfun.
491473 if (
492474 self .generation > self ._funhist_term
493- and np .max (self ._funhist_values ) - np .min (self ._funhist_values )
494- < self ._tolfun
475+ and np .max (self ._funhist_values ) - np .min (self ._funhist_values ) < self ._tolfun
495476 ):
496477 return True
497478
0 commit comments