Passed
Push — master ( 72341c...590175 )
by Simon
01:52
created

hyperactive.verb   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 13
eloc 44
dl 0
loc 68
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A VerbosityLVL1.__init__() 0 2 1
A VerbosityLVL2.update_p_bar() 0 4 1
A Verbosity.__init__() 0 2 1
A VerbosityLVL1.print_start_point() 0 6 1
A VerbosityLVL2.__init__() 0 2 1
A VerbosityLVL2._tqdm_dict() 0 10 1
A Verbosity.update_p_bar() 0 2 1
A VerbosityLVL2.init_p_bar() 0 2 1
A Verbosity.init_p_bar() 0 2 1
A VerbosityLVL0.__init__() 0 2 1
A VerbosityLVL0.print_start_point() 0 2 1
A Verbosity.close_p_bar() 0 2 1
A VerbosityLVL2.close_p_bar() 0 2 1
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
from tqdm.auto import tqdm
6
7
8
class Verbosity:
9
    def __init__(self):
10
        pass
11
12
    def init_p_bar(self, _cand_, _core_):
13
        pass
14
15
    def update_p_bar(self, n, _cand_):
16
        pass
17
18
    def close_p_bar(self):
19
        pass
20
21
22
class VerbosityLVL0(Verbosity):
23
    def __init__(self):
24
        pass
25
26
    def print_start_point(self, _cand_):
27
        return _cand_._get_warm_start()
28
29
30
class VerbosityLVL1(VerbosityLVL0):
31
    def __init__(self):
32
        pass
33
34
    def print_start_point(self, _cand_):
35
        start_point = _cand_._get_warm_start()
36
        print("\nbest para =", start_point)
37
        print("score     =", _cand_.score_best)
38
39
        return start_point
40
41
42
class VerbosityLVL2(VerbosityLVL1):
43
    def __init__(self):
44
        self.best_since_iter = 0
45
46
    def init_p_bar(self, _cand_, _core_):
47
        self.p_bar = tqdm(**self._tqdm_dict(_cand_, _core_))
48
49
    def update_p_bar(self, n, _cand_):
50
        self.p_bar.update(n)
51
        self.p_bar.set_postfix(
52
            best_score=str(_cand_.score_best), best_since_iter=self.best_since_iter
53
        )
54
55
    def close_p_bar(self):
56
        self.p_bar.close()
57
58
    def _tqdm_dict(self, _cand_, _core_):
59
        """Generates the parameter dict for tqdm in the iteration-loop of each optimizer"""
60
        return {
61
            "total": _core_.n_iter,
62
            "desc": "Thread "
63
            + str(_cand_.nth_process)
64
            + " -> "
65
            + _cand_._model_.func_.__name__,
66
            "position": _cand_.nth_process,
67
            "leave": True,
68
        }
69