gradient_free_optimizers.optimizers.base_optimizer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 27
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A BaseOptimizer.finish_initialization() 0 2 1
A BaseOptimizer.__init__() 0 19 1
A BaseOptimizer.evaluate() 0 7 2
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
6
from .core_optimizer import CoreOptimizer
7
8
9
class BaseOptimizer(CoreOptimizer):
10
    def __init__(
11
        self,
12
        search_space,
13
        initialize={"grid": 4, "random": 2, "vertices": 4},
14
        constraints=[],
15
        random_state=None,
16
        rand_rest_p=0,
17
        nth_process=None,
18
    ):
19
        super().__init__(
20
            search_space=search_space,
21
            initialize=initialize,
22
            constraints=constraints,
23
            random_state=random_state,
24
            rand_rest_p=rand_rest_p,
25
            nth_process=nth_process,
26
        )
27
28
        self.optimizers = [self]
29
30
    def finish_initialization(self):
31
        self.search_state = "iter"
32
33
    def evaluate(self, score_new):
34
        if self.pos_best is None:
35
            self.pos_best = self.pos_new
36
            self.pos_current = self.pos_new
37
38
            self.score_best = score_new
39
            self.score_current = score_new
40