1
2
3
4
5 """
6 Line search decorator that overrides the default alpha_step value with a factor times the last alpha_step
7 """
8
10 """
11 Overrides the default step size and replaces it with a factor times the last one
12 """
13 - def __init__(self, line_search, alpha_factor = 2., **kwargs):
14 """
15 Needs to have :
16 - the decorated line search (line_search)
17 Can have :
18 - an alpha modifier, a factor to modulate the last step length (alpha_factor = 2.)
19 """
20 self.line_search = line_search
21 self.alpha_factor = alpha_factor
22
23 - def __call__(self, origin, function, state, **kwargs):
24 """
25 Returns a good candidate
26 Parameters :
27 - origin is the origin of the search
28 - function is the function to minimize
29 - state is the state of the optimizer
30 """
31 if 'alpha_step' in state:
32 state['initial_alpha_step'] = self.alpha_factor * state['alpha_step']
33 return self.line_search(origin = origin, function = function, state = state, **kwargs)
34