Passed
Push — master ( d39371...69bf6f )
by Simon
03:38
created

SimulatedAnnealingOptimizer.__init__()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 4
dl 0
loc 4
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 import StochasticHillClimbingOptimizer
9
from ...search import Search
10
11
12
class SimulatedAnnealingOptimizer(StochasticHillClimbingOptimizer, Search):
13
    def __init__(self, search_space, annealing_rate=0.99, start_temp=100):
14
        super().__init__(search_space)
15
        self.annealing_rate = annealing_rate
16
        self.temp = start_temp
17
18
    # use _consider from StochasticHillClimbingOptimizer
19
20
    def _accept_default(self):
21
        return np.exp(-self._score_norm_default() / self.temp)
22
23
    def _accept_adapt(self):
24
        return self._score_norm_adapt() * self.temp
25
26
    def evaluate(self, score_new):
27
        super().evaluate(score_new)
28
29
        self.temp = self.temp * self.annealing_rate
30