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

gradient_free_optimizers.optimizers.local.stochastic_tunneling   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A StochasticTunnelingOptimizer._accept() 0 3 1
A StochasticTunnelingOptimizer.__init__() 0 2 1
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
6
import numpy as np
7
8
from .simulated_annealing import SimulatedAnnealingOptimizer
9
from ...search import Search
10
11
12
class StochasticTunnelingOptimizer(SimulatedAnnealingOptimizer, Search):
13
    def __init__(self, search_space, gamma=0.5, **kwargs):
14
        super().__init__(search_space, **kwargs)
15
16
    def _accept(self):
17
        f_stun = 1 - np.exp(-self._opt_args_.gamma * self._score_norm())
18
        return np.exp(-f_stun / self.temp)
19