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

gradient_free_optimizers.optimizers.exp_opt.random_annealing   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A RandomAnnealingOptimizer.iterate() 0 7 1
A RandomAnnealingOptimizer.__init__() 0 17 1
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