Passed
Push — master ( 9ff666...1a4396 )
by Simon
03:24
created

hyperactive.optimizers.random.random_annealing.RandomAnnealingOptimizer._init_opt_positioner()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
6
from ..local import HillClimbingOptimizer
7
8
9
class RandomAnnealingOptimizer(HillClimbingOptimizer):
10
    def __init__(self, _main_args_, _opt_args_):
11
        super().__init__(_main_args_, _opt_args_)
12
        self.temp = 1
13
14
    def _iterate(self, i, _cand_, _p_):
15
        _p_.pos_new = _p_.move_climb(
16
            _cand_, _p_.pos_current, epsilon_mod=self.temp * self._opt_args_.epsilon_mod
17
        )
18
        _p_.score_new = _cand_.eval_pos(_p_.pos_new)
19
20
        if _p_.score_new > _cand_.score_best:
21
            _cand_, _p_ = self._update_pos(_cand_, _p_)
22
23
        self.temp = self.temp * self._opt_args_.annealing_rate
24
25
        return _cand_
26