Passed
Push — master ( a45661...26ba2e )
by Simon
01:37
created

hyperactive.verb   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 26
eloc 71
dl 0
loc 109
rs 10
c 0
b 0
f 0

26 Methods

Rating   Name   Duplication   Size   Complexity  
A Verbosity.update_p_bar() 0 2 1
A Verbosity.init_p_bar() 0 2 1
A Verbosity.close_p_bar() 0 2 1
A VerbosityLVL1.warm_start() 0 2 1
A VerbosityLVL1.__init__() 0 2 1
A VerbosityLVL2.update_p_bar() 0 2 1
A VerbosityLVL3.__init__() 0 2 1
A Verbosity.no_meta_data() 0 2 1
A VerbosityLVL1.print_start_point() 0 6 1
A VerbosityLVL1.scatter_start() 0 2 1
A VerbosityLVL2.__init__() 0 2 1
A VerbosityLVL1.load_meta_data() 0 2 1
A VerbosityLVL1.random_start() 0 2 1
A VerbosityLVL2._tqdm_dict() 0 10 1
A Verbosity.load_samples() 0 2 1
A Verbosity.load_meta_data() 0 2 1
A VerbosityLVL1.no_meta_data() 0 2 1
A VerbosityLVL2.init_p_bar() 0 2 1
A VerbosityLVL0.__init__() 0 2 1
A Verbosity.random_start() 0 2 1
A VerbosityLVL0.print_start_point() 0 2 1
A VerbosityLVL1.load_samples() 0 2 1
A VerbosityLVL3.update_p_bar() 0 4 1
A Verbosity.warm_start() 0 2 1
A Verbosity.scatter_start() 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_p_bar(self, _cand_, _core_):
10
        pass
11
12
    def update_p_bar(self, n, _cand_):
13
        pass
14
15
    def close_p_bar(self):
16
        pass
17
18
    def warm_start(self):
19
        pass
20
21
    def scatter_start(self):
22
        pass
23
24
    def random_start(self):
25
        pass
26
27
    def load_meta_data(self):
28
        pass
29
30
    def no_meta_data(self):
31
        pass
32
33
    def load_samples(self, para):
34
        pass
35
36
37
class VerbosityLVL0(Verbosity):
38
    def __init__(self):
39
        pass
40
41
    def print_start_point(self, _cand_):
42
        return _cand_._get_warm_start()
43
44
45
class VerbosityLVL1(VerbosityLVL0):
46
    def __init__(self):
47
        pass
48
49
    def print_start_point(self, _cand_):
50
        start_point = _cand_._get_warm_start()
51
        print("best para =", start_point)
52
        print("score     =", _cand_.score_best, "\n")
53
54
        return start_point
55
56
    def warm_start(self):
57
        print("Set warm start")
58
59
    def scatter_start(self):
60
        print("Set scatter init")
61
62
    def random_start(self):
63
        print("Set random start position")
64
65
    def load_meta_data(self):
66
        print("Loading meta data successful", end="\r")
67
68
    def no_meta_data(self, model_func):
69
        print("No meta data found for", model_func.__name__, "function")
70
71
    def load_samples(self, para):
72
        print("Loading meta data successful:", len(para), "samples found")
73
74
75
class VerbosityLVL2(VerbosityLVL1):
76
    def __init__(self):
77
        self.best_since_iter = 0
78
79
    def init_p_bar(self, _cand_, _core_):
80
        self.p_bar = tqdm(**self._tqdm_dict(_cand_, _core_))
81
82
    def update_p_bar(self, n, _cand_):
83
        self.p_bar.update(n)
84
85
    def close_p_bar(self):
86
        self.p_bar.close()
87
88
    def _tqdm_dict(self, _cand_, _core_):
89
        """Generates the parameter dict for tqdm in the iteration-loop of each optimizer"""
90
        return {
91
            "total": _core_.n_iter,
92
            "desc": "Thread "
93
            + str(_cand_.nth_process)
94
            + " -> "
95
            + _cand_._model_.func_.__name__,
96
            "position": _cand_.nth_process,
97
            "leave": True,
98
        }
99
100
101
class VerbosityLVL3(VerbosityLVL2):
102
    def __init__(self):
103
        self.best_since_iter = 0
104
105
    def update_p_bar(self, n, _cand_):
106
        self.p_bar.update(n)
107
        self.p_bar.set_postfix(
108
            best_score=str(_cand_.score_best), best_since_iter=self.best_since_iter
109
        )
110