Passed
Push — master ( be0089...415349 )
by Simon
01:18
created

SBOM.__init__()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 3
dl 0
loc 2
rs 10
c 0
b 0
f 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, _main_args_, _opt_args_):
15
        super().__init__(_main_args_, _opt_args_)
16
17
    def _all_possible_pos(self, cand):
18
        pos_space = []
19
        for dim_ in cand._space_.dim:
20
            pos_space.append(np.arange(dim_ + 1))
21
22
        self.n_dim = len(pos_space)
23
        self.all_pos_comb = np.array(np.meshgrid(*pos_space)).T.reshape(-1, self.n_dim)
24
25
    def _init_opt_positioner(self, _cand_):
26
        _p_ = SbomPositioner()
27
28
        self._all_possible_pos(_cand_)
29
30
        if self._opt_args_.warm_start_smbo:
31
            self.X_sample = _cand_.mem._get_para()
32
            self.Y_sample = _cand_.mem._get_score()
33
        else:
34
            self.X_sample = _cand_.pos_best.reshape(1, -1)
35
            self.Y_sample = np.array(_cand_.score_best).reshape(1, -1)
36
37
        _p_.pos_current = _cand_.pos_best
38
        _p_.score_current = _cand_.score_best
39
40
        return _p_
41
42
43
class SbomPositioner(BasePositioner):
44
    def __init__(self, *args, **kwargs):
45
        super().__init__(*args, **kwargs)
46