gradient_free_optimizers.optimizer_search.tree_structured_parzen_estimators   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 34
dl 0
loc 77
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A TreeStructuredParzenEstimators.__init__() 0 29 1
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
from typing import List, Dict, Literal, Union
6
7
from ..search import Search
8
from ..optimizers import (
9
    TreeStructuredParzenEstimators as _TreeStructuredParzenEstimators,
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 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"],
53
            Union[int, list[dict]],
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
        gamma_tpe=0.2,
64
    ):
65
        super().__init__(
66
            search_space=search_space,
67
            initialize=initialize,
68
            constraints=constraints,
69
            random_state=random_state,
70
            rand_rest_p=rand_rest_p,
71
            nth_process=nth_process,
72
            warm_start_smbo=warm_start_smbo,
73
            max_sample_size=max_sample_size,
74
            sampling=sampling,
75
            replacement=replacement,
76
            gamma_tpe=gamma_tpe,
77
        )
78