Passed
Push — master ( 626f23...be3b1e )
by Simon
01:48
created

RandomAnnealingOptimizer.__init__()   A

Complexity

Conditions 1

Size

Total Lines 17
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nop 8
dl 0
loc 17
rs 9.6
c 0
b 0
f 0

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
6
from ..local_opt import HillClimbingOptimizer
7
from ...search import Search
8
9
10
class RandomAnnealingOptimizer(HillClimbingOptimizer, Search):
11
    name = "Random Annealing"
12
13
    def __init__(
14
        self,
15
        *args,
16
        epsilon=0.03,
17
        distribution="normal",
18
        n_neighbours=3,
19
        annealing_rate=0.98,
20
        start_temp=10,
21
        **kwargs,
22
    ):
23
        super().__init__(*args, **kwargs)
24
        self.epsilon = epsilon
25
        self.distribution = distribution
26
        self.n_neighbours = n_neighbours
27
        self.annealing_rate = annealing_rate
28
        self.start_temp = start_temp
29
        self.temp = start_temp
30
31
    @HillClimbingOptimizer.track_nth_iter
32
    @HillClimbingOptimizer.random_restart
33
    def iterate(self):
34
        pos = self._move_climb(self.pos_current, epsilon_mod=self.temp)
35
        self.temp = self.temp * self.annealing_rate
36
37
        return pos
38