| Total Complexity | 7 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # Author: Simon Blanke |
||
| 2 | # Email: [email protected] |
||
| 3 | # License: MIT License |
||
| 4 | |||
| 5 | import numpy as np |
||
| 6 | |||
| 7 | |||
| 8 | class BasePositioner: |
||
| 9 | def __init__(self, *args, **kwargs): |
||
| 10 | self._pos_new = None |
||
| 11 | self._score_new = -np.inf |
||
| 12 | |||
| 13 | self.pos_current = None |
||
| 14 | self.score_current = -np.inf |
||
| 15 | |||
| 16 | self.pos_best = None |
||
| 17 | self.score_best = -np.inf |
||
| 18 | |||
| 19 | self.pos_new_list = [] |
||
| 20 | self.score_new_list = [] |
||
| 21 | |||
| 22 | @property |
||
| 23 | def pos_new(self): |
||
| 24 | return self._pos_new |
||
| 25 | |||
| 26 | @pos_new.setter |
||
| 27 | def pos_new(self, value): |
||
| 28 | self.pos_new_list.append(value) |
||
| 29 | self._pos_new = value |
||
| 30 | |||
| 31 | @property |
||
| 32 | def score_new(self): |
||
| 33 | return self._score_new |
||
| 34 | |||
| 35 | @score_new.setter |
||
| 36 | def score_new(self, value): |
||
| 37 | self.score_new_list.append(value) |
||
| 38 | self._score_new = value |
||
| 39 | |||
| 40 | def move_climb(self, _cand_, pos, epsilon_mod=1): |
||
| 41 | sigma = 3 + _cand_._space_.dim * self.epsilon * epsilon_mod |
||
| 42 | pos_normal = self.climb_dist(pos, sigma, pos.shape) |
||
| 43 | pos_new_int = np.rint(pos_normal) |
||
| 44 | |||
| 45 | n_zeros = [0] * len(_cand_._space_.dim) |
||
| 46 | pos = np.clip(pos_new_int, n_zeros, _cand_._space_.dim) |
||
| 47 | |||
| 48 | return pos.astype(int) |
||
| 49 | |||
| 50 | def move_random(self, _cand_): |
||
| 51 | return _cand_._space_.get_random_pos() |
||
| 52 |