1 / 11

COMP 116: Introduction to Scientific Programming

COMP 116: Introduction to Scientific Programming . Lecture 11: Linear Regression. Revisiting linear programs.

cullen
Télécharger la présentation

COMP 116: Introduction to Scientific Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMP 116: Introduction to Scientific Programming Lecture 11: Linear Regression

  2. Revisiting linear programs • A store has requested a manufacturer to produce pants and sports jackets. For materials, the manufacturer has 750 m2 of cotton textile and 1,000 m2 of polyester. Every pair of pants (1 unit) needs 1 m2 of cotton and 2 m2 of polyester. Every jacket needs 1.5 m2 of cotton and 1 m2 of polyester. The price of the pants is fixed at $50 and the jacket, $40. What is the number of pants and jackets that the manufacturer must give to the stores so that these items obtain a maximum revenue?

  3. Solving linear programs • Design a linear program • What are the unknowns? • What is the cost/objective function? • What are the constraints? • Implement it in Matlab • x=linprog(f,A,b)

  4. Linear Equations • When is there a solution for a m x n matrix A? • A is square (m = n) • A has rank m • Equations are linearly independent • m < n • More unknown than equations • A is underdetermined • m > n • More equations than unknowns • A is overdetermined

  5. Least Squares • Overdetermined systems: too many equations! What to do? • Can’t solve Ax = b exactly • Instead, minimize the “residual” Residual vector: Ax - b Residual square error: (Ax – b)’*(Ax – b) • Matlab command >>x=A\b

  6. Example: Linear Friction • You measured friction in response to a force. What’s the best fitting line to the data?

  7. Example: Linear Friction • You measured friction in response to a force. What’s the best fitting line to the data?

  8. Least Squares % set up and solve matrix % equation A*[m;c] = y A = [x, ones(10,1)]; mc = A\y mc = 2.5121 3.4707 % evaluate error res = A*mc - y; err = res'*res err = 5.8308

  9. Least Squares • In general: Once you have • Mathematical model with parameters • Observed data Fit parameters to data by minimizing sum of squared residuals

  10. Least Squares • Linear least squares if model is linear in the parameters • Written as Ax = b • A, b observed data • x is set of unknowns • Error (scalar): squared residual • (Ax-b)'*(Ax-b)

  11. Same LS principle Minimize sum of squared distance to model (parabola).

More Related