NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) :...

24
Norms and Errors

Transcript of NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) :...

Page 1: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Norms and Errors

Page 2: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Norms

What’s a norm?

• A generalization of ‘absolute value’ to vectors.• f (x) : Rn → R

+0 , returns a ‘magnitude’ of the input vector

• In symbols: Often written ‖x‖.

Define norm.

A function ‖x‖ : Rn → R+0 is called a norm if and only if

1. ‖x‖ > 0⇔ x 6= 0.2. ‖γx‖ = |γ| ‖x‖ for all scalars γ.3. Obeys triangle inequality ‖x + y‖ 6 ‖x‖+ ‖y‖

1

Page 3: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Examples of Norms i

What are some examples of norms?

The so-called p-norms:∥∥∥∥∥∥∥ x1

xn

∥∥∥∥∥∥∥p

= p√

|x1|p + · · ·+ |xn|p (p > 1)

p = 1, 2,∞ particularly important

2

Page 5: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Norms and Errors i

If we’re computing a vector result, the error is a vector.That’s not a very useful answer to ‘how big is the error’.What can we do?

Apply a norm!

How? Attempt 1:

Magnitude of error 6= ‖true value‖−‖approximate value‖ WRONG!

Attempt 2:

Magnitude of error = ‖true value− approximate value‖

4

Page 6: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Absolute and Relative Error i

What are the absolute and relative errors in approximating thelocation of Siebel center (40.114,−88.224) as (40,−88) usingthe 2-norm?

(40.114−88.224

)−

(40−88

)=

(0.114−.224

)Absolute magnitude;∥∥∥∥∥

(40.114−88.224

)∥∥∥∥∥2

≈ 96.91

5

Page 7: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Absolute and Relative Error ii

Absolute error: ∥∥∥∥∥(

0.114−.224

)∥∥∥∥∥2

≈ .2513

Relative error:.251396.91

≈ .00259.

But: Is the 2-norm really the right norm here?

6

Page 8: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Demo: Calculate geographic distances usinghttp://tripstance.com

• Siebel Center is at 40.113813,-88.224671. (latitude,longitude)

• Locations in that format are accepted in the locationboxes.

• What’s the distance to the nearest integer lat/lonintersection, 40,-88?

• How does distance relate to lat/lon? Only lat? Only lon?

7

Page 9: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Matrix Norms i

What norms would we apply to matrices?

• Easy answer: ‘Flatten’ matrix as vector, use vector norm.This corresponds to an entrywise matrix norm called theFrobenius norm,

‖A‖F :=√∑

i,j

a2ij.

8

Page 10: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Matrix Norms ii

• However, interpreting matrices as linear functions, whatwe are really interested in is the maximum amplificationof the norm of any vector multiplied by the matrix,

‖A‖ := max‖x‖=1

‖Ax‖ .

These are called induced matrix norms, as each isassociated with a specific vector norm ‖·‖.

• The following are equivalent:

max‖x‖6=0

‖Ax‖‖x‖ = max

‖x‖6=0

∥∥∥∥∥∥∥∥∥Ax

‖x‖︸︷︷︸y

∥∥∥∥∥∥∥∥∥‖y‖=1= max

‖y‖=1‖Ay‖ = ‖A‖ .

9

Page 11: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Matrix Norms iii

• Logically, for each vector norm, we get a different matrixnorm, so that, e.g. for the vector 2-norm ‖x‖2 we get amatrix 2-norm ‖A‖2, and for the vector∞-norm ‖x‖∞ weget a matrix∞-norm ‖A‖∞.

10

Page 12: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Demo: Matrix norms (click to visit)

In-class activity: Matrix norms

11

Page 13: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Properties of Matrix Norms i

Matrix norms inherit the vector norm properties:

1. ‖A‖ > 0⇔ A 6= 0.2. ‖γA‖ = |γ| ‖A‖ for all scalars γ.3. Obeys triangle inequality ‖A+ B‖ 6 ‖A‖+ ‖B‖

But also some more properties that stem from our definition:

1. ‖Ax‖ 6 ‖A‖ ‖x‖2. ‖AB‖ 6 ‖A‖ ‖B‖ (easy consequence)

Both of these are called submultiplicativity of the matrix norm.

12

Page 14: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Example: Orthogonal Matrices i

What is the 2-norm of an orthogonal matrix?

Linear Algebra recap: For an orthogonal matrix A, A−1 = AT .

In other words: AAT = ATA = I.

Next:‖A‖2 = max

‖x‖2=1‖Ax‖2

where

‖Ax‖2 =√

(Ax)T(Ax) =√xT(ATA)x =

√xTx = ‖x‖2 ,

so ‖A‖2 = 1.

13

Page 15: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Conditioning i

Now, let’s study condition number of solving a linear system

Ax = b.

Input: b with error ∆b,

Output: x with error ∆x.

14

Page 16: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Conditioning ii

Observe A(x +∆x) = (b+∆b), so A∆x = ∆b.

rel err. in outputrel err. in input

=‖∆x‖ / ‖x‖‖∆b‖ / ‖b‖ =

‖∆x‖ ‖b‖‖∆b‖ ‖x‖

=

∥∥A−1∆b∥∥ ‖Ax‖‖∆b‖ ‖x‖

6∥∥A−1∥∥ ‖A‖ ‖∆b‖ ‖x‖

‖∆b‖ ‖x‖=

∥∥A−1∥∥ ‖A‖ .So we’ve found an upper bound on the condition number. Witha little bit of fiddling, it’s not too hard to find examples thatachieve this bound, i.e. that it is tight.

15

Page 17: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Conditioning iii

So we’ve found the condition number of linear system solving,also called the condition number of the matrix A:

cond(A) = κ(A) = ‖A‖∥∥A−1∥∥ .

• cond is relative to a given norm. So, to be precise, use

cond2 or cond∞ .

• If A−1 does not exist: cond(A) = ∞ by convention.

16

Page 19: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

More Properties of the Condition Number i

What is cond(A−1)?

cond(A−1) = ‖A‖ ·∥∥A−1∥∥ = cond(A).

What is the condition number of applying the matrix-vectormultiplication Ax = b? (I.e. now x is the input and b is theoutput)

Let B = A−1.

Then computing b = Ax is equivalent to solving Bb = x.

Solving Bb = x has condition numbercond(B) = cond(A−1) = cond(A).

18

Page 20: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

More Properties of the Condition Number ii

So the operation ‘multiply a vector by matrix A’ has the samecondition number as ‘solve a linear system with matrix A’.

19

Page 21: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Matrices with Great Conditioning (Part 1) i

Give an example of a matrix that is very well-conditioned.(I.e. has a condition-number that’s good for computation.)What is the best possible condition number of a matrix?

Small condition numbers mean not a lot of error amplification.

Small condition numbers are good.

The identity matrix I should be well-conditioned:

‖I‖ = max‖x‖=1

‖Ix‖ = max‖x‖=1

‖x‖ = 1.

It turns out that this is the smallest possible condition number:

1 = ‖I‖ =∥∥A · A−1∥∥ 6 ‖A‖ ·

∥∥A−1∥∥ = κ(A).

20

Page 22: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Matrices with Great Conditioning (Part 1) ii

Both of these are true for any norm ‖·‖.

21

Page 23: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

Matrices with Great Conditioning (Part 2) i

What is the 2-norm condition number of an orthogonal matrixA?

κ2(A) = ‖A‖2∥∥A−1∥∥2 = ‖A‖2

∥∥AT∥∥2 = 1.

That means orthogonal matrices have optimal conditioning.

They’re very well-behaved in computation.

22

Page 24: NormsandErrors · Norms What’sanorm? •Ageneralizationof‘absolutevalue’tovectors. •f(x) : R n!R + 0,returnsa‘magnitude’oftheinputvector •Insymbols:Oftenwrittenkxk.

In-class activity: Matrix Conditioning

23