Passed
Push — master ( 502a6e...660aa4 )
by Simon
04:50 queued 14s
created

SimulatedAnnealingOptimizer.__init__()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 5
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
6
import numpy as np
7
8
from ..local_opt import StochasticHillClimbingOptimizer
9
10
11
class SimulatedAnnealingOptimizer(StochasticHillClimbingOptimizer):
12
    name = "Simulated Annealing"
13
    _name_ = "simulated_annealing"
14
    __name__ = "SimulatedAnnealingOptimizer"
15
16
    optimizer_type = "local"
17
    computationally_expensive = False
18
19
    def __init__(self, *args, annealing_rate=0.97, start_temp=1, **kwargs):
20
        super().__init__(*args, **kwargs)
21
22
        self.annealing_rate = annealing_rate
23
        self.start_temp = start_temp
24
        self.temp = start_temp
25
26
    def _p_accept_default(self):
27
        # the 'minus' is omitted, because we maximize a score
28
        return np.exp(self._exponent)
29
30
    def evaluate(self, score_new):
31
        StochasticHillClimbingOptimizer.evaluate(self, score_new)
32
        self.temp *= self.annealing_rate
33