Code Duplication    Length = 27-71 lines in 6 locations

src/gradient_free_optimizers/optimizer_search/forest_optimization.py 1 location

@@ 11-81 (lines=71) @@
8
from ..optimizers import ForestOptimizer as _ForestOptimizer
9
10
11
class ForestOptimizer(_ForestOptimizer, Search):
12
    """
13
    A class implementing the **forest optimizer** for the public API.
14
    Inheriting from the `Search`-class to get the `search`-method and from
15
    the `ForestOptimizer`-backend to get the underlying algorithm.
16
17
    Parameters
18
    ----------
19
    search_space : dict[str, list]
20
        The search space to explore. A dictionary with parameter
21
        names as keys and a numpy array as values.
22
    initialize : dict[str, int]
23
        The method to generate initial positions. A dictionary with
24
        the following key literals and the corresponding value type:
25
        {"grid": int, "vertices": int, "random": int, "warm_start": list[dict]}
26
    constraints : list[callable]
27
        A list of constraints, where each constraint is a callable.
28
        The callable returns `True` or `False` dependend on the input parameters.
29
    random_state : None, int
30
        If None, create a new random state. If int, create a new random state
31
        seeded with the value.
32
    rand_rest_p : float
33
        The probability of a random iteration during the the search process.
34
    warm_start_smbo
35
        The warm start for SMBO.
36
    max_sample_size : int
37
        The maximum number of points to sample.
38
    sampling : dict
39
        The sampling method to use.
40
    replacement : bool
41
        Whether to sample with replacement.
42
    tree_regressor : str
43
        The tree regressor model to use.
44
    tree_para : dict
45
        The model specific parameters for the tree regressor.
46
    xi : float
47
        The xi parameter for the tree regressor.
48
    """
49
50
    def __init__(
51
        self,
52
        search_space: Dict[str, list],
53
        initialize: Dict[
54
            Literal["grid", "vertices", "random", "warm_start"], int | List
55
        ] = {"grid": 4, "random": 2, "vertices": 4},
56
        constraints: List[callable] = [],
57
        random_state: int = None,
58
        rand_rest_p: float = 0,
59
        nth_process: int = None,
60
        warm_start_smbo=None,
61
        max_sample_size: int = 10000000,
62
        sampling: Dict[Literal["random"], int] = {"random": 1000000},
63
        replacement: bool = True,
64
        tree_regressor="extra_tree",
65
        tree_para={"n_estimators": 100},
66
        xi=0.03,
67
    ):
68
        super().__init__(
69
            search_space=search_space,
70
            initialize=initialize,
71
            constraints=constraints,
72
            random_state=random_state,
73
            rand_rest_p=rand_rest_p,
74
            nth_process=nth_process,
75
            warm_start_smbo=warm_start_smbo,
76
            max_sample_size=max_sample_size,
77
            sampling=sampling,
78
            replacement=replacement,
79
            tree_regressor=tree_regressor,
80
            tree_para=tree_para,
81
            xi=xi,
82
        )
83

src/gradient_free_optimizers/optimizer_search/bayesian_optimization.py 1 location

@@ 12-78 (lines=67) @@
9
from ..optimizers.smb_opt.bayesian_optimization import gaussian_process
10
11
12
class BayesianOptimizer(_BayesianOptimizer, Search):
13
    """
14
    A class implementing the **bayesian optimizer** for the public API.
15
    Inheriting from the `Search`-class to get the `search`-method and from
16
    the `BayesianOptimizer`-backend to get the underlying algorithm.
17
18
    Parameters
19
    ----------
20
    search_space : dict[str, list]
21
        The search space to explore. A dictionary with parameter
22
        names as keys and a numpy array as values.
23
    initialize : dict[str, int]
24
        The method to generate initial positions. A dictionary with
25
        the following key literals and the corresponding value type:
26
        {"grid": int, "vertices": int, "random": int, "warm_start": list[dict]}
27
    constraints : list[callable]
28
        A list of constraints, where each constraint is a callable.
29
        The callable returns `True` or `False` dependend on the input parameters.
30
    random_state : None, int
31
        If None, create a new random state. If int, create a new random state
32
        seeded with the value.
33
    rand_rest_p : float
34
        The probability of a random iteration during the the search process.
35
    warm_start_smbo
36
        The warm start for SMBO.
37
    max_sample_size : int
38
        The maximum number of points to sample.
39
    sampling : dict
40
        The sampling method to use.
41
    replacement : bool
42
        Whether to sample with replacement.
43
    gpr : dict
44
        The Gaussian Process Regressor to use.
45
    xi : float
46
        The exploration-exploitation trade-off parameter.
47
    """
48
49
    def __init__(
50
        self,
51
        search_space: Dict[str, list],
52
        initialize: Dict[
53
            Literal["grid", "vertices", "random", "warm_start"], int | List
54
        ] = {"grid": 4, "random": 2, "vertices": 4},
55
        constraints: List[callable] = [],
56
        random_state: int = None,
57
        rand_rest_p: float = 0,
58
        nth_process: int = None,
59
        warm_start_smbo=None,
60
        max_sample_size: int = 10000000,
61
        sampling: Dict[Literal["random"], int] = {"random": 1000000},
62
        replacement: bool = True,
63
        gpr=gaussian_process["gp_nonlinear"],
64
        xi: float = 0.03,
65
    ):
66
        super().__init__(
67
            search_space=search_space,
68
            initialize=initialize,
69
            constraints=constraints,
70
            random_state=random_state,
71
            rand_rest_p=rand_rest_p,
72
            nth_process=nth_process,
73
            warm_start_smbo=warm_start_smbo,
74
            max_sample_size=max_sample_size,
75
            sampling=sampling,
76
            replacement=replacement,
77
            gpr=gpr,
78
            xi=xi,
79
        )
80

src/gradient_free_optimizers/optimizer_search/tree_structured_parzen_estimators.py 1 location

@@ 13-75 (lines=63) @@
10
)
11
12
13
class TreeStructuredParzenEstimators(_TreeStructuredParzenEstimators, Search):
14
    """
15
    A class implementing **tree structured parzen estimators** for the public API.
16
    Inheriting from the `Search`-class to get the `search`-method and from
17
    the `TreeStructuredParzenEstimators`-backend to get the underlying algorithm.
18
19
    Parameters
20
    ----------
21
    search_space : dict[str, list]
22
        The search space to explore. A dictionary with parameter
23
        names as keys and a numpy array as values.
24
    initialize : dict[str, int]
25
        The method to generate initial positions. A dictionary with
26
        the following key literals and the corresponding value type:
27
        {"grid": int, "vertices": int, "random": int, "warm_start": list[dict]}
28
    constraints : list[callable]
29
        A list of constraints, where each constraint is a callable.
30
        The callable returns `True` or `False` dependend on the input parameters.
31
    random_state : None, int
32
        If None, create a new random state. If int, create a new random state
33
        seeded with the value.
34
    rand_rest_p : float
35
        The probability of a random iteration during the the search process.
36
    warm_start_smbo
37
        The warm start for SMBO.
38
    max_sample_size : int
39
        The maximum number of points to sample.
40
    sampling : dict
41
        The sampling method to use.
42
    replacement : bool
43
        Whether to sample with replacement.
44
    gamma_tpe : float
45
        The parameter for the Tree Structured Parzen Estimators
46
    """
47
48
    def __init__(
49
        self,
50
        search_space: Dict[str, list],
51
        initialize: Dict[
52
            Literal["grid", "vertices", "random", "warm_start"], int | List
53
        ] = {"grid": 4, "random": 2, "vertices": 4},
54
        constraints: List[callable] = [],
55
        random_state: int = None,
56
        rand_rest_p: float = 0,
57
        nth_process: int = None,
58
        warm_start_smbo=None,
59
        max_sample_size: int = 10000000,
60
        sampling: Dict[Literal["random"], int] = {"random": 1000000},
61
        replacement: bool = True,
62
        gamma_tpe=0.2,
63
    ):
64
        super().__init__(
65
            search_space=search_space,
66
            initialize=initialize,
67
            constraints=constraints,
68
            random_state=random_state,
69
            rand_rest_p=rand_rest_p,
70
            nth_process=nth_process,
71
            warm_start_smbo=warm_start_smbo,
72
            max_sample_size=max_sample_size,
73
            sampling=sampling,
74
            replacement=replacement,
75
            gamma_tpe=gamma_tpe,
76
        )
77

src/gradient_free_optimizers/optimizer_search/lipschitz_optimizer.py 1 location

@@ 11-69 (lines=59) @@
8
from ..optimizers import LipschitzOptimizer as _LipschitzOptimizer
9
10
11
class LipschitzOptimizer(_LipschitzOptimizer, Search):
12
    """
13
    A class implementing the **lipschitz optimizer** for the public API.
14
    Inheriting from the `Search`-class to get the `search`-method and from
15
    the `LipschitzOptimizer`-backend to get the underlying algorithm.
16
17
    Parameters
18
    ----------
19
    search_space : dict[str, list]
20
        The search space to explore. A dictionary with parameter
21
        names as keys and a numpy array as values.
22
    initialize : dict[str, int]
23
        The method to generate initial positions. A dictionary with
24
        the following key literals and the corresponding value type:
25
        {"grid": int, "vertices": int, "random": int, "warm_start": list[dict]}
26
    constraints : list[callable]
27
        A list of constraints, where each constraint is a callable.
28
        The callable returns `True` or `False` dependend on the input parameters.
29
    random_state : None, int
30
        If None, create a new random state. If int, create a new random state
31
        seeded with the value.
32
    rand_rest_p : float
33
        The probability of a random iteration during the the search process.
34
    warm_start_smbo
35
        The warm start for SMBO.
36
    max_sample_size : int
37
        The maximum number of points to sample.
38
    sampling : dict
39
        The sampling method to use.
40
    replacement : bool
41
        Whether to sample with replacement.
42
    """
43
44
    def __init__(
45
        self,
46
        search_space: Dict[str, list],
47
        initialize: Dict[
48
            Literal["grid", "vertices", "random", "warm_start"], int | List
49
        ] = {"grid": 4, "random": 2, "vertices": 4},
50
        constraints: List[callable] = [],
51
        random_state: int = None,
52
        rand_rest_p: float = 0,
53
        nth_process: int = None,
54
        warm_start_smbo=None,
55
        max_sample_size: int = 10000000,
56
        sampling: Dict[Literal["random"], int] = {"random": 1000000},
57
        replacement: bool = True,
58
    ):
59
        super().__init__(
60
            search_space=search_space,
61
            initialize=initialize,
62
            constraints=constraints,
63
            random_state=random_state,
64
            rand_rest_p=rand_rest_p,
65
            nth_process=nth_process,
66
            warm_start_smbo=warm_start_smbo,
67
            max_sample_size=max_sample_size,
68
            sampling=sampling,
69
            replacement=replacement,
70
        )
71

src/gradient_free_optimizers/optimizer_search/direct_algorithm.py 1 location

@@ 11-69 (lines=59) @@
8
from ..optimizers import DirectAlgorithm as _DirectAlgorithm
9
10
11
class DirectAlgorithm(_DirectAlgorithm, Search):
12
    """
13
    A class implementing the **direct algorithm** for the public API.
14
    Inheriting from the `Search`-class to get the `search`-method and from
15
    the `DirectAlgorithm`-backend to get the underlying algorithm.
16
17
    Parameters
18
    ----------
19
    search_space : dict[str, list]
20
        The search space to explore. A dictionary with parameter
21
        names as keys and a numpy array as values.
22
    initialize : dict[str, int]
23
        The method to generate initial positions. A dictionary with
24
        the following key literals and the corresponding value type:
25
        {"grid": int, "vertices": int, "random": int, "warm_start": list[dict]}
26
    constraints : list[callable]
27
        A list of constraints, where each constraint is a callable.
28
        The callable returns `True` or `False` dependend on the input parameters.
29
    random_state : None, int
30
        If None, create a new random state. If int, create a new random state
31
        seeded with the value.
32
    rand_rest_p : float
33
        The probability of a random iteration during the the search process.
34
    warm_start_smbo
35
        The warm start for SMBO.
36
    max_sample_size : int
37
        The maximum number of points to sample.
38
    sampling : dict
39
        The sampling method to use.
40
    replacement : bool
41
        Whether to sample with replacement.
42
    """
43
44
    def __init__(
45
        self,
46
        search_space: Dict[str, list],
47
        initialize: Dict[
48
            Literal["grid", "vertices", "random", "warm_start"], int | List
49
        ] = {"grid": 4, "random": 2, "vertices": 4},
50
        constraints: List[callable] = [],
51
        random_state: int = None,
52
        rand_rest_p: float = 0,
53
        nth_process: int = None,
54
        warm_start_smbo=None,
55
        max_sample_size: int = 10000000,
56
        sampling: Dict[Literal["random"], int] = {"random": 1000000},
57
        replacement: bool = True,
58
    ):
59
        super().__init__(
60
            search_space=search_space,
61
            initialize=initialize,
62
            constraints=constraints,
63
            random_state=random_state,
64
            rand_rest_p=rand_rest_p,
65
            nth_process=nth_process,
66
            warm_start_smbo=warm_start_smbo,
67
            max_sample_size=max_sample_size,
68
            sampling=sampling,
69
            replacement=replacement,
70
        )
71

src/gradient_free_optimizers/optimizer_search/ensemble_optimizer.py 1 location

@@ 11-37 (lines=27) @@
8
from ..optimizers import EnsembleOptimizer as _EnsembleOptimizer
9
10
11
class EnsembleOptimizer(_EnsembleOptimizer, Search):
12
    def __init__(
13
        self,
14
        search_space: Dict[str, list],
15
        initialize: Dict[
16
            Literal["grid", "vertices", "random", "warm_start"], int | List
17
        ] = {"grid": 4, "random": 2, "vertices": 4},
18
        constraints: List[callable] = [],
19
        random_state: int = None,
20
        rand_rest_p: float = 0,
21
        nth_process: int = None,
22
        warm_start_smbo=None,
23
        max_sample_size: int = 10000000,
24
        sampling: Dict[Literal["random"], int] = {"random": 1000000},
25
        replacement: bool = True,
26
    ):
27
        super().__init__(
28
            search_space=search_space,
29
            initialize=initialize,
30
            constraints=constraints,
31
            random_state=random_state,
32
            rand_rest_p=rand_rest_p,
33
            nth_process=nth_process,
34
            warm_start_smbo=warm_start_smbo,
35
            max_sample_size=max_sample_size,
36
            sampling=sampling,
37
            replacement=replacement,
38
        )
39