Presentation is loading. Please wait.

Presentation is loading. Please wait.

Least Squares example There are 3 mountains u,y,z that from one site have been measured as 2474 ft., 3882 ft., and 4834 ft.. But from u, y looks 1422 ft.

Similar presentations

Presentation on theme: "Least Squares example There are 3 mountains u,y,z that from one site have been measured as 2474 ft., 3882 ft., and 4834 ft.. But from u, y looks 1422 ft."— Presentation transcript:

1 Least Squares example There are 3 mountains u,y,z that from one site have been measured as 2474 ft., 3882 ft., and 4834 ft.. But from u, y looks 1422 ft. taller and the z looks 2354 ft. taller, and from y, z looks 950 ft. taller. Set up the overdetermined system. 1 0 0 0 1 0 0 0 1 -1 1 0 -1 0 1 0 -1 1 uyzuyz ~ 2474 3882 4834 1422 2354 950 =b Ax= Want to minimize ||Ax-b|| 2

2 Exponential example Assume you are given the following data: 1.3 0.85 0.5 0.4 0.3 0.2 0.15 0.14 0.12 0.11 b 1 2 3 4 5 6 7 8 9 10 t Which you think fits the model b = u + w e -.5t for some values of u and w which you wish to determine so that The Matrix A would look like:

3 Approaches to solve Ax b Normal equations-quick and dirty QR- standard in libraries uses orthogonal decomposition SVD - decomposition which also gives indication how linear independent columns are Conjugate gradient- no decompositions, good for large sparse problems

4 Quick and Dirty Approach Multiply by A T to get the normal equations: A T A x = A T b For the mountain example the matrix A T A is 3 x 3. The matrix A T A is symmetric. However, sometimes A T A can be nearly singular or singular. Consider the matrix A = 1 1 e 0 0 e The matrix A T A = 1+ e 2 1 1 1+ e 2 becomes singular if e is less than the square root of the machine precision.

5 Normal equations for least squares - slide 2 For the hill problem: 3 -1 -1 u -1302 A T A x = -1 3 -1 y = 4354 = A T b -1 -1 3 x 8138 Solution is u =2472, y= 3886, z=4816.

6 Assume the m x n matrix A and the m-vector b can be partitioned into A = R and b = c 0 d where R is a nonsingular n x n matrix and c has length n. Then ||Ax-b|| 2 2 = ||Rx -c || 2 2 + || d || 2 2 So pick x such that ||Rx -c || 2 2 which implies ||Ax-b|| 2 2 = || d || 2 2.This is the best one can do. QR: A more stable approach

7 QR for least squares-slide 2 But most A matrices do not have this form, but using orthogonal transformations we can transform matrices of full column rank to this form. A matrix Q is orthogonal if Q T Q=I. If Q is orthogonal then for any x, ||Qx || 2 2 =||x || 2 2, that is an orthogonal matrix preserves the 2 norm. Examples of orthogonal matrices: 1 00 1cos y sin y 0 11 0-sin y cos y for some angle y Givens rotations

8 QR for least squares -slide 3 We wish to pick a sequence of orthogonal matrices such that A might be transformed into upper triangular form: x x xx x xx x xx x x x x x0 x x0 x x0 x x = R x x x0 x x 0 0 x0 0 x x x x 0 x x0 0 x0 0 0 0 The transformations are then applied to the data vector b The solution is now found by solving Rx =c, where c is the first n elements of the transformed b.

9 QR for least squares -slide 4 Householder transformations of the form I -2uu T / u T u can easily eliminate whole columns. If the A matrix is almost square the QR approach and the normal equations approach require about the same number of operations. If A is tall and skinny, the QR approach takes about the twice number of operations. Good project: Investigate structure of R if A is sparse. Most good least squares solvers use the QR approach. In Matlab: x= A \b.

10 Singular Value Decomposition The singular value decomposition(SVD) of a matrix A is given by A = USV T where U and V are orthogonal and S is a diagonal matrix of the form. If any of the s’s are 0, the matrix is singular. Thus one can determine how close A is to a singular matrix by looking at the smallest s’s. Good project: Investigate an application of SVD

11 SVD for least squares The solution to the least squares problem Ax b is given by x=VS 1 -1 U 1 T b Requires 4 to 10 times more work than QR but shows dependencies in model. If A is an m x n matrix of rank n, then A =USV T = [ U 1 U 2 ] V T = U 1 S 1 V T where U 1 has the first n rows of U and S 1 is n x n.

12 Conjugate gradient Does not require decomposition of matrix Good for large sparse problem-like PET Iterative method that requires matrix vector multiplication by A and A T each iteration In exact arithmetic for n variables guaranteed to converge in n iterations- so 2 iterations for the exponential fit and 3 iterations for the hill problem. Does not zigzag

13 Initialization: Guess x Set r= b-Ax, p = A t r ( p will be a direction), Set γ=p T p Until convergence Set q= Ap, α = γ/q T q Reset x to x + α p Reset r to r - α q Set s = A t r, γ new =s T s, β = γ new / γ, γ = γ new Reset p to s+ β p. Conjugate gradient algorithm

14 Nonlinear example Assume in the exponential example that the model was b = u + we -kt with w added to the list of unknowns. The variable k is nonlinear while u and w are linear. Possible approaches: Treat all three variables as nonlinear and use a nonlinear solver Use a 1-dimensional solver for k and each time a function value is requested one solves for u and w using a linear least squares solver, plug the best value for them in and give back the residual.

15 One dimensional minimization of f(x) Assumption Given an interval [a,b], where one “knows” there is a minimum, that f is unimodal on [a,b], i.e. there is only one local minimum. With this assumption we can find the minimum by sampling and discarding portions of the interval that cannot have the solution. Best algorithms are combinations of golden section search and quadratic interpolation with 3 points and finding minimum of the quadratic-Brent.

16 Golden section on -(2x 3 -9x 2 =12x+6) Originally a =0, x 1 =.7639, x 2 = 1.2361, b=2.0 Subsequent values of a and b ab.76392.0.76391.5279.76391.2361.94431.2361.94431.1246.94431.0557.98681.0557.98681.0294 etc.

17 Unconstrained minimization of f(x) where x has n elements Steepest descent- requires first derivatives (gradient) might zigzag good beginning strategy sped up by conjugate gradient Newton- requires first and second derivatives(Hessian) requires solution of linear system with n variables fast if close to solution Quasi-Newton(most practical)- requires first derivative no linear system to solve builds up approximation to inverse of Hessian

18 Newton’s method for minimization Let g = gradient, H = matrix of second partials Taylor’s Theorem: f(x+s) f(x) + g T s + 0.5 s T Hs. This quadratic function in s is minimized when s =- H -1 g Algorithm:guess x Until convergence Solve H(x) s =- g(x) {needs H and solver} Reset x to x + s

19 Quasi- Newton Method Builds up approximation to Hessian in directions that have been searched Almost as fast as Newton Initial: pick x, set B = I. Until convergence: set s = - Bg (no linear system to solve) set x new = x+s let γ= g(x new ) -g(x); δ = x new - x; x= x new reset B to B + δ δ T / δ T γ - B γ (B γ) T / γ T B γ

20 Comparison of steepest descent, Newton, and quasi Newton on f(x) = 0.5x 1 2 + 2.5x 2 2 IterationSteepestNewtonQuasi-Newton 13.333-0.6670.000.000.00-4.00 22.2220.444-2.2220.444 31.481-0.2960.8160.082 40.9880.198-0.009-0.015 50.658-0.132-0.0010.001 60.4390.088 70.293-0.059

21 Large Scale Problems Conjugate gradient vs. Limited Memory Quasi-Newton Conjugate gradient- each step is linear combination of previous step and current gradient Limited Memory-(Nocedal,Schnabel, Byrd, Kaufman) Do not multiply B out but keep vectors. Need to keep 2 vectors per iteration After k steps(k is about 5) reset B to I and start again. Experimentation favors LMQN over CG Good project: How should LMQN be done

Download ppt "Least Squares example There are 3 mountains u,y,z that from one site have been measured as 2474 ft., 3882 ft., and 4834 ft.. But from u, y looks 1422 ft."

Similar presentations

Ads by Google