Conditions | 5 |
Total Lines | 55 |
Code Lines | 43 |
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, p_bar): |
||
112 | self._setup_process() |
||
113 | |||
114 | memory_warm_start = self.hg_conv.conv_memory_warm_start(self.memory_warm_start) |
||
115 | |||
116 | self.experiment.backend_adapter(ObjectiveFunction, self.s_space) |
||
117 | |||
118 | self.gfo_optimizer.init_search( |
||
119 | self.experiment.gfo_objective_function, |
||
120 | self.n_iter, |
||
121 | self.max_time, |
||
122 | self.max_score, |
||
123 | self.early_stopping, |
||
124 | self.memory, |
||
125 | memory_warm_start, |
||
126 | False, |
||
127 | ) |
||
128 | for nth_iter in range(self.n_iter): |
||
129 | if p_bar: |
||
130 | p_bar.set_description( |
||
131 | "[" |
||
132 | + str(self.nth_process) |
||
133 | + "] " |
||
134 | + str(self.experiment.__class__.__name__) |
||
135 | + " (" |
||
136 | + self.optimizer_class.name |
||
137 | + ")", |
||
138 | ) |
||
139 | |||
140 | self.gfo_optimizer.search_step(nth_iter) |
||
141 | if self.gfo_optimizer.stop.check(): |
||
142 | break |
||
143 | |||
144 | if p_bar: |
||
145 | p_bar.set_postfix( |
||
146 | best_score=str(self.gfo_optimizer.score_best), |
||
147 | best_pos=str(self.gfo_optimizer.pos_best), |
||
148 | best_iter=str(self.gfo_optimizer.p_bar._best_since_iter), |
||
149 | ) |
||
150 | |||
151 | p_bar.update(1) |
||
152 | p_bar.refresh() |
||
153 | |||
154 | self.gfo_optimizer.finish_search() |
||
155 | |||
156 | self.convert_results2hyper() |
||
157 | |||
158 | self._add_result_attributes( |
||
159 | self.best_para, |
||
160 | self.best_score, |
||
161 | self.gfo_optimizer.p_bar._best_since_iter, |
||
162 | self.eval_times, |
||
163 | self.iter_times, |
||
164 | self.search_data, |
||
165 | self.gfo_optimizer.random_seed, |
||
166 | ) |
||
167 |