The Method of Least Squares. To understand least squares fitting of data.

Similar documents
A widely used display of protein shapes is based on the coordinates of the alpha carbons - - C α

Zeros of Polynomials

Lecture 6 Chi Square Distribution (χ 2 ) and Least Squares Fitting

Lecture 6 Chi Square Distribution (χ 2 ) and Least Squares Fitting

Linear regression. Daniel Hsu (COMS 4771) (y i x T i β)2 2πσ. 2 2σ 2. 1 n. (x T i β y i ) 2. 1 ˆβ arg min. β R n d

Definitions and Theorems. where x are the decision variables. c, b, and a are constant coefficients.

Linear Regression Demystified

3.2 Properties of Division 3.3 Zeros of Polynomials 3.4 Complex and Rational Zeros of Polynomials

CHAPTER 5. Theory and Solution Using Matrix Techniques

Chapter 2 The Solution of Numerical Algebraic and Transcendental Equations

Chapter 4. Fourier Series

6.3 Testing Series With Positive Terms

(A sequence also can be thought of as the list of function values attained for a function f :ℵ X, where f (n) = x n for n 1.) x 1 x N +k x N +4 x 3

Inverse Matrix. A meaning that matrix B is an inverse of matrix A.

September 2012 C1 Note. C1 Notes (Edexcel) Copyright - For AS, A2 notes and IGCSE / GCSE worksheets 1

[ 11 ] z of degree 2 as both degree 2 each. The degree of a polynomial in n variables is the maximum of the degrees of its terms.

Recurrence Relations

U8L1: Sec Equations of Lines in R 2

U8L1: Sec Equations of Lines in R 2

Notes on iteration and Newton s method. Iteration

REGRESSION (Physics 1210 Notes, Partial Modified Appendix A)

Properties and Tests of Zeros of Polynomial Functions

Efficient GMM LECTURE 12 GMM II

Math 155 (Lecture 3)

Algebra of Least Squares

In algebra one spends much time finding common denominators and thus simplifying rational expressions. For example:

Feedback in Iterative Algorithms

CALCULUS BASIC SUMMER REVIEW

SNAP Centre Workshop. Basic Algebraic Manipulation

Sequences A sequence of numbers is a function whose domain is the positive integers. We can see that the sequence

Study the bias (due to the nite dimensional approximation) and variance of the estimators

ECON 3150/4150, Spring term Lecture 3

Last time, we talked about how Equation (1) can simulate Equation (2). We asserted that Equation (2) can also simulate Equation (1).

Problem Set 4 Due Oct, 12

The Discrete Fourier Transform

Optimization Methods MIT 2.098/6.255/ Final exam

A sequence of numbers is a function whose domain is the positive integers. We can see that the sequence

Introduction to Machine Learning DIS10

Unit 4: Polynomial and Rational Functions

Topic 9: Sampling Distributions of Estimators

Eigenvalues and Eigenvectors

Most text will write ordinary derivatives using either Leibniz notation 2 3. y + 5y= e and y y. xx tt t

It is often useful to approximate complicated functions using simpler ones. We consider the task of approximating a function by a polynomial.

Section A assesses the Units Numerical Analysis 1 and 2 Section B assesses the Unit Mathematics for Applied Mathematics

ALGEBRAIC GEOMETRY COURSE NOTES, LECTURE 5: SINGULARITIES.

A NEW CLASS OF 2-STEP RATIONAL MULTISTEP METHODS

Topic 9: Sampling Distributions of Estimators

ANALYSIS OF EXPERIMENTAL ERRORS

3. Z Transform. Recall that the Fourier transform (FT) of a DT signal xn [ ] is ( ) [ ] = In order for the FT to exist in the finite magnitude sense,

Linear Programming and the Simplex Method

Chapter 10: Power Series

Math 475, Problem Set #12: Answers

NUMERICAL METHODS FOR SOLVING EQUATIONS

Outline. Linear regression. Regularization functions. Polynomial curve fitting. Stochastic gradient descent for regression. MLE for regression

, then cv V. Differential Equations Elements of Lineaer Algebra Name: Consider the differential equation. and y2 cos( kx)

EDEXCEL NATIONAL CERTIFICATE UNIT 4 MATHEMATICS FOR TECHNICIANS OUTCOME 4 - CALCULUS

The Growth of Functions. Theoretical Supplement

Find quadratic function which pass through the following points (0,1),(1,1),(2, 3)... 11

Polynomial Functions. New Section 1 Page 1. A Polynomial function of degree n is written is the form:

For a 3 3 diagonal matrix we find. Thus e 1 is a eigenvector corresponding to eigenvalue λ = a 11. Thus matrix A has eigenvalues 2 and 3.

Statistical Inference (Chapter 10) Statistical inference = learn about a population based on the information provided by a sample.

10.6 ALTERNATING SERIES

TEACHER CERTIFICATION STUDY GUIDE

Math 113 Exam 3 Practice

Direction: This test is worth 250 points. You are required to complete this test within 50 minutes.

Linear Regression Models

18.01 Calculus Jason Starr Fall 2005

The picture in figure 1.1 helps us to see that the area represents the distance traveled. Figure 1: Area represents distance travelled

Machine Learning for Data Science (CS 4786)

M A T H F A L L CORRECTION. Algebra I 1 4 / 1 0 / U N I V E R S I T Y O F T O R O N T O

Slide Set 13 Linear Model with Endogenous Regressors and the GMM estimator

Summary and Discussion on Simultaneous Analysis of Lasso and Dantzig Selector

Resampling Methods. X (1/2), i.e., Pr (X i m) = 1/2. We order the data: X (1) X (2) X (n). Define the sample median: ( n.

Section 11.8: Power Series

Topic 9: Sampling Distributions of Estimators

THE UNIVERSITY OF TORONTO UNDERGRADUATE MATHEMATICS COMPETITION. In Memory of Robert Barrington Leigh. March 9, 2014

MATH 304: MIDTERM EXAM SOLUTIONS

5.1. The Rayleigh s quotient. Definition 49. Let A = A be a self-adjoint matrix. quotient is the function. R(x) = x,ax, for x = 0.

Geometry of LS. LECTURE 3 GEOMETRY OF LS, PROPERTIES OF σ 2, PARTITIONED REGRESSION, GOODNESS OF FIT

2 Geometric interpretation of complex numbers

We are mainly going to be concerned with power series in x, such as. (x)} converges - that is, lims N n

TMA4205 Numerical Linear Algebra. The Poisson problem in R 2 : diagonalization methods

PAPER : IIT-JAM 2010

IP Reference guide for integer programming formulations.

x x x 2x x N ( ) p NUMERICAL METHODS UNIT-I-SOLUTION OF EQUATIONS AND EIGENVALUE PROBLEMS By Newton-Raphson formula

Infinite Sequences and Series

Math 113 Exam 3 Practice

Physics 324, Fall Dirac Notation. These notes were produced by David Kaplan for Phys. 324 in Autumn 2001.

Analysis of Experimental Measurements

~j=zhax~ 6=0, t,2... ), k=~

The Phi Power Series

A multivariate rational interpolation with no poles in R m

Chapter 6 Infinite Series

CALCULATION OF FIBONACCI VECTORS

BINOMIAL COEFFICIENT AND THE GAUSSIAN

Chapter 9 - CD companion 1. A Generic Implementation; The Common-Merge Amplifier. 1 τ is. ω ch. τ io

6.867 Machine learning, lecture 7 (Jaakkola) 1

Math 312 Lecture Notes One Dimensional Maps

( a) ( ) 1 ( ) 2 ( ) ( ) 3 3 ( ) =!

MIDTERM 3 CALCULUS 2. Monday, December 3, :15 PM to 6:45 PM. Name PRACTICE EXAM SOLUTIONS

Transcription:

The Method of Least Squares KEY WORDS Curve fittig, least square GOAL To uderstad least squares fittig of data To uderstad the least squares solutio of icosistet systems of liear equatios 1 Motivatio Curve fittig is a process of fidig a relatively simple fuctio to approximate a set of data The data are ofte from experimetal measuremets that may cotai errors or have a limited umber of sigificat digits The approximatig fuctio cotais parameters that ca be adjusted to give agreemet with the data The quality of the fit is most ofte measured by a distace characterizatio betwee values of the approximatig fuctio ad the give data The least squares priciple asserts that the best fit is the oe that miimizes this distace For example, cosider the problem of fittig the data set x x 0 = 0 x 1 = 2 x 2 = 1 x 3 = 4 y y 0 = 2 y 1 = 1 y 2 = 1 y 3 = 3 I stadard polyomial iterpolatio, we would eed to fid a polyomial of degree 3, deoted by p 3 (x), such that p 3 (x i ) = y i, i = 0, 1, 2, 3 If the data ivolve error, this error will be carried over by the iterpolatig polyomial p 3 (x) Now we ask if we ca fit the give data set by usig a straight lie, a polyomial of degree 1 This meas that we eed to fid a polyomial such that p 1 (x) = a 0 + a 1 x (1) p 1 (x i ) = y i, i = 0, 1, 2, 3 (2) Sice a liear fuctio has oly two coefficiets (which ca be cosidered as adjustable parameters), it is geerally impossible to satisfy (2) I other words, i geeral, it is impossible to fid a liear fuctio that iterpolates four poits simultaeously The least squares method fids a liear fuctio p 1 (x) that fits the four poits i a best possible way This procedure ca be described as follows 1

First, we defie the error betwee the straight lie p 1 (x) of (1) ad the give set of data as follows: 3 σ(p 1 ) [p 1 (x i ) y i ] 2 i=0 Next, we adjust the parameters a 0 ad a 1 to miimize the error fuctio σ(p 1 ) To carry out the details for our example, we otice that the error fuctio is really give by 3 σ(p 1 ) = (a 0 + a 1 x i y i ) 2, which ca be expressed as i=0 σ(p 1 ) = (a 0 2) 2 + (a 0 + 2a 1 1) 2 + (a 0 a 1 + 1) 2 + (a 0 + 4a 1 3) 2 The fuctio σ(p 1 ) attais its miimum value at a poit (a 0, a 1 ) where the gradiet of σ(p 1 ) vaishes Therefore, we eed to solve the followig system of liear equatios: σ(p 1 ) a 0 2(a 0 2) + 2(a 0 + 2a 1 1) + 2(a 0 a 1 + 1) + 2(a 0 + 4a 1 3) = 8a 0 + 10a 1 10 = 0, σ(p 1 ) a 1 4(a 0 + 2a 1 1) 2(a 0 a 1 + 1) + 8(a 0 + 4a 1 3) = 10a 0 + 42a 1 30 = 0 This system of liear equatios ca the be rewritte as 4a 0 + 5a 1 = 5, 5a 0 + 21a 1 = 15, which ca be solved usig Gaussia elimiatio to give a 0 = 30 59, a 1 = 35 59 (You ca check this usig the backslash operator i MATLAB) As a result, the straight lie that best fits the give data set i the least squares sese is y = 30 59 + 35 59 x 2 Least Squares Fittig I this sectio, we preset a geeral discussio of least squares fittig of the data {(x r, f r )} As before, we assume that f r = f(x r ) 2

Let q m (x) be a polyomial of degree m with m Observe that q m (x r ) f r is the error i acceptig q m (x r ) as a approximatio to f r Thus the sum of the squares of these errors, σ(q m ) [q m (x r ) f r ] 2, gives a measure of how well q m (x) fits f(x) The idea is that the smaller the value of σ(q m ), the closer the polyomial q m (x) fits the data We say p m (x) is a least squares polyomial of degree m if p m (x) is a polyomial of degree m with the property that σ(p m ) σ(q m ) for all polyomials q m (x) of degree m; usually we oly have equality if q m (x) p m (x) As show i a advaced course i umerical aalysis or liear algebra, if the poits {x r } r=1 are distict ad if m, there is oe ad oly oe least squares polyomial of degree m for these data; thus we say p m (x) is the least squares polyomial of degree m So, the polyomial p m (x) that produces the smallest value σ(p m ) yields the least squares fit of the data While p m (x) produces the best fit of the data i the least squares sese, it may ot produce a very useful fit For example, cosider the case m = The the least squares fit p (x) is the same as the iterpolatig polyomial We have see already that the iterpolatig polyomial ca be a poor fit i the sese of havig a large ad highly oscillatory error So, a close fit i a least squares sese does ot ecessarily imply a very good fit ad, i some cases, the closer the fit is to a iterpolat the less useful it might be Sice the least squares criterio relaxes the fittig coditio from iterpolatio to a weaker coditio o the coefficiets of the polyomial, we eed fewer coefficiets (that is, a lower degree polyomial) i the represetatio As we have idicated, for the problem to be well posed, it is sufficiet that all the data poits be distict ad that m EXAMPLE 1 Cosider the least squares fit to the data i x i f i 0 1 2 1 3 4 2 4 3 3 5 1 by a straight lie: p 1 (x) = a 0 + a 1 x; that is, the coefficiets a 0 ad a 1 are to be determied We have σ(p 1 ) = {p 1 (1) 2} 2 + {p 1 (3) 4} 2 + {p 1 (4) 3} 2 + {p 1 (5) 1} 2 = {a 0 + a 1 2} 2 + {a 0 + 3a 1 4} 2 + {a 0 + 4a 1 3} 2 + {a 0 + 5a 1 1} 2 3

Observe that σ(p 1 ) is quadratic i the ukow coefficiets a 0 ad a 1 For a miimum of σ(p 1 ), the ukows a 0 ad a 1 must satisfy the liear equatios σ(p 1 ) a 0 2 {a 0 + a 1 2} + 2 {a 0 + 3a 1 4} + 2 {a 0 + 4a 1 3} + 2 {a 0 + 5a 1 1} = 20 + 8a 0 + 26a 1 = 0, σ(p 1 ) a 1 2 {a 0 + a 1 2} + 6 {a 0 + 3a 1 4} + 8 {a 0 + 4a 1 3} + 10 {a 0 + 5a 1 1} = 62 + 26a 0 + 102a 1 = 0; that is, Gaussia elimiatio yields the solutio 4a 0 + 13a 1 = 10, (3) 13a 0 + 51a 1 = 31 (4) a 0 = 107 35, a 1 = 6 35 (Agai you ca check this usig the backslash operator i MATLAB) Therefore, the straight lie that best fits the give data set i the least squares sese is p 1 (x) = 107 35 6 35 x It ca be see that the method of least-squares ivolves two mai steps: Formulate the total error Determie parameters (coefficiets) to miimize the total error Geerally, if we cosider fittig data usig a polyomial writte i power series form p m (x) = a 0 + a 1 x + + a m x m, (5) the σ(p m ) is quadratic i the ukow coefficiets a 0, a 1,, a m For the data {(x r, f r )}, we have σ(p m ) = {p m (x r ) f r } 2 (6) = {p m (x 0 ) f 0 } 2 + {p m (x 1 ) f 1 } 2 + + {p m (x ) f } 2 (7) 4

The coefficiets a 0, a 1,, a m are determied by solvig the liear system For each value j = 0, 1,, m, the liear equatio is formed as follows Observe that The, by the chai rule, σ(p m ) a 0 = 0, (8) σ(p m ) a 1 = 0, (9) (10) σ(p m ) a m = 0 (11) σ(p m ) a j = 0 p m (x r ) a j = x j r σ(p m ) [ = {p m (x 0 ) f 0 } 2 + {p m (x 1 ) f 1 } 2 + + {p m (x ) f } 2] (12) a j a j [ = 2 {p m (x 0 ) f 0 } p m(x 0 ) + {p m (x 1 ) f 1 } p m(x 1 ) + + {p m (x ) f } p ] m(x ) (13) a j a j a j [ ] = 2 {p m (x 0 ) f 0 } x j 0 + {p m(x 1 ) f 1 } x j 1 + + {p m(x ) f } x j (14) = 2 {p m (x r ) f r } x j r (15) = 2 x j rp m (x r ) 2 f r x j r (16) Substitutig the power series form for the polyomial p m (x r ), (5), leads to [ ] σ(p m ) = 2 x j r {a 0 + a 1 x r + + a m x m r } f r x j r (17) a j [ ] = 2 a 0 x j r + a 1 x j+1 r + + a m x j+m r f r x j r (18) Therefore, the equatios σ(pm) a j ormal equatios: a 0 x j r + a 1 x j+1 r + + a m = 0, j = 0, 1,, m, may be rewritte as the 5 x j+m r = f r x j r, j = 0, 1,, m

I matrix form, the ormal equatios may be writte as 1 x r x r x2 r xm r xm+1 r xm r xm+1 r x2m r a 0 a 1 a m = f r f rx r f rx m r (19) The coefficiet matrix of this system is symmetric ad positive defiite, permittig use of a accurate, efficiet modified versio of Gaussia elimiatio which exploits these properties, without the eed for partial pivotig by rows for size This ca be doe usig the backslash operator \ i MATLAB (Whe \ is called with a symmetric coefficiet matrix that has positive diagoal elemets, MATLAB determies if the matrix is positive defiite ad, if it is, solves the system i a optimal way Otherwise, it uses Gaussia elimiatio with partial pivotig) EXAMPLE 2 To compute a straight lie fit a 0 +a 1 x to the data {(x r, f r )}, we set m = 1 i the ormal equatios to give a 0 a 0 x r + a 1 1 + a 1 x r = x 2 r = f r, (20) f r x r (21) Substitutig the data i x i f i 0 1 2 1 3 4 2 4 3 3 5 1 from Example 1, we have the ormal equatios 4a 0 + 13a 1 = 10, 13 0 + 51a 1 = 31, which give the same result as i Example 1 The ext example shows how a quadratic polyomial ca be determied i the least squares sese for a give set of data 6

EXAMPLE 3 To compute a quadratic fit a 0 + a 1 x + a 2 x 2 to the data {(x r, f r )}, we set m = 2 i the ormal equatios to give a 0 1 + a 1 x r + a 2 a 0 x r + a 1 x 2 r + a 2 a 0 x 2 r + a 1 x 3 r + a 2 x 2 r = x 3 r = x 4 r = f r, (22) f r x r, (23) f r x 2 r (24) The least squares formulatio permits more geeral fuctios p m (x) tha simply polyomials, but the ukow coefficiets i p m (x) must still occur liearly The most geeral form is p m (x) = a 0 φ 0 (x) + a 1 φ 1 (x) + + a m φ m (x) = m a r φ r (x), where the basis fuctios {φ r (x)} m could be, for example, a liear polyomial splie basis, a cubic polyomial B splie basis, or a set of liearly idepedet trigoometric fuctios By aalogy with the power series case, the liear system of ormal equatios is a 0 φ 0 (x r )φ j (x r )+a 1 φ 1 (x r )φ j (x r )+ +a m φ m (x r )φ j (x r ) = f r φ j (x r ), for j = 0, 1,, m Agai, the coefficiet matrix of this liear system φ 0(x r ) 2 φ 0(x r )φ 1 (x r ) φ 0(x r )φ m (x r ) φ 1(x r )φ 0 (x r ) φ 1(x r ) 2 φ 1(x r )φ m (x r ) φ m(x r )φ 0 (x r ) φ m(x r )φ 1 (x r ) φ m(x r ) 2 is symmetric ad positive defiite 3 Least Squares Solutio of Liear Systems The priciple of least squares ca be used i other situatios As a example, let us attempt to solve a icosistet system of liear equatios of the form: a ij x j = b i, i = 1, 2,, m; (25) j=1 that is Ax = b, 7

where A = (a ij ) m, x = [x 1,, x ] T, b = [b 1,, b m ] T Here, m > ; that is, the umber of equatios is more tha the umber of ukows i the system of liear equatios (25) Geerally speakig, this system of liear equatios is icosistet i the sese that there is o vector x = (x 1,, x ) T which satisfies all the equatios i (25) I this case, a alterative is to miimize the sum of the squares of the residuals to obtai the least squares solutio of the liear system This solutio ca be determied i the followig way The sum of the squares of the residuals is give by 2 m σ(x 1, x 2,, x ) = a ij x j b i To fid the miimizatio poit for the error fuctio σ(x 1, x 2,, x ), we take the partial derivative of σ with respect to each variable x k, yieldig σ m = 2 a ij x j b i a ik, x k j=1 for k = 1, 2, Therefore, the miimizatio poit x = (x 1,, x ) must be a solutio of the liear system By settig j=1 j=1 m m a ij a ik x j = a ik b i, k = 1, 2,, m m c kj = a ij a ik, d k = a ik b i, (26) we see that the miimizatio poit x = (x 1, x 2,, x ) is the solutio of the system of liear equatios: c kj x j = d k, k = 1, 2,, m j=1 EXAMPLE 4 As a example of the least squares solutio of icosistet liear systems, cosider the three equatios i two ukows: x 1 + x 2 = 1, x 1 x 2 = 2, x 1 + 2x 2 = 1, 8

or 1 1 1 1 1 2 ( x1 x 2 ) = 1 2 1 This system of liear equatios is icosistet because it has o solutio at all Now, from (26), we see that c 11 = 3, c 12 = 2, c 21 = 2, c 22 = 6, d 1 = 2, d 2 = 3 Therefore, the least squares solutio must solve the 2 2 liear system The solutio is give by 3x 1 + 2x 2 = 2, (27) 2x 1 + 6x 2 = 3 (28) x 1 = 9 7, x 2 = 13 14 There is a short cut to the least squares formulatio for icosistet liear systems Notice that the matrix C = (c ij ), where c ij is give by (26), is othig but the product of A T ad A; that is, C = A T A, ad the right-had side vector d = (d 1,, d ) T is give by d = A T b Therefore, the least squares solutio of the matrix problem Ax = b is give by the solutio of the ormal equatios A T Ax = A T b The followig summarizes the procedure i the least squares approach for icosistet liear systems of the form Ax = b: Fid the traspose of A, deoted by A T Multiply the system Ax = b by A T : A T Ax = A T b Fid the solutio for the ormal system: A T Ax = A T b The solutio to the ormal system is exactly the least squares solutio of the origial icosistet liear system 9