1
|
|
|
"""Base class for experiment.""" |
2
|
|
|
|
3
|
|
|
from skbase.base import BaseObject |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class BaseExperiment(BaseObject): |
7
|
|
|
"""Base class for experiment.""" |
8
|
|
|
|
9
|
|
|
def __init__(self): |
10
|
|
|
super().__init__() |
11
|
|
|
|
12
|
|
|
def __call__(self, **kwargs): |
13
|
|
|
"""Score parameters, with kwargs call.""" |
14
|
|
|
score, _ = self.score(**kwargs) |
15
|
|
|
return score |
16
|
|
|
|
17
|
|
|
def paramnames(self): |
18
|
|
|
"""Return the parameter names of the search. |
19
|
|
|
|
20
|
|
|
Returns |
21
|
|
|
------- |
22
|
|
|
list of str |
23
|
|
|
The parameter names of the search parameters. |
24
|
|
|
""" |
25
|
|
|
return self._paramnames() |
26
|
|
|
|
27
|
|
|
def _paramnames(self): |
28
|
|
|
"""Return the parameter names of the search. |
29
|
|
|
|
30
|
|
|
Returns |
31
|
|
|
------- |
32
|
|
|
list of str |
33
|
|
|
The parameter names of the search parameters. |
34
|
|
|
""" |
35
|
|
|
raise NotImplementedError |
36
|
|
|
|
37
|
|
|
def score(self, **params): |
38
|
|
|
"""Score the parameters. |
39
|
|
|
|
40
|
|
|
Parameters |
41
|
|
|
---------- |
42
|
|
|
params : dict with string keys |
43
|
|
|
Parameters to score. |
44
|
|
|
|
45
|
|
|
Returns |
46
|
|
|
------- |
47
|
|
|
float |
48
|
|
|
The score of the parameters. |
49
|
|
|
dict |
50
|
|
|
Additional metadata about the search. |
51
|
|
|
""" |
52
|
|
|
paramnames = self.paramnames() |
53
|
|
|
if not set(params.keys()) <= set(paramnames): |
54
|
|
|
raise ValueError("Parameters do not match.") |
55
|
|
|
return self._score(**params) |
56
|
|
|
|
57
|
|
|
def _score(self, **params): |
58
|
|
|
"""Score the parameters. |
59
|
|
|
|
60
|
|
|
Parameters |
61
|
|
|
---------- |
62
|
|
|
params : dict with string keys |
63
|
|
|
Parameters to score. |
64
|
|
|
|
65
|
|
|
Returns |
66
|
|
|
------- |
67
|
|
|
float |
68
|
|
|
The score of the parameters. |
69
|
|
|
dict |
70
|
|
|
Additional metadata about the search. |
71
|
|
|
""" |
72
|
|
|
raise NotImplementedError |
73
|
|
|
|