Conditions | 5 |
Total Lines | 68 |
Code Lines | 52 |
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 |
||
111 | def search(self, nth_process, p_bar): |
||
112 | self._setup_process(nth_process) |
||
113 | |||
114 | gfo_wrapper_model = ObjectiveFunction( |
||
115 | objective_function=self.objective_function, |
||
116 | optimizer=self.gfo_optimizer, |
||
117 | callbacks=self.callbacks, |
||
118 | catch=self.catch, |
||
119 | nth_process=self.nth_process, |
||
120 | ) |
||
121 | gfo_wrapper_model.pass_through = self.pass_through |
||
122 | |||
123 | memory_warm_start = self.hg_conv.conv_memory_warm_start( |
||
124 | self.memory_warm_start |
||
125 | ) |
||
126 | |||
127 | gfo_objective_function = gfo_wrapper_model(self.s_space()) |
||
128 | |||
129 | self.gfo_optimizer.init_search( |
||
130 | gfo_objective_function, |
||
131 | self.n_iter, |
||
132 | self.max_time, |
||
133 | self.max_score, |
||
134 | self.early_stopping, |
||
135 | self.memory, |
||
136 | memory_warm_start, |
||
137 | False, |
||
138 | ) |
||
139 | for nth_iter in range(self.n_iter): |
||
140 | if p_bar: |
||
141 | p_bar.set_description( |
||
142 | "[" |
||
143 | + str(nth_process) |
||
144 | + "] " |
||
145 | + str(self.objective_function.__name__) |
||
146 | + " (" |
||
147 | + self.optimizer_class.name |
||
148 | + ")", |
||
149 | ) |
||
150 | |||
151 | self.gfo_optimizer.search_step(nth_iter) |
||
152 | if self.gfo_optimizer.stop.check(): |
||
153 | break |
||
154 | |||
155 | if p_bar: |
||
156 | p_bar.set_postfix( |
||
157 | best_score=str(gfo_wrapper_model.optimizer.score_best), |
||
158 | best_pos=str(gfo_wrapper_model.optimizer.pos_best), |
||
159 | best_iter=str( |
||
160 | gfo_wrapper_model.optimizer.p_bar._best_since_iter |
||
161 | ), |
||
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 |