1
2
3
4
5 """
6 Computes Goldstein-Price step for a specific function at a specific point
7 """
8
9 import math
10 from numpy import dot
11 from numpy.linalg import solve as n_solve
12 from numpy.linalg import norm, cholesky
13
15 """
16 The Goldstein-Price step
17 """
19 """
20 """
21 self.mu = mu
22 self.nu = math.cos(math.pi/2.0 - mu)
23
24 - def __call__(self, function, point, state):
25 """
26 Computes Goldstein-Price step
27 """
28 g = function.gradient(point)
29 state['gradient'] = g
30 G = function.hessian(point)
31 state['hessian'] = G
32
33 isPositiveDefinite = True
34 d0 = None
35
36 try:
37 L = cholesky(G)
38 d0 = n_solve(L.T, n_solve(L, -g))
39 except:
40 isPositiveDefinite = False
41
42 if isPositiveDefinite:
43 cosTheta = dot(d0, -g) / (norm(d0) * norm(g))
44 if cosTheta >= self.nu:
45 step = d0
46 else:
47 step = -g
48 else:
49 step = -g
50
51 state['direction'] = step
52 return step
53