def Hessian return np array 1896 632 -632 -632 316 def LevenbergMarkva

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
def Hessian(x):
return np.array([[1896*x[0]**2 - 632*x[1] + 4, -632*x[0]],
[-632*x[0], 316]])
def LevenbergMarkvardt(x, step = 0, m = 10000, eps = 0.0001, M = 1000):
d = grad(x)
if np.linalg.norm(d) < eps or step > M:
return f(x), x, step
while True:
d = np.matmul(np.linalg.inv(-(Hessian(x)+m*np.ones([n, n]))), d.transpose())
new_x = x + d
print(d, x)
print(new_x)
if f(new_x) < f(x):
return LevenbergMarkvardt(new_x, step+1, m / 2.)
m *= 2