Conditions | 8 |
Total Lines | 62 |
Code Lines | 45 |
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 |
||
62 | def search(self, nth_process, p_bar): |
||
63 | for optimizer_setup in self.optimizer_setup_l: |
||
64 | hyper_opt = optimizer_setup["optimizer"] |
||
65 | duration = optimizer_setup["duration"] |
||
66 | opt_strat_early_stopping = optimizer_setup["early_stopping"] |
||
67 | |||
68 | if opt_strat_early_stopping: |
||
69 | early_stopping = opt_strat_early_stopping |
||
70 | else: |
||
71 | early_stopping = self.early_stopping |
||
72 | |||
73 | n_iter = round(self.n_iter * duration / self.duration_sum) |
||
74 | |||
75 | # initialize |
||
76 | if self.best_para is not None: |
||
77 | initialize = {} |
||
78 | if "warm_start" in initialize: |
||
79 | initialize["warm_start"].append(self.best_para) |
||
80 | else: |
||
81 | initialize["warm_start"] = [self.best_para] |
||
82 | else: |
||
83 | initialize = dict(self.initialize) |
||
84 | |||
85 | # memory_warm_start |
||
86 | if self.search_data is not None: |
||
87 | memory_warm_start = self.search_data |
||
88 | else: |
||
89 | memory_warm_start = self.memory_warm_start |
||
90 | |||
91 | # warm_start_smbo |
||
92 | if ( |
||
93 | hyper_opt.optimizer_class.optimizer_type == "sequential" |
||
94 | and self.search_data is not None |
||
95 | ): |
||
96 | hyper_opt.opt_params["warm_start_smbo"] = self.search_data |
||
97 | |||
98 | hyper_opt.setup_search( |
||
99 | objective_function=self.objective_function, |
||
100 | s_space=self.s_space, |
||
101 | n_iter=n_iter, |
||
102 | initialize=initialize, |
||
103 | pass_through=self.pass_through, |
||
104 | callbacks=self.callbacks, |
||
105 | catch=self.catch, |
||
106 | max_score=self.max_score, |
||
107 | early_stopping=early_stopping, |
||
108 | random_state=self.random_state, |
||
109 | memory=self.memory, |
||
110 | memory_warm_start=memory_warm_start, |
||
111 | verbosity=self.verbosity, |
||
112 | ) |
||
113 | |||
114 | hyper_opt.search(nth_process, p_bar) |
||
115 | |||
116 | self._add_result_attributes( |
||
117 | hyper_opt.best_para, |
||
118 | hyper_opt.best_score, |
||
119 | hyper_opt.best_since_iter, |
||
120 | hyper_opt.eval_times, |
||
121 | hyper_opt.iter_times, |
||
122 | hyper_opt.search_data, |
||
123 | hyper_opt.gfo_optimizer.random_seed, |
||
124 | ) |
||
125 |