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

RandomAnnealingOptimizer.iterate()   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
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