Passed
Pull Request — master (#110)
by
unknown
11:00 queued 09:30
created

hyperactive.base._experiment   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 25
dl 0
loc 84
rs 10
c 0
b 0
f 0

7 Methods

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