gradient_free_optimizers.optimizers.local_opt.repulsing_hill_climbing_optimizer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 45
dl 0
loc 62
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A RepulsingHillClimbingOptimizer.iterate() 0 7 1
A RepulsingHillClimbingOptimizer.__init__() 0 28 1
A RepulsingHillClimbingOptimizer.evaluate() 0 7 2
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
6
from . import HillClimbingOptimizer
7
8
9
class RepulsingHillClimbingOptimizer(HillClimbingOptimizer):
10
    name = "Repulsing Hill Climbing"
11
    _name_ = "repulsing_hill_climbing"
12
    __name__ = "RepulsingHillClimbingOptimizer"
13
14
    optimizer_type = "local"
15
    computationally_expensive = False
16
17
    def __init__(
18
        self,
19
        search_space,
20
        initialize={"grid": 4, "random": 2, "vertices": 4},
21
        constraints=[],
22
        random_state=None,
23
        rand_rest_p=0,
24
        nth_process=None,
25
        epsilon=0.03,
26
        distribution="normal",
27
        n_neighbours=3,
28
        repulsion_factor=5,
29
    ):
30
        super().__init__(
31
            search_space=search_space,
32
            initialize=initialize,
33
            constraints=constraints,
34
            random_state=random_state,
35
            rand_rest_p=rand_rest_p,
36
            nth_process=nth_process,
37
            epsilon=epsilon,
38
            distribution=distribution,
39
            n_neighbours=n_neighbours,
40
        )
41
42
        self.tabus = []
43
        self.repulsion_factor = repulsion_factor
44
        self.epsilon_mod = 1
45
46
    @HillClimbingOptimizer.track_new_pos
47
    def iterate(self):
48
        return self.move_climb(
49
            self.pos_current,
50
            epsilon=self.epsilon,
51
            distribution=self.distribution,
52
            epsilon_mod=self.epsilon_mod,
53
        )
54
55
    def evaluate(self, score_new):
56
        super().evaluate(score_new)
57
58
        if score_new <= self.score_current:
59
            self.epsilon_mod = self.repulsion_factor
60
        else:
61
            self.epsilon_mod = 1
62