|
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
|
|
|
|