]> git.rustad.me Git - nummat1/commitdiff
Rename newtsteep
authorBjørn Rustad <bjornrus@samfundet.no>
Fri, 30 Sep 2011 19:04:55 +0000 (21:04 +0200)
committerBjørn Rustad <bjornrus@samfundet.no>
Fri, 30 Sep 2011 19:04:55 +0000 (21:04 +0200)
steepestnewton.py [new file with mode: 0644]

diff --git a/steepestnewton.py b/steepestnewton.py
new file mode 100644 (file)
index 0000000..2498575
--- /dev/null
@@ -0,0 +1,23 @@
+from newton import newton
+from steepest import steepest
+from function import gradient_g
+from numpy.linalg import norm
+
+# Run steepest method until tolerance steep_tol, then continue with Newtons
+# method until tolerance newt_tol
+def steepestnewton(x0, H, b, c, steep_tol, newt_tol):
+    x = []
+    r = []
+
+    # Use the starting norm to calculate relative residuals in both algorithms
+    x0_norm = norm(gradient_g(x0, H, b, c))
+    points, residuals = steepest(x0, H, b, c, steep_tol, 100, 0, x0_norm)
+    x.extend(points)
+    r.extend(residuals)
+
+    # Newton starts in the same point as steepest ends in
+    points, residuals = newton.newton(x[len(x)-1], H, b, c, newt_tol, 100, x0_norm)
+    x.extend(points[1:])
+    r.extend(residuals[1:])
+
+    return (x, r)