| Total Complexity | 11 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # Author: Simon Blanke |
||
| 2 | # Email: [email protected] |
||
| 3 | # License: MIT License |
||
| 4 | |||
| 5 | import numpy as np |
||
| 6 | from tqdm.auto import tqdm |
||
| 7 | |||
| 8 | |||
| 9 | class ProgressBarLVL0: |
||
| 10 | def __init__(self): |
||
| 11 | pass |
||
| 12 | |||
| 13 | def init(self, nth_process, n_iter, obj_func): |
||
| 14 | pass |
||
| 15 | |||
| 16 | def update(self, iter, score_new): |
||
| 17 | pass |
||
| 18 | |||
| 19 | def close(self): |
||
| 20 | pass |
||
| 21 | |||
| 22 | def _tqdm_dict(self, nth_process, n_iter, obj_func): |
||
| 23 | pass |
||
| 24 | |||
| 25 | |||
| 26 | class ProgressBarLVL1: |
||
| 27 | def __init__(self): |
||
| 28 | self.best_since_iter = 0 |
||
| 29 | self.score_best = -np.inf |
||
| 30 | # tqdm.set_lock(tqdm.get_lock()) |
||
| 31 | |||
| 32 | def init(self, nth_process, n_iter, obj_func): |
||
| 33 | self._tqdm = tqdm(**self._tqdm_dict(nth_process, n_iter, obj_func)) |
||
| 34 | |||
| 35 | def update(self, iter, score_new): |
||
| 36 | self._tqdm.update(iter) |
||
| 37 | |||
| 38 | if score_new > self.score_best: |
||
| 39 | self.score_best = score_new |
||
| 40 | self.best_since_iter = self._tqdm.n |
||
| 41 | self._tqdm.set_postfix( |
||
| 42 | best_score=str(score_new), best_since_iter=self.best_since_iter |
||
| 43 | ) |
||
| 44 | |||
| 45 | def close(self): |
||
| 46 | self._tqdm.close() |
||
| 47 | |||
| 48 | def _tqdm_dict(self, nth_process, n_iter, obj_func): |
||
| 49 | """Generates the parameter dict for tqdm in the iteration-loop of each optimizer""" |
||
| 50 | return { |
||
| 51 | "total": n_iter, |
||
| 52 | "desc": "Process " + str(nth_process) + " -> " + obj_func.__name__, |
||
| 53 | "position": nth_process, |
||
| 54 | "leave": True, |
||
| 55 | } |
||
| 57 |