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