| Total Complexity | 2 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 |