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
|
|
|
_tags = { |
10
|
|
|
"object_type": "experiment", |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
def __init__(self): |
14
|
|
|
super().__init__() |
15
|
|
|
|
16
|
|
|
def __call__(self, **kwargs): |
17
|
|
|
"""Score parameters, with kwargs call.""" |
18
|
|
|
score, _ = self.score(kwargs) |
19
|
|
|
return score |
20
|
|
|
|
21
|
|
|
@property |
22
|
|
|
def __name__(self): |
23
|
|
|
return type(self).__name__ |
24
|
|
|
|
25
|
|
|
def paramnames(self): |
26
|
|
|
"""Return the parameter names of the search. |
27
|
|
|
|
28
|
|
|
Returns |
29
|
|
|
------- |
30
|
|
|
list of str |
31
|
|
|
The parameter names of the search parameters. |
32
|
|
|
""" |
33
|
|
|
return self._paramnames() |
34
|
|
|
|
35
|
|
|
def _paramnames(self): |
36
|
|
|
"""Return the parameter names of the search. |
37
|
|
|
|
38
|
|
|
Returns |
39
|
|
|
------- |
40
|
|
|
list of str |
41
|
|
|
The parameter names of the search parameters. |
42
|
|
|
""" |
43
|
|
|
raise NotImplementedError |
44
|
|
|
|
45
|
|
|
def score(self, params): |
46
|
|
|
"""Score the parameters. |
47
|
|
|
|
48
|
|
|
Parameters |
49
|
|
|
---------- |
50
|
|
|
params : dict with string keys |
51
|
|
|
Parameters to score. |
52
|
|
|
|
53
|
|
|
Returns |
54
|
|
|
------- |
55
|
|
|
float |
56
|
|
|
The score of the parameters. |
57
|
|
|
dict |
58
|
|
|
Additional metadata about the search. |
59
|
|
|
""" |
60
|
|
|
paramnames = self.paramnames() |
61
|
|
|
if not set(params.keys()) <= set(paramnames): |
62
|
|
|
raise ValueError("Parameters do not match.") |
63
|
|
|
return self._score(params) |
64
|
|
|
|
65
|
|
|
def _score(self, params): |
66
|
|
|
"""Score the parameters. |
67
|
|
|
|
68
|
|
|
Parameters |
69
|
|
|
---------- |
70
|
|
|
params : dict with string keys |
71
|
|
|
Parameters to score. |
72
|
|
|
|
73
|
|
|
Returns |
74
|
|
|
------- |
75
|
|
|
float |
76
|
|
|
The score of the parameters. |
77
|
|
|
dict |
78
|
|
|
Additional metadata about the search. |
79
|
|
|
""" |
80
|
|
|
raise NotImplementedError |
81
|
|
|
|