Quiz You are given a procedure A = Mat(({a,b},{A,B}), - - PowerPoint PPT Presentation

quiz
SMART_READER_LITE
LIVE PREVIEW

Quiz You are given a procedure A = Mat(({a,b},{A,B}), - - PowerPoint PPT Presentation

Quiz You are given a procedure A = Mat(({a,b},{A,B}), {(a,A):one, transformation(A) with the (b,B):one,(a,B):one, (b,A):one}) following spec: >>>


slide-1
SLIDE 1

Quiz

You are given a procedure transformation(A) with the following spec:

◮ input: Mat A ◮ output: Mat M such that M ∗ A

is a Mat in echelon form Your job is to write each of the following procedures: A = Mat(({’a’,’b’},{’A’,’B’}), {(’a’,’A’):one, (’b’,’B’):one,(’a’,’B’):one, (’b’,’A’):one}) >>> M=transformation(A) >>> print(M*A) A B

  • |
  • ne one

1 | The input to these is a list of Vecs:

◮ rank(L) ◮ is independent(L) ◮ basis(L) returns a list of Vecs

forming a basis for Span L

◮ null space basis(A) where A is a Mat ◮ solve(A, b) where A is a Mat and b is a Vec

For solve, you can also assume a procedure echelon solve(A,b) that requires A to be in echelon form and solves Ax = b.

slide-2
SLIDE 2

Properties of orthogonality

To solve the Fire Engine Problem, we will use the Pythagorean Theorem in conjunction with the following simple observations: Orthogonality Properties: Property O1: If u is orthogonal to v then u is orthogonal to α v for every scalar α. Property O2: If u and v are both orthogonal to w then u + v is orthogonal to w. Proof:

  • 1. u, α v = α u, v = α 0 = 0
  • 2. u + v, w = u, w + v, w = 0 + 0

Example: [1, 2] · [2, −1] = 0 so [1, 2] · [20, −10] = 0 Example: [1, 2, 1] · [1, −1, 1] = [0, 1, 1] · [1, −1, 1] = ([1, 2, 1] + [0, 1, 1]) · [1, −1, 1] =

slide-3
SLIDE 3

Decomposition of b into parallel and perpendicular components

Definition: For any vector b and any vector a, define vectors b||a and b⊥a to be the projection of b onto Span {a} and the projection of b orthogonal to a if

b = b||a + b⊥a

and there is a scalar σ ∈ R such that

b||a = σ a

and

b⊥a is orthogonal to a

b b||a b⊥ a

projection along a projection orthogonal to a

b = +

slide-4
SLIDE 4

Decomposition of b into b||a and b⊥a

b = b||a + b⊥a and there is a scalar σ ∈ R such that b||a = σ a and b⊥a is orthogonal to a

Example: b = [b1, b2], a = [1, 0]. Then b||a = [b1, 0] Note that [b1, 0] = b1 [1, 0].

b⊥a = b − b||a = [b1, b2] − [b1, 0] = [0, b2]

Example: b = [10, 20, 30] and a = [−1, 2, 1]. I claim b||a = [−10, 20, 10] and therefore b⊥a = [10, 20, 30] − [−10, 20, 10] = [20, 0, 20]. Are these correct?

◮ Check if b||a = σa for some σ... Yes, σ = 10 ◮ Check if b⊥a is orthogonal to a... [20, 0, 20] · [−1, 2, 1] = 0, so yes

slide-5
SLIDE 5

Orthogonality helps solve the fire engine problem

Fire Engine Lemma:

◮ Let b be a vector. ◮ Let a be a nonzero vector ◮

Then b||a is the point on the line {α a : α ∈ R} that is closest to b, and the distance is b⊥a. Example: Line is the x-axis, i.e. the set {(x, y) : y = 0}, and point is (b1, b2). Lemma states: closest point on the line is p = (b1, 0).

◮ For any other point q, the points b = (b1, b2), b||a, and q

form a right triangle.

◮ Since q is different from b||a, the base is nonzero. ◮ By the Pythagorean Theorem, the hypotenuse’s length is

greater than the height.

q b||a

(b1,b2) p q

slide-6
SLIDE 6

Orthogonality helps solve the fire engine problem

Fire Engine Lemma:

◮ Let b be a vector. ◮ Let a be a nonzero vector ◮

Then b||a is the point on the line {α a : α ∈ R} that is closest to b, and the distance is b⊥a. Proof: Let L be the line. Let p = b||a. Let q be any point on L. The three points q, p, and b form a triangle.

◮ Since p and q are both on L, they are both multiples of a, so their

difference p − q is also a multiple of a.

◮ Hence, since b⊥a is orthogonal to a, it is also orthogonal to p − q.

Note b⊥a = b − p.

◮ Hence by the Pythagorean Theorem,

||b − q||2 = ||p − q||2 + ||b − p||2.

b p = σ a q = β a

a

slide-7
SLIDE 7

Orthogonality helps solve the fire engine problem

Fire Engine Lemma:

◮ Let b be a vector. ◮ Let a be a nonzero vector ◮

Then b||a is the point on the line {α a : α ∈ R} that is closest to b, and the distance is b⊥a. Proof: Let L be the line. Let p = b||a. Let q be any point on L. The three points q, p, and b form a triangle.

◮ Since p and q are both on L, they are both multiples of a, so their

difference p − q is also a multiple of a.

◮ Hence, since b⊥a is orthogonal to a, it is also orthogonal to p − q.

Note b⊥a = b − p.

◮ Hence by the Pythagorean Theorem,

||b − q||2 = ||p − q||2 + ||b − p||2.

b p q p - q b - p b - q

slide-8
SLIDE 8

Decomposition of b into parallel and perpendicular components: example

For any vector b and any vector a, define vectors b||a and b⊥a ....

◮ b = b||a + b⊥a, and ◮ there is a scalar σ ∈ R such that

b||a = σ a, and

◮ b⊥a is orthogonal to a

Example: What if a is the zero vector? In this case, the only vector b||a satisfying the second equation is the zero vector. According to first equation, b⊥a must equal b. Fortunately, this choice of b⊥a does satisfy third equation: b⊥a is orthogonal to a. Indeed, every vector is orthogonal to a when a is the zero vector. What is the point in Span {0} closest to b? The only point in Span {0} is the zero vector... so that must be the closest point to b, and the distance to b is ||b||.

slide-9
SLIDE 9

Computing the projections

b = b||a + b⊥a b||a = σ a b⊥a is orthogonal to a

If a = 0 then b||a = 0 What if a = 0? Need to compute σ....

  • b⊥a, a
  • = 0. Substitute for b⊥a:
  • b − b||a, a
  • = 0.

◮ Substitute for b||: b − σ a, a = 0. ◮ Using linearity and homogeneity of inner product,

b, a − σ a, a = 0

◮ Solving for σ, we obtain

σ =

b,a

  • a,a

In the special case in which a = 1, the denominator a, a = 1 so σ = b, a Quiz: Write project along(b, a) to return the vector b||a Answer: def project along(b, a): return ((b*a)/(a*a))*a Almost. Best: def project along(b, a): return ((b*a)/(a*a) if a*a != 0 else 0)*a

slide-10
SLIDE 10

Computing the projections

b = b||a + b⊥a b||a = σ a b⊥a is orthogonal to a

◮ σ = b,a

  • a,a

◮ However, if a = 0 then σ = 0. ◮ def project_along(b, a):

sigma = (b*a)/(a*a) if a*a != 0 else 0 return sigma * a Quiz: Use project along(b, a) to write the procedure project orthogonal 1(b, a) that returns b⊥a def project orthogonal 1(b, a): return b - project along(b, a)

slide-11
SLIDE 11

Projecting along “nearly zero” vectors

Mathematically, this procedure is correct: def project_along(b, a): sigma = (b*a)/(a*a) if a*a != 0 else 0 return sigma * a However, because of floating-point roundoff error, we need to make a slight change. Often the vector a will be not a truly zero vector but practically it will be zero. If the entries of a are tiny, the procedure should treat a as a zero vector: sigma should be assigned zero. We will consider a to be a zero vector if its squared norm is no more than, say, 10−20. Revised version: def project_along(b, a): sigma = (b*a)/(a*a) if a*a > 1e-20 else 0 return sigma * a

slide-12
SLIDE 12

Solution to the fire engine problem

Example:

a = [6, 2] and b = [2, 4].

The closest point on the line {α a : α ∈ R} is the point

b||a = σ a where

σ =

a · b a · a

= 6 · 2 + 2 · 4 6 · 6 + 2 · 2 = 20 40 = 1 2

  • 1

1 2 3 4 5 6

  • 1

1 2 3 4 5 6

house b road (line through origin and v)

where on line is the closest point? how far?

Thus the point closest to b is 1

2 [6, 2] = [3, 1].

The distance to b is b⊥a = [2, 4] − [3, 1] = [−1, 3] = √ 10 which is just under 3.5, the length of the firehose. The house is saved!

slide-13
SLIDE 13

Best approximation

The fire engine problem can be restated as finding the vector on the line that “best approximates” the given vector b. By “best approximation”, we just mean closest. This notion of “best approximates” comes up again and again:

◮ in least-squares, a fundamental data analysis technique, ◮ image compression, ◮ in principal component analysis, another data analysis technique, and ◮ in latent semantic analysis, an information retrieval technique.

slide-14
SLIDE 14

Towards solving the higher-dimensional version of best approximation

The fire engine problem can be stated thus: Computational Problem: Closest point in the span of a single vector Given a vector b and a vector a over the reals, find the vector in Span {a} closest to b. A natural generalization of the fire engine problem is this: Computational Problem: Closest point in the span of several vectors Given a vector b and vectors a1, . . . , an over the reals, find the vector in Span {a1, . . . , an} closest to b. We will study this problem next.