linear fitting
play

Linear Fitting CS3220 - Summer 2008 Jonathan Kaldor (based on Sp07 - PowerPoint PPT Presentation

Linear Fitting CS3220 - Summer 2008 Jonathan Kaldor (based on Sp07 Slides) From N to M We have been talking about solving linear systems of n equations in n variables In other words, Ax = b where A is n x n Usually: a single


  1. Linear Fitting CS3220 - Summer 2008 Jonathan Kaldor (based on Sp07 Slides)

  2. From N to M • We have been talking about solving linear systems of n equations in n variables • In other words, Ax = b where A is n x n • Usually: a single solution x = b A Square system

  3. From N to M • What happens if the number of equations is not equal to the number of unknowns? • General case: m linear equations in n unknowns • Still expressible as a matrix times a vector... • ...but no longer a square matrix

  4. Rectangular Systems A b x = x = b A Overdetermined Underdetermined (m > n) (m < n)

  5. Rectangular Systems • Still well-defined set of matrix equations • May be full rank but have many solutions (or no exact solutions) • Our focus: m > n (overdetermined systems)

  6. Example 4 2 x 1 2 10 y = 0 2 4 3

  7. Overdetermined Systems • When full rank, extra equations either not necessary or unsatisfiable • Can we even talk about what a solution to this problem is? • Want “best” answer for some definition of “best”

  8. Examples • Model Fitting

  9. Examples • Model Fitting

  10. Examples • Model Fitting • We’ve fit our data points exactly • But do we need to? • Error in experimental results • Fewer dimensions in model • High degree polynomial overfitting data

  11. Examples • Model Fitting

  12. Examples • Model Fitting 1 x 1 d 1 b 1 x 2 d 2 a = 1 x 3 d 3 1 x 4 d 4 ⋮ ⋮ Find best equation ax+b to match data

  13. Examples • Model Fitting 1 x 1 x 12 d 1 c 1 x 2 x 22 d 2 b = 1 x 3 x 32 d 3 a 1 x 4 x 42 d 4 ⋮ ⋮ Find best equation ax 2 + bx + c to match data

  14. Examples • Hugely applicable in sciences • Fitting model to experimental results • Economics • Predicting economic performance from economic indicators • NBA - predicting future performance of draft picks

  15. Back to the Problem • So this is an important problem • ... but we still don’t know what the answer will look like! • In the square system, solved Ax = b , i.e. Ax - b = 0 • In the rectangular system, Ax - b is not necessarily 0 , but instead we can minimize the distance between Ax and b

  16. Vector Distances • How long is this vector? (3,4)

  17. Vector Distances • How long is this vector? (3,4) 5?

  18. Vector Distances • How long is this vector? (3,4) 5? 7?

  19. Vector Distances • How long is this vector? (3,4) 5? 7? Something else?

  20. Vector Distances • Distances (called ‘norms’, denoted with ‖‖ ) • We require four properties: ‖ 0 ‖ = 0 ‖ x ‖ > 0 if x ≠ 0 ‖ c x ‖ = |c| ‖ x ‖ ‖ x + y ‖ ≤ ‖ x ‖ + ‖ y ‖ • Last property: triangle inequality

  21. Vector Distances • Common vector norms: p-norms • ( ∑ |x i | p )^(1/p) • Common cases: • p = 1 (Manhattan distance) • p = 2 (Euclidean distance) • p = infinity (Chebyshev norm)

  22. Vector Distances • Denote particular p-norm with subscript • ‖ x ‖ 1 , ‖ x ‖ 2 , etc... • Note alternate form of 2-norm • sqrt( x T x )

  23. Back to the Problem (Again) • Rectangular systems solved with respect to the 2-norm • x * = min ‖ Ax - b ‖ 2 x = min sqrt( ∑ ( A (i,:)* x - b(i)) 2 ) x = min ∑ ( A (i,:)* x - b(i)) 2 x • We say x * is the least-squares solution to the rectangular system Ax = b , with residual r = Ax * - b

  24. Least Squares • Why the 2-norm? • Intuitive • Sometimes is the ‘proper’ measure • Easy to solve • Of the 3 reasons, third is most important

  25. 2x1 Least Squares • Take a 2x1 example 2 x = 3 1 3

  26. 2x1 Least Squares (3,3) (2,1)

  27. 2x1 Least Squares (3,3) (2,1)

  28. 2x1 Least Squares • Given line and point p , find closest point on line to p • Perpendicular from p to the line • a.k.a. orthogonal projection

  29. Review of Orthogonality • We say two vectors are orthogonal if their dot product is equal to 0 • x T y = ‖ x ‖ 2 ‖ y ‖ 2 cos Θ • If x ≠ 0 and y ≠ 0 , above is zero iff cos Θ = 0, i.e. Θ =± π /2, i.e. they are perpendicular

  30. Review of Orthogonality • We say two vectors are orthonormal if they are orthogonal and ‖ v 1 ‖ 2 = ‖ v 2 ‖ 2 = 1 • Can extend to say sets of n vectors are orthonormal with respect to each other • We say a matrix Q is orthogonal if its columns are all orthonormal with respect to each other • Q T Q = I

  31. Perpendicular Residual • In our 2x1 case, the residual a x - b is orthogonal to the vector a • Leads to a T r = 0 a T ( a x - b ) = 0 a T a x - a T b = 0 a T a x = a T b

  32. 3x2 Case • Trust your geometric intuition • 3x2 case: closest point on plane • Holds in higher dimensions (but best not to try and picture it!)

  33. 3x2 Case • Find closest point on 2D plane defined by vectors a 1 and a 2 (3D vectors) • Residual must be orthogonal to both a 1 and a 2 • Two equations: a 1T r = 0 a 2T r = 0 • Rewrite as a 1T a 1 a 2 x = b a 2T

  34. General Case • Extend this to m equations in n variables • Our residual must be orthogonal to each column in A • Results in n equations, each of the form A (:,i) T r = 0 • Can rewrite as A T Ax = A T b

  35. Normal Equations • This is known as the system of normal equations • The solution to A T Ax = A T b , x * , is the solution to the least squares problem Ax = b • Convert rectangular system into square system, solve using standard techniques (note: can use Cholesky)

  36. Outliers

  37. Outliers

  38. Outliers • Where do they come from? • Error in measurements • User error • Why do they have such an effect? • Least squares

  39. Outliers • How can we handle them? • Toss out worst-fitting points (but need to make sure they really are outliers first!) • Measure error differently

  40. Solving Least Squares in MATLAB • Remember \ ? • Solves rectangular as well as square systems • A \ b will solve the rectangular system Ax = b in the least squares sense • Can also specify multiple right hand sides: A \ B solves AX = B for each column of B

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend