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