Total Complexity | 6 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # Author: Simon Blanke |
||
2 | # Email: [email protected] |
||
3 | # License: MIT License |
||
4 | |||
5 | |||
6 | import numpy as np |
||
7 | |||
8 | |||
9 | from ...base_optimizer import BaseOptimizer |
||
10 | from ...base_positioner import BasePositioner |
||
11 | |||
12 | |||
13 | class SBOM(BaseOptimizer): |
||
14 | def __init__(self, _opt_args_): |
||
15 | super().__init__(_opt_args_) |
||
16 | self.n_positioners = 1 |
||
17 | |||
18 | def _all_possible_pos(self, cand): |
||
19 | pos_space = [] |
||
20 | for dim_ in cand._space_.dim: |
||
21 | pos_space.append(np.arange(dim_ + 1)) |
||
22 | |||
23 | self.n_dim = len(pos_space) |
||
24 | self.all_pos_comb = np.array(np.meshgrid(*pos_space)).T.reshape(-1, self.n_dim) |
||
25 | |||
26 | def _init_iteration(self, _cand_): |
||
27 | p = SbomPositioner() |
||
28 | p.move_random(_cand_) |
||
29 | |||
30 | self._optimizer_eval(_cand_, p) |
||
31 | self._update_pos(_cand_, p) |
||
32 | |||
33 | self._all_possible_pos(_cand_) |
||
34 | |||
35 | if self._opt_args_.warm_start_smbo: |
||
36 | self.X_sample = _cand_.mem._get_para() |
||
37 | self.Y_sample = _cand_.mem._get_score() |
||
38 | else: |
||
39 | self.X_sample = _cand_.pos_best.reshape(1, -1) |
||
40 | self.Y_sample = np.array(_cand_.score_best).reshape(1, -1) |
||
41 | |||
42 | return p |
||
43 | |||
44 | |||
45 | class SbomPositioner(BasePositioner): |
||
46 | def __init__(self, *args, **kwargs): |
||
47 | super().__init__(*args, **kwargs) |
||
48 |