Code Duplication    Length = 66-73 lines in 2 locations

src/hyperactive/experiment/_experiment.py 1 location

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

src_old/hyperactive/base/_experiment.py 1 location

@@ 6-71 (lines=66) @@
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
        return self.score(kwargs)
15
16
    def paramnames(self):
17
        """Return the parameter names of the search.
18
19
        Returns
20
        -------
21
        list of str
22
            The parameter names of the search parameters.
23
        """
24
        return self._paramnames()
25
26
    def _paramnames(self):
27
        """Return the parameter names of the search.
28
29
        Returns
30
        -------
31
        list of str
32
            The parameter names of the search parameters.
33
        """
34
        raise NotImplementedError
35
36
    def score(self, **params):
37
        """Score the parameters.
38
39
        Parameters
40
        ----------
41
        params : dict with string keys
42
            Parameters to score.
43
44
        Returns
45
        -------
46
        float
47
            The score of the parameters.
48
        dict
49
            Additional metadata about the search.
50
        """
51
        paramnames = self.paramnames()
52
        if not set(paramnames) == set(params.keys()):
53
            raise ValueError("Parameters do not match.")
54
        return self._score(**params)
55
56
    def _score(self, **params):
57
        """Score the parameters.
58
59
        Parameters
60
        ----------
61
        params : dict with string keys
62
            Parameters to score.
63
64
        Returns
65
        -------
66
        float
67
            The score of the parameters.
68
        dict
69
            Additional metadata about the search.
70
        """
71
        raise NotImplementedError
72