| Conditions | 6 |
| Total Lines | 62 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # Author: Simon Blanke |
||
| 39 | def __init__(self, nth_process, _main_args_, _info_): |
||
| 40 | self.start_time = time.time() |
||
| 41 | self.i = 0 |
||
| 42 | self._main_args_ = _main_args_ |
||
| 43 | self.memory = _main_args_.memory |
||
| 44 | |||
| 45 | self.memory_dict = {} |
||
| 46 | self.memory_dict_new = {} |
||
| 47 | |||
| 48 | self._info_ = _info_() |
||
| 49 | |||
| 50 | self._score = -np.inf |
||
| 51 | self._pos = None |
||
| 52 | |||
| 53 | self.score_best = -np.inf |
||
| 54 | self.pos_best = None |
||
| 55 | |||
| 56 | self.score_list = [] |
||
| 57 | self.pos_list = [] |
||
| 58 | |||
| 59 | self.nth_process = nth_process |
||
| 60 | model_nr = nth_process % _main_args_.n_models |
||
| 61 | self.func_ = list(_main_args_.search_config.keys())[model_nr] |
||
| 62 | self.search_space = _main_args_.search_config[self.func_] |
||
| 63 | |||
| 64 | self._space_ = SearchSpace(_main_args_, model_nr) |
||
| 65 | self.func_name = str(self.func_).split(" ")[1] |
||
| 66 | self._model_ = Model(self.func_, nth_process, _main_args_) |
||
| 67 | self._init_ = InitSearchPosition(self._space_, self._model_, _main_args_) |
||
| 68 | |||
| 69 | self.eval_time = [] |
||
| 70 | self.iter_times = [] |
||
| 71 | |||
| 72 | if not self.memory: |
||
| 73 | self.mem = None |
||
| 74 | self.eval_pos = self.eval_pos_noMem |
||
| 75 | |||
| 76 | elif self.memory == "short": |
||
| 77 | self.mem = None |
||
| 78 | self.eval_pos = self.eval_pos_Mem |
||
| 79 | |||
| 80 | elif self.memory == "long": |
||
| 81 | self.mem = Hypermemory( |
||
| 82 | _main_args_.X, |
||
| 83 | _main_args_.y, |
||
| 84 | self.func_, |
||
| 85 | self.search_space, |
||
| 86 | path=meta_data_path(), |
||
| 87 | ) |
||
| 88 | self.eval_pos = self.eval_pos_Mem |
||
| 89 | |||
| 90 | self.memory_dict = self.mem.load() |
||
| 91 | |||
| 92 | else: |
||
| 93 | print("Warning: Memory not defined") |
||
| 94 | self.mem = None |
||
| 95 | self.eval_pos = self.eval_pos_noMem |
||
| 96 | |||
| 97 | if self.mem: |
||
| 98 | if self.mem.meta_data_found: |
||
| 99 | self.pos_best = self.mem.pos_best |
||
| 100 | self.score_best = self.mem.score_best |
||
| 101 | |||
| 174 |