Conditions | 5 |
Total Lines | 64 |
Code Lines | 49 |
Lines | 64 |
Ratio | 100 % |
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 |
||
115 | View Code Duplication | def _search(self, p_bar): |
|
116 | self._setup_process() |
||
117 | |||
118 | gfo_wrapper_model = ObjectiveFunction( |
||
119 | objective_function=self.experiment.objective_function, |
||
120 | callbacks=self.callbacks, |
||
121 | catch=self.catch, |
||
122 | ) |
||
123 | gfo_wrapper_model.pass_through = self.pass_through |
||
124 | |||
125 | memory_warm_start = self.hg_conv.conv_memory_warm_start( |
||
126 | self.memory_warm_start |
||
127 | ) |
||
128 | |||
129 | gfo_objective_function = gfo_wrapper_model(self.s_space()) |
||
130 | |||
131 | self.gfo_optimizer.init_search( |
||
132 | gfo_objective_function, |
||
133 | self.n_iter, |
||
134 | self.max_time, |
||
135 | self.max_score, |
||
136 | self.early_stopping, |
||
137 | self.memory, |
||
138 | memory_warm_start, |
||
139 | False, |
||
140 | ) |
||
141 | for nth_iter in range(self.n_iter): |
||
142 | if p_bar: |
||
143 | p_bar.set_description( |
||
144 | "[" |
||
145 | + str(self.nth_process) |
||
146 | + "] " |
||
147 | + str(self.experiment.__class__.__name__) |
||
148 | + " (" |
||
149 | + self.optimizer_class.name |
||
150 | + ")", |
||
151 | ) |
||
152 | |||
153 | self.gfo_optimizer.search_step(nth_iter) |
||
154 | if self.gfo_optimizer.stop.check(): |
||
155 | break |
||
156 | |||
157 | if p_bar: |
||
158 | p_bar.set_postfix( |
||
159 | best_score=str(self.gfo_optimizer.score_best), |
||
160 | best_pos=str(self.gfo_optimizer.pos_best), |
||
161 | best_iter=str(self.gfo_optimizer.p_bar._best_since_iter), |
||
162 | ) |
||
163 | |||
164 | p_bar.update(1) |
||
165 | p_bar.refresh() |
||
166 | |||
167 | self.gfo_optimizer.finish_search() |
||
168 | |||
169 | self.convert_results2hyper() |
||
170 | |||
171 | self._add_result_attributes( |
||
172 | self.best_para, |
||
173 | self.best_score, |
||
174 | self.gfo_optimizer.p_bar._best_since_iter, |
||
175 | self.eval_times, |
||
176 | self.iter_times, |
||
177 | self.search_data, |
||
178 | self.gfo_optimizer.random_seed, |
||
179 | ) |
||
180 |