Passed
Push — master ( 7ebd63...8bd9a3 )
by Simon
06:11
created

DownhillSimplexOptimizer.__init__()   A

Complexity

Conditions 1

Size

Total Lines 26
Code Lines 25

Duplication

Lines 26
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 25
dl 26
loc 26
rs 9.28
c 0
b 0
f 0
cc 1
nop 11

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
from typing import List, Dict, Literal, Literal
6
7
from ..search import Search
8
from ..optimizers import DownhillSimplexOptimizer as _DownhillSimplexOptimizer
9
10
11
class DownhillSimplexOptimizer(_DownhillSimplexOptimizer, Search):
12
    """
13
    A class implementing the **downhill simplex optimizer** for the public API.
14
    Inheriting from the `Search`-class to get the `search`-method and from
15
    the `DownhillSimplexOptimizer`-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
    alpha : float
35
        The reflection parameter of the simplex algorithm.
36
    gamma : float
37
        The expansion parameter of the simplex algorithm.
38
    beta : float
39
        The contraction parameter of the simplex algorithm.
40
    sigma : float
41
        The shrinking parameter of the simplex algorithm.
42
    """
43
44 View Code Duplication
    def __init__(
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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
        alpha: float = 1,
55
        gamma: float = 2,
56
        beta: float = 0.5,
57
        sigma: float = 0.5,
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
            alpha=alpha,
67
            gamma=gamma,
68
            beta=beta,
69
            sigma=sigma,
70
        )
71