Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _init_base_positioner(self, _cand_, positioner=None):
if positioner:
_p_ = positioner(self._opt_args_)
else:
_p_ = BasePositioner(self._opt_args_)
_p_.pos_new = _cand_.pos_best
_p_.score_new = _cand_.score_best
return _p_
self._update_pos(_cand_, self.p_list[0])
def _iterate(self, i, _cand_):
self._hill_climb_iter(i, _cand_)
def _init_iteration(self, _cand_):
p = super()._init_base_positioner(_cand_, positioner=HillClimbingPositioner)
self._optimizer_eval(_cand_, p)
self._update_pos(_cand_, p)
return p
class HillClimbingPositioner(BasePositioner):
def __init__(self, _opt_args_):
super().__init__(_opt_args_)
self.epsilon = _opt_args_.epsilon
self.distribution = _opt_args_.distribution
self._optimizer_eval(_cand_, p)
self._update_pos(_cand_, p)
self._all_possible_pos(_cand_)
if self._opt_args_.warm_start_smbo:
self.X_sample = _cand_.mem._get_para()
self.Y_sample = _cand_.mem._get_score()
else:
self.X_sample = _cand_.pos_best.reshape(1, -1)
self.Y_sample = np.array(_cand_.score_best).reshape(1, -1)
return p
class SbomPositioner(BasePositioner):
def __init__(self, _opt_args_):
super().__init__(_opt_args_)
self._optimizer_eval(_cand_, _p_current)
self._update_pos(_cand_, _p_current)
return _cand_
def _init_iteration(self, _cand_):
p = self._init_particle(_cand_)
self._optimizer_eval(_cand_, p)
self._update_pos(_cand_, p)
return p
class Particle(BasePositioner):
def __init__(self):
super().__init__(self)
self.velo = None
def move_part(self, _cand_, pos):
pos_new = (pos + self.velo).astype(int)
# limit movement
n_zeros = [0] * len(_cand_._space_.dim)
self.pos_new = np.clip(pos_new, n_zeros, _cand_._space_.dim)