From 7ad019e4c45583a17c650d4443457e2bf6d3b7b0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B8rn=20Rustad?= Date: Fri, 30 Sep 2011 21:04:55 +0200 Subject: [PATCH] Rename newtsteep --- steepestnewton.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 steepestnewton.py diff --git a/steepestnewton.py b/steepestnewton.py new file mode 100644 index 0000000..2498575 --- /dev/null +++ b/steepestnewton.py @@ -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) -- 2.47.3