Conditions | 6 |
Total Lines | 65 |
Code Lines | 47 |
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_best = -np.inf |
||
51 | self.pos_best = None |
||
52 | self.model = None |
||
53 | |||
54 | self.nth_process = nth_process |
||
55 | model_nr = nth_process % _main_args_.n_models |
||
56 | self.func_ = list(_main_args_.search_config.keys())[model_nr] |
||
57 | self.search_space = _main_args_.search_config[self.func_] |
||
58 | |||
59 | self._space_ = SearchSpace(_main_args_, model_nr) |
||
60 | self.func_name = str(self.func_).split(" ")[1] |
||
61 | self._model_ = Model(self.func_, nth_process, _main_args_) |
||
62 | self._init_ = InitSearchPosition(self._space_, self._model_, _main_args_) |
||
63 | |||
64 | self.eval_time = [] |
||
65 | self.iter_times = [] |
||
66 | |||
67 | if not self.memory: |
||
68 | self.mem = None |
||
69 | self.eval_pos = self.eval_pos_noMem |
||
70 | |||
71 | self._init_eval() |
||
72 | |||
73 | elif self.memory == "short": |
||
74 | self.mem = None |
||
75 | self.eval_pos = self.eval_pos_Mem |
||
76 | |||
77 | self._init_eval() |
||
78 | |||
79 | elif self.memory == "long": |
||
80 | self.mem = Hypermemory( |
||
81 | _main_args_.X, |
||
82 | _main_args_.y, |
||
83 | self.func_, |
||
84 | self.search_space, |
||
85 | path=meta_data_path(), |
||
86 | ) |
||
87 | self.eval_pos = self.eval_pos_Mem |
||
88 | |||
89 | self.memory_dict = self.mem.load() |
||
90 | |||
91 | else: |
||
92 | print("Warning: Memory not defined") |
||
93 | self.mem = None |
||
94 | self.eval_pos = self.eval_pos_noMem |
||
95 | |||
96 | self._init_eval() |
||
97 | |||
98 | if self.mem: |
||
99 | if self.mem.meta_data_found: |
||
100 | self.pos_best = self.mem.pos_best |
||
101 | self.score_best = self.mem.score_best |
||
102 | else: |
||
103 | self._init_eval() |
||
104 | |||
154 |