Passed
Pull Request — master (#110)
by
unknown
01:27
created

hyperactive.base._experiment   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 73
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A BaseExperiment.__init__() 0 2 1
A BaseExperiment.score() 0 19 2
A BaseExperiment._score() 0 16 1
A BaseExperiment._paramnames() 0 9 1
A BaseExperiment.paramnames() 0 9 1
A BaseExperiment.__call__() 0 4 1
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