30
Part VIIb: Newton-Krylov Methods MA 580; Iterative Methods for Nonlinear Equations C. T. Kelley NC State University tim [email protected] Version of November 4, 2016 Read Sections 6.1.1, 6.4, 8.1 of the Red book NCSU, Fall 2016 Part VIIb: Newton-Krylov Methods and Global Convergence ©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 1 / 30

MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

  • Upload
    others

  • View
    22

  • Download
    0

Embed Size (px)

Citation preview

Page 1: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

MA 580; Iterative Methods for NonlinearEquations

C. T. KelleyNC State University

tim [email protected]

Version of November 4, 2016

Read Sections 6.1.1, 6.4, 8.1 of the Red book

NCSU, Fall 2016Part VIIb: Newton-Krylov Methods and Global Convergence

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 1 / 30

Page 2: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Newton-Iterative Methods

Replace exact (or direct) solution of

F′(xc)s = −F(xc)

with an iterative method.Terminate the linear (inner) iteration when the inexact Newtoncondition

‖F′(xc)s + F(xc)‖ ≤ ηc‖F(xc)‖

holds.η is called the forcing term.

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 2 / 30

Page 3: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Options

Examples: Newton-GMRES, Newton-MG, Newton-Krylov-SchwarzJacobian-vector product:

F′(x)v ≈ F(x + hv)− F(x)

h

where h is scaled to capture the low-order bits.

h = ‖x‖√εmach/‖v‖.

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 3 / 30

Page 4: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

JFNK

These methods are often calledJacobian-Free Newton Krylov (JFNK) methods.

You will see the term JFNK all over computational scienceand engineering.

Cost:

Nonlinear (Newton) iterationsKrylovs/Newton

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 4 / 30

Page 5: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Suppose, think H-equation, function/Jacobian cost O(N2) work

Matrix factorization costs N3/3 work.

So if you get convergence (as we will see) in 6 Newtons and atotal of 17 GMRES iterations independently of N!!!,

your cost is O(N2), and

You’ve got a winner on your hands!

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 5 / 30

Page 6: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Convergence Theory

Theorem: Assume that ηn ≤ η̄ < 1, SA, and good data. Then theNewton iteration converges to x∗ and

‖en+1‖ = O(‖en‖2 + ηn‖en‖)

Proof: Cheating theorem.

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 6 / 30

Page 7: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Remarks

If ηn = O(‖F(xn)‖) the convergence is quadratic.

If ηn → 0 the convergence is q-superlinear,

‖en+1‖/‖en‖ → 0.

It is usually a poor idea to over solve in the inner iteration.

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 7 / 30

Page 8: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Integro-Differential Equation Example

Remember:

R_data=struct(’D2’,D2,’w’,w,’x’,x);

function f=ieq(u,R_data)

x=R_data.x; D2=R_data.D2; w=R_data.w;

f = D2*u + cos(x*u’)*w;

function jac=ieqprime(u,R_data);

x=R_data.x; D2=R_data.D2; w=R_data.w;

jac=D2-diag(x)*sin(x*u’)*diag(w);

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 8 / 30

Page 9: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Packaging things for the Jacobian-vector product

All we need to do is

Write the Jacobian-vector product.

Preconditon with D−12

So we will have to get orgainzed.

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 9 / 30

Page 10: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Example: Preconditioning Data

[L,U]=lu(D2);

PVEC=struct(’L’,L,’U’,U);

Then pass the structure to the preconditioner

function pv = precondv(v,PVEC)

L=PVEC.L; U=PVEC.U; pv = U\(L\v);

Pass the Jacobian matrix directly to GMRES as in the linear case.

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 10 / 30

Page 11: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Communicating with GMRES

Pass MVEC to kl as precomputed data for the preconditioner,

and jac as precomputed data for the mat-vec.

GMRES parameters:

ltol = eta

Commect maxit with η.

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 11 / 30

Page 12: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Call to kl to compute the step

Given

[L,U]=lu(D2); eta =.1;

res=ieq(u,R_data);

fp=ieqprime(u,R_data);

options=kl_optset(’ltol ’,rtol ,...

’matvec_data ’,fp,’ptv ’,@precondv ,...

’p_side ’,’right ’,’p_data ’,PVEC);

[step , histl] = kl(u, -res , @mvec ,options);

See ieq jfnk.m on the Moodle page.

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 12 / 30

Page 13: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

How did we do?

iterations0 1 2 3 4

Rel

ativ

e re

sidu

al

10-16

10-14

10-12

10-10

10-8

10-6

10-4

10-2

100 Residual History, BVP Example, Newton

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 13 / 30

Page 14: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

This is getting complicated

What would a finite-difference Jacobian need?u, F(u), data for F, . . .

What if the function feeds data to the preconditioner?

What if the preconditioner depends on the current iterate?

What if GMRES is not your favorite linear solver?

Tools can manage this better than your writing a code every time.

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 14 / 30

Page 15: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Software

I use knl.m for the examples/homework.

http://www4.ncsu.edu/~ctk/knl.html

Link on Moodle page.

You may also use nsoli.m

http://www4.ncsu.edu/~ctk/newtony.html

and you can write your own using kl.m, for example.

[sol, it_hist, ierr, x_hist] = knl(x,f, nloptions,static_data)

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30

Page 16: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Input to knl

x: initial iterate

f: handle to the residual

nloptions: options structure

static data: any precomputed data for f, thepreconditioner, or the Jacobian-vector product.

The options are complex, because the algorithms are.

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 16 / 30

Page 17: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Output

sol: solution

it hist: iteration history

ierr: error flag

x hist: (optional) complete history of iteration

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 17 / 30

Page 18: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Options

atol, rtol, maxit, maxitl

etamax: Forcing term control

GMRES is the default linear solver

FD is the default Jacobian-vector product

Here’s the IEQ example . . .

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 18 / 30

Page 19: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Calling knl

options=knl_optset(’etamax ’,-.1,’atol ’,atol ,...

’rtol ’,rtol ,’ptv ’,@precondv ,...

’p_side ’,’right ’,’p_data ’,PVEC);

[u,it_hist]=knl(u,@ieq ,options ,R_data);

histc=it_hist (:,1);

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 19 / 30

Page 20: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Residual History Plots: H0 ≡ 1, c = .975

iterations0 5 10 15 20 25 30 35 40

Rel

ativ

e re

sidu

al

10 -14

10 -12

10 -10

10 -8

10 -6

10 -4

10 -2

100 Residual History, Three Solvers

NewtonChordJFNK

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 20 / 30

Page 21: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Newton-Iterative Methods

Newton vs Chord vs JFNK: timings on MacBook Air

Residual histories are independent of N, but not of c .

For N = 5000 and c = .975 the timings for a solve are

Newton: 14 secs, 5 iterationsChord: 8 secs, 39 iterationsJFNK: .3 secs, 6 iterations

For N = 5000 and c = .5 the timings for a solve are

Newton: 10 secs, 3 iterationsChord: 3.5 secs, 6 iterationsJFNK: .2 secs, 6 iterations

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 21 / 30

Page 22: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Global Convergence

Poor Data

Suppose you try to solve arctan(x) = 0 with Newton and x0 = 10.The iterations are

10,−138, 2.9× 104,−1.5× 109, 9.9× 1017.

What happened?

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 22 / 30

Page 23: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Global Convergence

Line searches and the Armijo rule

Now we make a distinction between the Newton direction

d = −F′(xc)−1F(xc)

and the Newton steps = x+ − xc

Simply put, we find the least λ = 2−m for m = 0, 1, . . . so that

‖F(xc + λd)‖ < ‖F(xc)‖

and use s = λd. This process, a line search almost works.

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 23 / 30

Page 24: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Global Convergence

Saving the ArcTan iteration

0 1 2 3 4 5 6 7 8 9 10 11 1225

20

15

10

5

0

5

Nonlinear iterations

Log

Abso

lute

Non

linea

r Res

idua

l

3 2 2 3

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 24 / 30

Page 25: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Global Convergence

Sufficient Decrease and Termination

You need a little more to prove something. The sufficient decreasecondition is

‖F(xc + 2−md)‖ < (1− α2−m)‖F(xc)‖,

Typical α = 10−4.We will terminate when the nonlinear residual ‖F‖ is small, i.e.when

‖F(xn)‖ ≤ τa + τr‖F(x0)‖.

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 25 / 30

Page 26: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Global Convergence

Newton-Iterative Algorithm

nsolg(x,F , τa, τr )

evaluate F(x); τ ← τr |F(x)|+ τa.while ‖F(x)‖ > τ do

Find d such that ‖F′(x)d + F(x)‖ ≤ η‖F(x)‖If no such d can be found, terminate with failure.λ = 1while ‖F(x + λd)‖ > (1− αλ)‖F(x)‖ doλ← σλ where σ ∈ [1/10, 1/2]

end whilex← x + λd

end while

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 26 / 30

Page 27: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Global Convergence

Theory

Theorem: Suppose F is Lipschitz continuously differentiable, {xn}is the inexact Newton-Armijo sequence, 0 < ηn < η̄ < 1. Thethere are only three possibilities:

{xn} converges to a root x∗ of F at which the standardassumptions hold, full steps (λ = 1) are taken for nsufficiently large, and the local convergence theory holds.

The sequence {xn} is unbounded.

The sequence {F′(xn)−1} is unbounded.

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 27 / 30

Page 28: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Global Convergence

A few examples

f (x) = ex ; the Newton-Armijo sequence takes full steps and

x+ = xc −exc

exc= xc − 1

So xn → −∞.

f (x) = x2 + 1; You dont get full steps and xn → 0. Whathappened?

Bottom line: you can’t solve a problem with no solution.

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 28 / 30

Page 29: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Global Convergence

Choosing a Solver

The most important issues in selecting a solver are

the size of the problem,

the cost of evaluating f and f ′, and

the way linear systems of equations will be solved.

The items in the list above are not independent.

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 29 / 30

Page 30: MA 580; Iterative Methods for Nonlinear EquationsKelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 15 / 30. Part VIIb: Newton-Krylov Methods Newton-Iterative

Part VIIb: Newton-Krylov Methods

Global Convergence

Rough guidelines

Small N and cheap f; try direct methods and a forwarddifference Jacobian (but see the example at the end of thislecture for a different view).

Large N or expensive f ′; try matrix-free Newton-Krylovsolvers.

Large N, very sparse f ′, only bad preconditioners; try sparsedifferencing for the Jacobian and use a direct method.

©C. T. Kelley, I. C. F. Ipsen, 2016 Part VIIb: Newton-Krylov Methods MA 580, Fall 2016 30 / 30