Conditions | 1 |
Total Lines | 59 |
Code Lines | 20 |
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 | """Hill climbing optimizer from gfo.""" |
||
148 | @classmethod |
||
149 | def get_test_params(cls, parameter_set="default"): |
||
150 | """Return testing parameter settings for the skbase object. |
||
151 | |||
152 | ``get_test_params`` is a unified interface point to store |
||
153 | parameter settings for testing purposes. This function is also |
||
154 | used in ``create_test_instance`` and ``create_test_instances_and_names`` |
||
155 | to construct test instances. |
||
156 | |||
157 | ``get_test_params`` should return a single ``dict``, or a ``list`` of ``dict``. |
||
158 | |||
159 | Each ``dict`` is a parameter configuration for testing, |
||
160 | and can be used to construct an "interesting" test instance. |
||
161 | A call to ``cls(**params)`` should |
||
162 | be valid for all dictionaries ``params`` in the return of ``get_test_params``. |
||
163 | |||
164 | The ``get_test_params`` need not return fixed lists of dictionaries, |
||
165 | it can also return dynamic or stochastic parameter settings. |
||
166 | |||
167 | Parameters |
||
168 | ---------- |
||
169 | parameter_set : str, default="default" |
||
170 | Name of the set of test parameters to return, for use in tests. If no |
||
171 | special parameters are defined for a value, will return `"default"` set. |
||
172 | |||
173 | Returns |
||
174 | ------- |
||
175 | params : dict or list of dict, default = {} |
||
176 | Parameters to create testing instances of the class |
||
177 | Each dict are parameters to construct an "interesting" test instance, i.e., |
||
178 | `MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance. |
||
179 | `create_test_instance` uses the first (or only) dictionary in `params` |
||
180 | """ |
||
181 | import numpy as np |
||
182 | from hyperactive.experiment.integrations import SklearnCvExperiment |
||
183 | |||
184 | sklearn_exp = SklearnCvExperiment.create_test_instance() |
||
185 | params_sklearn = { |
||
186 | "experiment": sklearn_exp, |
||
187 | "search_space": { |
||
188 | "C": np.array([0.01, 0.1, 1, 10]), |
||
189 | "gamma": np.array([0.0001, 0.01, 0.1, 1, 10]), |
||
190 | }, |
||
191 | "n_iter": 100, |
||
192 | } |
||
193 | |||
194 | from hyperactive.experiment.toy import Ackley |
||
195 | |||
196 | ackley_exp = Ackley.create_test_instance() |
||
197 | params_ackley = { |
||
198 | "experiment": ackley_exp, |
||
199 | "search_space": { |
||
200 | "x0": np.linspace(-5, 5, 10), |
||
201 | "x1": np.linspace(-5, 5, 10), |
||
202 | }, |
||
203 | "n_iter": 100, |
||
204 | } |
||
205 | |||
206 | return [params_sklearn, params_ackley] |
||
207 |