Docsity

Linear Least Squares MATLAB Implementation-Machine Learning-Lecture Slides, Slides of Machine Learning

Partial preview of the text

Download Linear Least Squares MATLAB Implementation-Machine Learning-Lecture Slides and more Slides Machine Learning in PDF only on Docsity!

Chapter 3

Linear Least Squares

(MATLAB Implementation)

Dr. Muhammad Hanif Durad

Department of Computer and Information SciencesPakistan Institute Engineering and Applied Sciences

[email protected]

Most of the codes have been adopted from various books forNumerical Computing using MATLAB their references have beengiven in short on each topic

docsity.com

Dr. Hanif Durad

Lecture Outline (1/2)

Data Fitting (Slides)

Example: Data Fitting (book)

Normal Equations

Orthogonal Projector

Pseudoinverse (book)

Pseudoinverse - MATLAB

Condition Number

docsity.com

Example: Data Fitting (Slides)

>>A=[1 -1.0 1.0; 1 -0.5 0.25; 1 0.0 0.0;1 0.5 0.25;1 1.0 1.0]>> b=[1.0 0.5 0.0 0.5 2.0]‘>>x=A\bx =

Refer EMSE, P-

P-

Dr. Hanif Durad

docsity.com

Example: Data Fitting (book-1/2)

A=[1.

0

0;1.

0.2500;

1.0000;1.

2.2500;

4.0000;1.

6.2500;

9.0000; 1.

12.2500;

16.0000;1.

20.2500;

25.0000;1.

30.2500;

36.0000; 1.

42.2500;

49.0000; 1.

56.2500;

64.0000;1.

72.2500;

81.0000; 1.

10.0000 100.0000]

Dr. Hanif Durad

docsity.com

MATLAB beauty

>>u = linspace(0.0,10,21)'>>x=ones(21,1)>>A=[ ones(21,1) u u.^2]

Dr. Hanif Durad

docsity.com

Normal Equations (1/2)>>A=[1 0 0;0 1 0;0 0 1;-1 1 0;-1 0 1;0 -1 1];

b=[1237 1941 2417 711 1177 475]‘;

>>Y=A'*AY =

>> Z=A'*bZ =

Dr. Hanif Durad

docsity.com

Normal Equations function

format long>> [x,dist] = lsqne(A,b)x =

1.0e+003 *

1.2360000000000001.9430000000000002.

dist =

Dr. Hanif Durad

err = A'(b - Ax)err =

1.0e-012 *-0.

0.6821210263296960.

Tutorial 4, P-

docsity.com

Orthogonal Projector ontoSpan(A)

Dr. Hanif Durad

Pseudoinverse - MATLAB

Dr. Hanif Durad

  • Columns 1 through P=A(A'A)^-1*A'P = - 0. - 0. - 0. - -0. - -0. - 0. - 0. - 0. - 0. - 0. - 0. - 0. - 0. - -0. - 0. - 0. - 0. - -0. - 0. - 0. - 0. - -0. - 0. - -0. - 0.
    • Column - -0. - 0. - -0. - 0.25000.
  • Columns 1 through B = pinv(A)B = - 0. - 0. - 0. - -0. - -0. - 0. - 0. - 0. - 0. - 0. - 0. - 0. - 0. - -0. - 0.
    • Column - 0. - -0. - 0.

Condition Number

>> n = norm(A)n =

>> norm(B)ans =

>> cond(A)ans =

Dr. Hanif Durad

docsity.com

Householder Example (2/2)

>> H*aans =

Try yourself on slides example

Dr. Hanif Durad

docsity.com

Householder QR Factorization(1/4)

P1 = Houspre(u, A)

P1 =

-1.

0

0

0

0

0

-0.

0

-0.

0

-1.

Dr. Hanif Durad

Example 3.8, P-

A=[1 0 0;0 1 0;0 0 1;-1 1 0;-1 0 1;0 -1 1];b=[1237 1941 2417 711 1177 475]';>> u = Housv(A(:,1))u =

0 0

-0.3251-0.

Tutorial 4, P-

→

7

docsity.com

Householder QR Factorization(3/4)

v2(1,1)=0v2 =

0

0

-0.2113-1.

Dr. Hanif Durad

Example 3.8, P-

u = Housv(v2)u =

0.70710.

0

-0.0915-0.

and so on

docsity.com

Householder QR Factorization-Assignment (3/4)^ 

Write a complete program for computingHouseholder QR Factorization suing ideasgiven in functions Housv.m and Houspre.m

Dr. Hanif Durad

docsity.com