From 70a143031b6777775b0058d6fcc845558e370483 Mon Sep 17 00:00:00 2001 From: Lars Ruthotto Date: Wed, 19 Jun 2013 12:39:00 -0700 Subject: [PATCH] Generalized Gauss Newton by using Lambda Functions --- code/GaussNewton.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/code/GaussNewton.py b/code/GaussNewton.py index 997ffbb4..ab9f5f52 100644 --- a/code/GaussNewton.py +++ b/code/GaussNewton.py @@ -1,9 +1,19 @@ import numpy as np from pylab import norm -def GaussNewton(x0, maxIter=20, maxIterLS=10, LSreduction=1e-4, tolJ=1e-3, tolX=1e-3, tolG=1e-3, eps=1e-16, xStop=np.empty): +def GaussNewton(fctn, x0,maxIter=20, maxIterLS=10, LSreduction=1e-4, tolJ=1e-3, tolX=1e-3, + tolG=1e-3, eps=1e-16, xStop=np.empty): """ - GaussNewton optimization for Rosenbrock function (has to be generalized) + GaussNewton Optimization + + Input: + ------ + fctn - objective Function (lambda function) + x0 - starting guess + + Output: + ------- + xOpt - numerical optimizer """ # initial output print "%s GaussNewton %s" % ('='*22,'='*22) @@ -13,7 +23,7 @@ def GaussNewton(x0, maxIter=20, maxIterLS=10, LSreduction=1e-4, tolJ=1e-3, tolX= # evaluate stopping criteria if xStop==np.empty: xStop=x0 - Jstop = Rosenbrock(xStop) + Jstop = fctn(xStop) print "%3d\t%1.2e" % (-1, Jstop[0]) # initialize @@ -25,7 +35,7 @@ def GaussNewton(x0, maxIter=20, maxIterLS=10, LSreduction=1e-4, tolJ=1e-3, tolX= xOld=xc while 1: # evaluate objective function - Jc,dJ,H = Rosenbrock(xc) + Jc,dJ,H = fctn(xc) print "%3d\t%1.2e\t%1.2e\t%d" % (iter, Jc[0],norm(dJ),iterLS) # check stopping rules @@ -45,7 +55,7 @@ def GaussNewton(x0, maxIter=20, maxIterLS=10, LSreduction=1e-4, tolJ=1e-3, tolX= LS =0; t = 1; iterLS=1 while (iterLS