| 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 | """Adapter for gfo package.""" |
||
| 58 | @classmethod |
||
| 59 | def get_test_params(cls, parameter_set="default"): |
||
| 60 | """Return testing parameter settings for the skbase object. |
||
| 61 | |||
| 62 | ``get_test_params`` is a unified interface point to store |
||
| 63 | parameter settings for testing purposes. This function is also |
||
| 64 | used in ``create_test_instance`` and ``create_test_instances_and_names`` |
||
| 65 | to construct test instances. |
||
| 66 | |||
| 67 | ``get_test_params`` should return a single ``dict``, or a ``list`` of ``dict``. |
||
| 68 | |||
| 69 | Each ``dict`` is a parameter configuration for testing, |
||
| 70 | and can be used to construct an "interesting" test instance. |
||
| 71 | A call to ``cls(**params)`` should |
||
| 72 | be valid for all dictionaries ``params`` in the return of ``get_test_params``. |
||
| 73 | |||
| 74 | The ``get_test_params`` need not return fixed lists of dictionaries, |
||
| 75 | it can also return dynamic or stochastic parameter settings. |
||
| 76 | |||
| 77 | Parameters |
||
| 78 | ---------- |
||
| 79 | parameter_set : str, default="default" |
||
| 80 | Name of the set of test parameters to return, for use in tests. If no |
||
| 81 | special parameters are defined for a value, will return `"default"` set. |
||
| 82 | |||
| 83 | Returns |
||
| 84 | ------- |
||
| 85 | params : dict or list of dict, default = {} |
||
| 86 | Parameters to create testing instances of the class |
||
| 87 | Each dict are parameters to construct an "interesting" test instance, i.e., |
||
| 88 | `MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance. |
||
| 89 | `create_test_instance` uses the first (or only) dictionary in `params` |
||
| 90 | """ |
||
| 91 | import numpy as np |
||
| 92 | from hyperactive.experiment.integrations import SklearnCvExperiment |
||
| 93 | |||
| 94 | sklearn_exp = SklearnCvExperiment.create_test_instance() |
||
| 95 | params_sklearn = { |
||
| 96 | "experiment": sklearn_exp, |
||
| 97 | "search_space": { |
||
| 98 | "C": np.array([0.01, 0.1, 1, 10]), |
||
| 99 | "gamma": np.array([0.0001, 0.01, 0.1, 1, 10]), |
||
| 100 | }, |
||
| 101 | "n_iter": 100, |
||
| 102 | } |
||
| 103 | |||
| 104 | from hyperactive.experiment.toy import Ackley |
||
| 105 | |||
| 106 | ackley_exp = Ackley.create_test_instance() |
||
| 107 | params_ackley = { |
||
| 108 | "experiment": ackley_exp, |
||
| 109 | "search_space": { |
||
| 110 | "x0": np.linspace(-5, 5, 10), |
||
| 111 | "x1": np.linspace(-5, 5, 10), |
||
| 112 | }, |
||
| 113 | "n_iter": 100, |
||
| 114 | } |
||
| 115 | |||
| 116 | return [params_sklearn, params_ackley] |
||
| 117 |