quiz
play

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: >>>


  1. 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: >>> M=transformation(A) ◮ input: Mat A >>> print(M*A) ◮ output: Mat M such that M ∗ A is a Mat in echelon form A B --------- Your job is to write each of the 0 | one one following procedures: 1 | 0 0 The input to these is a list of Vecs: ◮ null space basis(A) where A is a Mat ◮ rank(L) ◮ solve(A, b) where A is a Mat and b is a Vec ◮ is independent(L) For solve , you can also assume a procedure ◮ basis(L) returns a list of Vecs echelon solve(A,b) that requires A to be in echelon forming a basis for Span L form and solves A x = b .

  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 [0 , 1 , 1] · [1 , − 1 , 1] = 0 ([1 , 2 , 1] + [0 , 1 , 1]) · [1 , − 1 , 1] = 0

  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 projection along a projection orthogonal to a b ||a b ⊥ a + b =

  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 = [ b 1 , b 2 ], a = [1 , 0]. Then b || a = [ b 1 , 0] Note that [ b 1 , 0] = b 1 [1 , 0]. b ⊥ a = b − b || a = [ b 1 , b 2 ] − [ b 1 , 0] = [0 , b 2 ] 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

  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 ( b 1 , b 2 ). (b 1 ,b 2 ) Lemma states: closest point on the line is p = ( b 1 , 0). ◮ For any other point q , the points b = ( b 1 , b 2 ), b || a , and q form a right triangle. ◮ Since q is different from b || a , the base is nonzero. p q ◮ By the Pythagorean Theorem, the hypotenuse’s length is greater than the height. b || a q ◮

  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 � . Let L be the line. Let p = b || a . Let q be any point on L . The Proof: three points q , p , and b form a triangle. b ◮ 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 . q = β a ◮ Hence by the Pythagorean Theorem, p = σ a a || b − q || 2 = || p − q || 2 + || b − p || 2 .

  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 � . Let L be the line. Let p = b || a . Let q be any point on L . The Proof: b 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 . b - q Note b ⊥ a = b − p . ◮ Hence by the Pythagorean Theorem, b - p q || b − q || 2 = || p − q || 2 + || b − p || 2 . p - q p

  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 || .

  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): Almost. return ((b*a)/(a*a))*a Best: def project along(b, a): return ((b*a)/(a*a) if a*a != 0 else 0)*a

  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)

  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

  12. Solution to the fire engine problem Example: a = [6 , 2] and b = [2 , 4]. 6 The closest point on the line { α a : α ∈ R } is the point 5 b || a = σ a where house b 4 a · b = σ a · a 3 how far? 6 · 2 + 2 · 4 = 2 where on line is 6 · 6 + 2 · 2 the closest point? 20 1 = road (line through origin and v ) 40 1 -1 0 1 2 3 4 5 6 = 2 -1 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!

  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.

  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 a 1 , . . . , a n over the reals, find the vector in Span { a 1 , . . . , a n } closest to b . We will study this problem next.

Recommend


More recommend