Least Squares and Data Fitting
Data fitting How do we best fit a set of data points?
Linear Least Squares 1) Fitting with a line Given ๐ data points { ๐ข ! , ๐ง ! , โฆ , ๐ข " , ๐ง " } , we want to find the function ๐ง = ๐ฆ ! + ๐ฆ " ๐ข that best fit the data (or better, we want to find the coefficients ๐ฆ # , ๐ฆ ! ). Thinking geometrically, we can think โwhat is the line that most nearly passes through all the points?โ
Given ๐ data points { ๐ข ! , ๐ง ! , โฆ , ๐ข " , ๐ง " } , we want to find ๐ฆ # and ๐ฆ ! such that ๐ง $ = ๐ฆ # + ๐ฆ ! ๐ข $ โ๐ โ 1, ๐ or in matrix form: Note that this system of ๐ง ! linear equations has more 1 ๐ข ! ๐ฆ # โฎ ๐ฉ ๐ = ๐ โฎ โฎ equations than unknowns โ ๐ฆ ! = ๐ง " 1 ๐ข " OVERDETERMINED SYSTEMS ๐ร๐ ๐ร๐ ๐ร๐ We want to find the appropriate linear combination of the columns of ๐ฉ that makes up the vector ๐ . If a solution exists that satisfies ๐ฉ ๐ = ๐ then ๐ โ ๐ ๐๐๐๐(๐ฉ)
Linear Least Squares โข In most cases, ๐ โ ๐ ๐๐๐๐(๐ฉ) and ๐ฉ ๐ = ๐ does not have an exact solution! โข Therefore, an overdetermined system is better expressed as ๐ฉ ๐ โ ๐
Linear Least Squares โข Least Squares : find the solution ๐ that minimizes the residual ๐ = ๐ โ ๐ฉ ๐ โข Letโs define the function ๐ as the square of the 2-norm of the residual % ๐ ๐ = ๐ โ ๐ฉ ๐ %
Linear Least Squares โข Least Squares : find the solution ๐ that minimizes the residual ๐ = ๐ โ ๐ฉ ๐ โข Letโs define the function ๐ as the square of the 2-norm of the residual % ๐ ๐ = ๐ โ ๐ฉ ๐ % โข Then the least squares problem becomes min ๐ ๐ (๐) โข Suppose ๐: โ " โ โ is a smooth function, then ๐ ๐ reaches a (local) maximum or minimum at a point ๐ โ โ โ " only if โ๐ ๐ โ = 0
How to find the minimizer? โข To minimize the 2-norm of the residual vector % min ๐ ๐ ๐ = ๐ โ ๐ฉ ๐ % ๐ ๐ = (๐ โ ๐ฉ ๐) ( (๐ โ ๐ฉ ๐ ) โ๐ ๐ = 2(๐ฉ ( ๐ โ ๐ฉ ( ๐ฉ ๐) Normal Equations โ solve a linear system of equations First order necessary condition: โ๐ ๐ = 0 โ ๐ฉ ( ๐ โ ๐ฉ ( ๐ฉ ๐ = ๐ โ ๐ฉ ( ๐ฉ ๐ = ๐ฉ ( ๐ Second order sufficient condition: ๐ธ % ๐ ๐ = 2๐ฉ ( ๐ฉ 2๐ฉ ( ๐ฉ is a positive semi-definite matrix โ the solution is a minimum
Linear Least Squares (another approach) โข Find ๐ = ๐ฉ ๐ which is closest to the vector ๐ โข What is the vector ๐ = ๐ฉ ๐ โ ๐ ๐๐๐๐(๐ฉ) that is closest to vector ๐ in the Euclidean norm? When ๐ = ๐ โ ๐ = ๐ โ ๐ฉ ๐ is orthogonal to all columns of ๐ฉ , then ๐ is closest to ๐ ๐ฉ " ๐ฉ ๐ = ๐ฉ " ๐ ๐ฉ ๐ผ ๐ = ๐ฉ ๐ผ (๐ โ ๐ฉ ๐)= 0
Summary: โข ๐ฉ is a ๐ร๐ matrix, where ๐ > ๐ . โข ๐ is the number of data pair points. ๐ is the number of parameters of the โbest fitโ function. โข Linear Least Squares problem ๐ฉ ๐ โ ๐ always has solution. โข The Linear Least Squares solution ๐ minimizes the square of the 2-norm of the residual: % min ๐ โ ๐ฉ ๐ % ๐ โข One method to solve the minimization problem is to solve the system of Normal Equations ๐ฉ ( ๐ฉ ๐ = ๐ฉ ( ๐ โข Letโs see some examples and discuss the limitations of this method.
Example: Solve: ๐ฉ # ๐ฉ ๐ = ๐ฉ # ๐
Data fitting - not always a line fit! โข Does not need to be a line! For example, here we are fitting the data using a quadratic curve. Linear Least Squares : The problem is linear in its coefficients!
Another examples We want to find the coefficients of the quadratic function that best fits the data points: ๐ง = ๐ฆ ! + ๐ฆ " ๐ข + ๐ฆ # ๐ข # We would not want our โfitโ curve to pass through the data points exactly as we are looking to model the general trend and not capture the noise.
Data fitting ๐ง ! " ๐ฆ $ 1 ๐ข ! ๐ข ! Solve: ๐ฉ # ๐ฉ ๐ = ๐ฉ # ๐ ๐ฆ ! โฎ = โฎ โฎ โฎ ๐ฆ " ๐ง # " 1 ๐ข # ๐ข # ( ๐ข $ , ๐ง $ )
Which function is not suitable for linear least squares? A) ๐ง = ๐ + ๐ ๐ฆ + ๐ ๐ฆ # + ๐ ๐ฆ % B) ๐ง = ๐ฆ ๐ + ๐ ๐ฆ + ๐ ๐ฆ # + ๐ ๐ฆ % C) ๐ง = ๐ sin ๐ฆ + ๐/ cos ๐ฆ D) ๐ง = ๐ sin ๐ฆ + ๐ฆ/ cos ๐๐ฆ E) ๐ง = ๐ ๐ &#' + ๐ ๐ #'
Computational Cost ๐ฉ # ๐ฉ ๐ = ๐ฉ # ๐ โข Compute ๐ฉ ( ๐ฉ : ๐ ๐๐ % % ! 2 ๐ 2 , Cholesky โ ๐ โข Factorize ๐ฉ ( ๐ฉ : LU โ ๐ 2 ๐ 2 โข Solve ๐ ๐ % โข Since ๐ > ๐ the overall cost is ๐ ๐๐ %
Short questions Given the data in the table below, which of the plots shows the line of best fit in terms of least squares? A) B) C) D)
Short questions Given the data in the table below, and the least squares model ๐ง = ๐ ! + ๐ % sin ๐ข๐ + ๐ 2 sin ๐ข๐/2 + ๐ 3 sin ๐ข๐/4 written in matrix form as determine the entry ๐ต %2 of the matrix ๐ฉ . Note that indices start with 1. A) โ1.0 B) 1.0 C) โ 0.7 D) 0.7 E) 0.0
Solving Linear Least Squares with SVD
What we have learned so farโฆ ๐ฉ is a ๐ร๐ matrix where ๐ > ๐ (more points to fit than coefficient to be determined) Normal Equations: ๐ฉ ! ๐ฉ ๐ = ๐ฉ ! ๐ The solution ๐ฉ ๐ โ ๐ is unique if and only if ๐ ๐๐๐ ๐ = ๐ โข ( ๐ฉ is full column rank) ๐ ๐๐๐ ๐ = ๐ โ columns of ๐ฉ are linearly independent โ ๐ non-zero โข singular values โ ๐ฉ ! ๐ฉ has only positive eigenvalues โ ๐ฉ ! ๐ฉ is a symmetric and positive definite matrix โ ๐ฉ ! ๐ฉ is invertible ๐ = ๐ฉ ! ๐ฉ "๐ ๐ฉ ! ๐ If ๐ ๐๐๐ ๐ < ๐ , then ๐ฉ is rank-deficient, and solution of linear least squares โข problem is not unique .
Condition number for Normal Equations Finding the least square solution of ๐ฉ ๐ โ ๐ (where ๐ฉ is full rank matrix) using the Normal Equations ๐ฉ ( ๐ฉ ๐ = ๐ฉ ( ๐ has some advantages, since we are solving a square system of linear equations with a symmetric matrix (and hence it is possible to use decompositions such as Cholesky Factorization) However, the normal equations tend to worsen the conditioning of the matrix. ๐๐๐๐ ๐ฉ ( ๐ฉ = (๐๐๐๐ ๐ฉ ) % How can we solve the least square problem without squaring the condition of the matrix?
SVD to solve linear least squares problems ๐ฉ is a ๐ร๐ rectangular matrix where ๐ > ๐, and hence the SVD decomposition is given by: ๐ # โฑ " โฎ โฆ โฎ โฆ ๐ฐ # โฆ ๐ % ๐ฉ = ๐ # โฆ ๐ $ โฎ โฎ โฎ 0 " โฎ โฆ โฎ โฆ ๐ฐ % โฆ โฎ 0 We want to find the least square solution of ๐ฉ ๐ โ ๐ , where ๐ฉ = ๐ฝ ๐ป ๐พ ๐ผ or better expressed in reduced form: ๐ฉ = ๐ฝ 5 ๐ป ๐บ ๐พ ๐ผ
Recall Reduced SVD ๐ > ๐ ๐ฉ = ๐ฝ 4 ๐ป ๐บ ๐พ ๐ผ ๐ร๐ ๐ร๐ ๐ร๐ ๐ร๐
SVD to solve linear least squares problems ๐ฉ = ๐ฝ 4 ๐ป ๐บ ๐พ ๐ผ ( ๐ ! โฎ โฆ โฎ โฆ ๐ฐ ! โฆ ๐ฉ = ๐ ! โฆ ๐ A โฑ โฎ โฎ โฎ ( โฎ โฆ โฎ ๐ A โฆ ๐ฐ A โฆ We want to find the least square solution of ๐ฉ ๐ โ ๐ , where ๐ฉ = ๐ฝ $ ๐ป ๐บ ๐พ ๐ผ Normal equations: ๐ฉ " ๐ฉ ๐ = ๐ฉ " ๐ โถ ๐ฝ & ๐ป ๐บ ๐พ " " ๐ฝ & ๐ป ๐บ ๐พ " ๐ = ๐ฝ & ๐ป ๐บ ๐พ " " ๐ " ๐ฝ & ๐ป ๐บ ๐พ " ๐ = ๐พ ๐ป ๐บ ๐ฝ & " ๐ ๐พ ๐ป ๐บ ๐ฝ & " ๐ ๐พ ๐ป ๐บ ๐ป ๐บ ๐พ " ๐ = ๐พ ๐ป ๐บ ๐ฝ & ( ๐พ " ๐ = ๐ป ๐บ ๐ฝ & " ๐ ๐ป ๐บ When can we take the inverse of the singular matrix?
" ๐พ # ๐ = ๐ป ๐บ ๐ฝ $ # ๐ ๐ป ๐บ 1) Full rank matrix ( ๐ $ โ 0 โ๐ ): Unique solution: rank ๐ฉ = ๐ ! ๐ "' ๐ฝ $ ๐ = ๐พ ๐ป ๐บ # ๐ ๐พ # ๐ = %& ๐ฝ $ ๐ป ๐บ ๐ร1 ๐ร1 ๐ร๐ ๐ร๐ ๐ร๐ 2) Rank deficient matrix ( rank ๐ฉ = ๐ < ๐ ) " ๐พ # ๐ = ๐ป ๐บ ๐ฝ $ # ๐ ๐ป ๐บ Solution is not unique!! " Find solution ๐ such that min ๐ ๐ ๐ = ๐ โ ๐ฉ ๐ " min ๐ ๐ and also ๐
2) Rank deficient matrix (continue) " ๐พ # ๐ = ๐ป ๐บ ๐ฝ $ # ๐ and also satisfies We want to find the solution ๐ that satisfies ๐ป ๐บ min ๐ ๐ ๐ # ๐ for the variable ๐ Change of variables: Set ๐พ # ๐ = ๐ and then solve ๐ป ๐บ ๐ = ๐ฝ $ " ๐ ๐ง + = ๐ + ๐ = 1,2, โฆ , ๐ " ๐ ๐ # ๐ # ๐ง # ๐ + โฎ โฑ โฎ What do we do when ๐ > ๐ ? " ๐ ๐ ) ๐ ) ๐ง ) Which choice of ๐ง + will minimize = ๐ง )*# " ๐ )*# ๐ 0 โฎ โฎ โฑ ๐ ๐ = ๐พ ๐ ๐ ? ๐ง % " ๐ ๐ % 0 ๐ง + = 0, ๐ = ๐ + 1, โฆ , ๐ Set Evaluate ๐ง & ) (๐ * โฎ โฆ โฎ ) # ๐) ๐ง " ๐ = ๐พ๐ = ๐ & โฆ ๐ ) ๐ = 9 ๐ง * ๐ ๐ = 9 ๐ ๐ โฎ ๐ * โฎ โฆ โฎ ๐ง ) *+& *+& - ! ./
Recommend
More recommend