-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgradv.py
35 lines (31 loc) · 799 Bytes
/
gradv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import numpy as np
from scipy import optimize as opt
import armijo
import math
class GradientMethod(object):
"""
Constructor Gradient-Method
"""
def __init__ (self, f, fd, H, xk, eps):
self.xk = xk
self.eps = eps
self.fd = fd
self.f = f
self.H = H
return
"""
Gradient-Method
"""
def work (self):
f = self.f
xk = self.xk
eps = self.eps
fd = self.fd
it = 0
maxit = 2000
while (np.linalg.norm(fd(xk)) > eps) and (it < maxit):
t = armijo.schrittweite(f, fd, xk, -fd(xk), sigma = 0.02, rho = 0.5, gamma = 0.0001)
xk = xk - t * fd(xk)
print("Log-Values(Gradient): ", math.log10(f(xk)))
it += 1
return xk, it