1
2 """
3 Computes Goldfeld step for a specific function at a specific point
4 """
5 from numpy import pi, dot, cos
6 from numpy.linalg import solve as n_solve
7 from numpy.linalg import norm, cholesky, eigvalsh
8
10
11 """
12 The Goldfeld step
13 """
14 - def __call__(self, function, point, state):
15 """
16 Computes Goldfeld step
17 """
18 g = function.gradient(point)
19 state['gradient'] = g
20 G = function.hessian(point)
21 state['hessian'] = G
22 c = 1e-8
23
24
25
26 d0 = None
27
28 try:
29 L = cholesky(G)
30
31 step = n_solve(L.T, n_solve(L, -g))
32 except:
33
34 G_eigvals = eigvalsh(G)
35 minEig = min(G_eigvals)
36 if minEig < 0:
37 shift = -minEig + c
38
39
40 for i in xrange(point): G[i,i] += shift
41
42 step = n_solve(G, -g)
43
44
45 state['direction'] = step
46 return step
47