Conditions | 3 |
Total Lines | 62 |
Code Lines | 48 |
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 |
||
102 | def search(self, nth_process, p_bar): |
||
103 | self._setup_process(nth_process) |
||
104 | |||
105 | gfo_wrapper_model = ObjectiveFunction( |
||
106 | objective_function=self.objective_function, |
||
107 | optimizer=self.gfo_optimizer, |
||
108 | callbacks=self.callbacks, |
||
109 | catch=self.catch, |
||
110 | nth_process=self.nth_process, |
||
111 | ) |
||
112 | gfo_wrapper_model.pass_through = self.pass_through |
||
113 | |||
114 | memory_warm_start = self.hg_conv.conv_memory_warm_start(self.memory_warm_start) |
||
115 | |||
116 | gfo_objective_function = gfo_wrapper_model(self.s_space()) |
||
117 | |||
118 | self.gfo_optimizer.init_search( |
||
119 | 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 | p_bar.set_description( |
||
130 | "[" |
||
131 | + str(nth_process) |
||
132 | + "] " |
||
133 | + str(self.objective_function.__name__) |
||
134 | + " (" |
||
135 | + self.optimizer_class.name |
||
136 | + ")", |
||
137 | ) |
||
138 | |||
139 | self.gfo_optimizer.search_step(nth_iter) |
||
140 | if self.gfo_optimizer.stop.check(): |
||
141 | break |
||
142 | |||
143 | p_bar.set_postfix( |
||
144 | best_score=str(gfo_wrapper_model.optimizer.score_best), |
||
145 | best_pos=str(gfo_wrapper_model.optimizer.pos_best), |
||
146 | best_iter=str(gfo_wrapper_model.optimizer.p_bar._best_since_iter), |
||
147 | ) |
||
148 | |||
149 | p_bar.update(1) |
||
150 | p_bar.refresh() |
||
151 | |||
152 | self.gfo_optimizer.finish_search() |
||
153 | |||
154 | self.convert_results2hyper() |
||
155 | |||
156 | self._add_result_attributes( |
||
157 | self.best_para, |
||
158 | self.best_score, |
||
159 | self.gfo_optimizer.p_bar._best_since_iter, |
||
160 | self.eval_times, |
||
161 | self.iter_times, |
||
162 | self.search_data, |
||
163 | self.gfo_optimizer.random_seed, |
||
164 | ) |
||
165 |