Introduction, basic but important concepts

Similar documents
Solving non-linear systems of equations

Jim Lambers MAT 610 Summer Session Lecture 2 Notes

Numerical Methods I Solving Square Linear Systems: GEM and LU factorization

Numerical Methods I Non-Square and Sparse Linear Systems

Iterative Methods for Solving A x = b

Chapter 1 Mathematical Preliminaries and Error Analysis

Math 471. Numerical methods Introduction

Lecture 7. Floating point arithmetic and stability

Scientific Computing: Dense Linear Systems

Outline. Math Numerical Analysis. Errors. Lecture Notes Linear Algebra: Part B. Joseph M. Mahaffy,

MATH20602 Numerical Analysis 1

MATH20602 Numerical Analysis 1

Numerical Algorithms. IE 496 Lecture 20

CHAPTER 11. A Revision. 1. The Computers and Numbers therein

lecture 2 and 3: algorithms for linear algebra

Sparse Linear Systems. Iterative Methods for Sparse Linear Systems. Motivation for Studying Sparse Linear Systems. Partial Differential Equations

Numerical Methods - Numerical Linear Algebra

Elements of Floating-point Arithmetic

1 Number Systems and Errors 1

Today s class. Linear Algebraic Equations LU Decomposition. Numerical Methods, Fall 2011 Lecture 8. Prof. Jinbo Bi CSE, UConn

Review Questions REVIEW QUESTIONS 71

Next topics: Solving systems of linear equations

Bindel, Fall 2011 Intro to Scientific Computing (CS 3220) Week 3: Wednesday, Jan 9

AMS 147 Computational Methods and Applications Lecture 17 Copyright by Hongyun Wang, UCSC

Solving Linear Systems of Equations

Math 411 Preliminaries

Process Model Formulation and Solution, 3E4

MATH 612 Computational methods for equation solving and function minimization Week # 6

What is it we are looking for in these algorithms? We want algorithms that are

1. Nonlinear Equations. This lecture note excerpted parts from Michael Heath and Max Gunzburger. f(x) = 0

Projection Methods. Felix Kubler 1. October 10, DBF, University of Zurich and Swiss Finance Institute

Review of matrices. Let m, n IN. A rectangle of numbers written like A =

1 ERROR ANALYSIS IN COMPUTATION

LINEAR ALGEBRA: NUMERICAL METHODS. Version: August 12,

COURSE Iterative methods for solving linear systems

Applied Linear Algebra in Geoscience Using MATLAB

Iterative Methods. Splitting Methods

Math/Phys/Engr 428, Math 529/Phys 528 Numerical Methods - Summer Homework 3 Due: Tuesday, July 3, 2018

1 Backward and Forward Error

CME 302: NUMERICAL LINEAR ALGEBRA FALL 2005/06 LECTURE 0

Uniform Random Number Generators

Course Notes: Week 1

Compute the behavior of reality even if it is impossible to observe the processes (for example a black hole in astrophysics).

Numerical Analysis: Solutions of System of. Linear Equation. Natasha S. Sharma, PhD

B553 Lecture 5: Matrix Algebra Review

Lecture Note 7: Iterative methods for solving linear systems. Xiaoqun Zhang Shanghai Jiao Tong University

1.2 Finite Precision Arithmetic

Floating Point Number Systems. Simon Fraser University Surrey Campus MACM 316 Spring 2005 Instructor: Ha Le

Preliminary/Qualifying Exam in Numerical Analysis (Math 502a) Spring 2012

LINEAR SYSTEMS (11) Intensive Computation

Introduction to Applied Linear Algebra with MATLAB

Mathematical preliminaries and error analysis

Bindel, Fall 2016 Matrix Computations (CS 6210) Notes for

Lecture 9. Errors in solving Linear Systems. J. Chaudhry (Zeb) Department of Mathematics and Statistics University of New Mexico

Scientific Computing with Case Studies SIAM Press, Lecture Notes for Unit VII Sparse Matrix

Stability of the Gram-Schmidt process

6. Iterative Methods for Linear Systems. The stepwise approach to the solution...

Numerical Analysis and Computing

Lecture Notes to Accompany. Scientific Computing An Introductory Survey. by Michael T. Heath. Chapter 2. Systems of Linear Equations

Solving Linear Systems

Applied Mathematics 205. Unit 0: Overview of Scientific Computing. Lecturer: Dr. David Knezevic

ECEN 615 Methods of Electric Power Systems Analysis Lecture 18: Least Squares, State Estimation

Lecture 7. Gaussian Elimination with Pivoting. David Semeraro. University of Illinois at Urbana-Champaign. February 11, 2014

Numerical Methods in Informatics

Computational Economics and Finance

Elements of Floating-point Arithmetic

TEACHING NUMERICAL LINEAR ALGEBRA AT THE UNDERGRADUATE LEVEL by Biswa Nath Datta Department of Mathematical Sciences Northern Illinois University

MATH2071: LAB #5: Norms, Errors and Condition Numbers

GAUSSIAN ELIMINATION AND LU DECOMPOSITION (SUPPLEMENT FOR MA511)

forms Christopher Engström November 14, 2014 MAA704: Matrix factorization and canonical forms Matrix properties Matrix factorization Canonical forms

Math 308 Midterm Answers and Comments July 18, Part A. Short answer questions

LU Factorization. Marco Chiarandini. DM559 Linear and Integer Programming. Department of Mathematics & Computer Science University of Southern Denmark

Scientific Computing: Solving Linear Systems

Notes for Chapter 1 of. Scientific Computing with Case Studies

1 Error analysis for linear systems

The Solution of Linear Systems AX = B

Scientific Computing: An Introductory Survey

x x2 2 + x3 3 x4 3. Use the divided-difference method to find a polynomial of least degree that fits the values shown: (b)

A Method for Constructing Diagonally Dominant Preconditioners based on Jacobi Rotations

lecture 3 and 4: algorithms for linear algebra

Chapter 2. Solving Systems of Equations. 2.1 Gaussian elimination

Arithmetic and Error. How does error arise? How does error arise? Notes for Part 1 of CMSC 460

Solving Linear Systems

A primer on matrices

CS 257: Numerical Methods

Computer Arithmetic. MATH 375 Numerical Analysis. J. Robert Buchanan. Fall Department of Mathematics. J. Robert Buchanan Computer Arithmetic

Chapter 2 - Linear Equations

FIXED POINT ITERATIONS

3.2 Iterative Solution Methods for Solving Linear

Binary floating point

6.4 Krylov Subspaces and Conjugate Gradients

Numerical Linear Algebra Primer. Ryan Tibshirani Convex Optimization /36-725

High Performance Nonlinear Solvers

CS 450 Numerical Analysis. Chapter 8: Numerical Integration and Differentiation

Lecture 28 The Main Sources of Error

Matrix Assembly in FEA

EAD 115. Numerical Solution of Engineering and Scientific Problems. David M. Rocke Department of Applied Science

Numerical Linear Algebra

Introduction to Scientific Computing Languages

Numerical Linear Algebra

Transcription:

Introduction, basic but important concepts Felix Kubler 1 1 DBF, University of Zurich and Swiss Finance Institute October 7, 2017 Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 1 / 31

Economics or Math Numerical analysis and scientific computing light-years ahead of us Try to focus on a set of economic problems and search for best methods available for this problem Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 2 / 31

Which language? Matlab Python Julia Fortran/C++ Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 3 / 31

Writing Code Tradeoff between HP-computing and HP-coding But remember that one can reuse parts of good code Also use other people s codes (unless they are economists) Do not drink and code! Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 4 / 31

This week Standard stuff: Non-linear equations, optimization. Somewhat standard stuff: Numerical dynamic programming, projection methods Less standard stuff: Dynamic programming with forward looking constraints, sparse grid methods, applied projection methods Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 5 / 31

8 Chapters 1 Introduction 2 Non-linear equations 3 Non-linear programming 4 Dynamic programming 5 Integration and function approximation 6 Projection Methods 7 High-dimensional projection methods 8 Applications Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 6 / 31

Homeworks Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 7 / 31

Main problem Abstractly, we will try throughout the class to solve the following problem: Find an x such that F(x, d) = 0, where d is a set of data which the solution depends on and F is some functional relation between x and d. In this formulation x can be some element of Euclidean space or a function, while F might be a complicated functional equation or simply a non-linear system of equations. An algorithm can now generally be thought of as a sequence of problems F n (., d) and a sequence of x n such that F n (x n, d) 0. Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 8 / 31

Errors In general there are 2 sources of errors in numerical computations: rounding and truncation errors. Rounding errors are a consequence of using finite precision arithmetic. Truncation errors: Even if one has convergent algorithm, for which lim F n(x n, d) F(x, d), n one only has finite time and has to stop at some N <. Any algorithm we use will therefore stop at some approximation ˆx to a x with F(x, d) = 0. In general, we would be happy with a tiny relative error, i.e. with x ˆx x u. This is called a small forward error. However, in some circumstances all we can hope for is a small backward error, i.e. that F(ˆx, ˆd) = 0 for some ˆd with ˆd d u. Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 9 / 31

Finite precision arithmetics - examples Consider the function f (x) = (1 cos(x))/x 2 with x = 1.2 10 5 the value of cos, rounded to 10 significant digits is c = 0.9999999999 so that 1 cos(x) = 0.00000001 Then (1 c)/x 2 = 10 10 /1.44 10 10 = 0.69... Unfortunately, the correct result is 0.5 Suppose we are trying to solve the quadratic equation Using the simple formula 10 20 x 2 3 10 20 x + 2 10 20 = 0 x = b ± b 2 4ac, 2a the result will almost certainly be NaN. Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 10 / 31

Floating point arithmetics A floating point number system F R is a subset of the reals which is characterized by 4 integer parameters the base β (typically 2) the precision t the exponent range e min e e max The elements of F have the form y = ±β e 0.d 1 d 2,..., d t. In general the numbers in F are not equally spaced. E.g. for β = 2, t = 3, e min = 1 and e max = 3 the non-negative numbers are 0, 0.25, 0.3125, 0.375, 0.4375, 0.5, 0.625, 0.750, 0.875, 1.0, 1.25, 1.5, 1.75, 2.0, 2.5, 3, 3.5, 4.0, 5.0, 6.0, 7.0. Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 11 / 31

Floating point arithmetics (cont.) Most computers and programming languages (e.g. all Intel based computers) use the so called IEEE floating point standard. In this standard there are three precisions with type β t e min e max u IEEE single 2 24-125 128 6 10 8 IEEE double 2 53-1021 1024 1 10 16 IEEE extended 2 64-16381 16384 5 10 20 Where the maximal relative roundoff error (machine precision) is u = 1 2 β1 t. Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 12 / 31

Precision in matlab Typically, matlab uses douvle precision (i.e. 16 digits) The command "digits" can be used to increase presciosion (and decrease speed) Fun to play around with Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 13 / 31

Linear algebra Numerical linear algebra is an extremely well developed field Excellent code in Fortran, C, and Matlab were developed in the 1970 s and 1980 s. One prominent problem is t solve a linear system: Solve Ax = b for a vector x R n, assuming that the n n matrix A is an invertible. Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 14 / 31

Direct methods to solve linear system NEVER use x = A 1 b. Instead: LL (Cholesky) factorization (sparse, symmetric, positive definite) LDL factorization (sparse, symmetric, indefinite) LU factorization (sparse, generic, full rank) QR factorization (dense, generic) USV singular value decomposition (dense, generic) Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 15 / 31

Iterative methods One guesses a starting x 0 then iterates on x k+1 = Bx k + f until x k+1 x k becomes small. Hopefully B and f can be chosen to ensure that x k x 0 for x with Ax = b. Two important methods: Gauss-Seidel and Gauss-Jacobi Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 16 / 31

Gauss-Jacobi For each i = 1,..., n, set x k+1 i = 1 a ii b i n j=1,j i a ij x k j Note that, in this scheme B = I D 1 A where D is a diagonal matrix with the diagonal elements of A on its diagonal, f = D 1 b. Note that, fortunately, x = Bx + f and Ax = b are equivalent. Therefore, if x Bx + f that then Ax b, so if the iterations converge they converge to the right solution. Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 17 / 31

Gauss-Seidel Sometime it is useful to use information from iteration k + 1 already in that iteration. One example is Gauss-Seidel x k+1 i = 1 i 1 n b i a ij x k+1 a j a ij xj k ii j=1 Lower storage requirements. Perhaps faster. j=i+1 Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 18 / 31

Iterative methods (concluded) Methods are easy to code and can solve huge systems Convergence only guaranteed under unrealistic assumptions. Can be very slow, but we can use acceleration methods. For example Chebychev second-order iterative schemes. Here we set α i+1 = ωg(α i ) + (τ ω)α i + (1 τ)α i 1. Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 19 / 31

Conditioning and loss in precision A very important concept is that of a condition number. Badly conditioned system will be difficult or impossible to solve. For linear systems we can make this concrete: Define a matrix norm as follows Ax A = sup x 0 x. The condition-number of a matrix A is defined by κ(a) = A A 1. Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 20 / 31

Conditioning and loss in precision (cont) For small perturbations in linear systems, we have that if A(x + δ x ) = b + δ b then δ x x κ(a) δ b b Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 21 / 31

Conditioning and loss in precision (concl.) Why? δ x x κ(a) δ b b δ x x = δ x b b x = A 1 δ b b Ax x A 1 A δ b b If b has t digits of accuracy then x has t log(κ(a)) digits of accuracy. In this sense log(κ) measures the loss of precision! Check out Matlab command Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 22 / 31

Derivatives In many numerical methods, we need to evaluate not only a non-linear function but also its first (and perhaps even second) derivatives. In practice we often use a numerical approximation to the derivative, the so-called finite difference derivative: f (x) x i f (x + he i) f (x), h where e i is the i th column of the identity matrix and h is an appropriate step-length. This is also sometimes refereed to as one-sided finite differences and there might be situations where it is better to use two-sided finite-differences defined as f (x) f (x + he i) f (x he i ). x i 2h Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 23 / 31

Automatic Differentiation Any high-school student can take derivatives, so we should be able to teach it to a computer. There are programs for Matlab, Fortan, C that do automatic forward differentiation (just google "automatic differentiation matlab") It is more efficient to have Mathematica or other algebraic packages to the differentiation and have it simplify the expression Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 24 / 31

Computational Noise We will often be faced with the problem that we want to minimize (or find the root of) a function that is the result of an elaborate calculation. This calculation could involve approximation of other functions and/or integration. Clearly if we use Monte-Carlo s method for integration this function will be noisy in the sense that we actually want to minimize some other true function but can only compute only a noisy approximation. Even if the computations are deterministic, this will turn out to be a problem because of truncation and rounding errors. In order for many numerical methods to work, this noise should not be too large. It is also easy to see that finite-difference derivatives might be meaningless when there is a lot of noise and, as it turns out, the step-length, h, should depend on the noise in the function. Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 25 / 31

Computational Noise (cont.) Moré and Wild (2011) introduce a very simple workable definition and an algorithm to estimate noise. They assume that the true function f s (x) can only be computed with some random additive element, i.e. f (x) = f s (x) + ɛ(x), x N(x 0 ), where ɛ(x) is a random variable whose distribution is independent of x. They define the noise as the standard deviation of ɛ. Their algorithm ECnoise (that is available in matlab on Stefan Wild s website at Argonne National Lab) takes as given the function sampled at k equi-spaced points and determines the noise. Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 26 / 31

Computational Noise (cont.) The basic idea for the univariate case is as follows. Define 0 f (t) = f (t) and recursively k+1 f (t) = k f (t + h) k f (t) If the true function f s (.) is sufficiently smooth, we obtain that for large k k f (t) = f (s) (ξ)h k + k ɛ(t), for some intermediate value ξ, for sufficiently small h, h k 0 which implies that As it turns out, we have that k f (t) k ɛ(t). var(ɛ) = (k!)2 2k! E(( k ɛ(t)) 2 ) Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 27 / 31

Linear programming We consider the following linear minimization problem under linear constraints. min x R n c T x s.t. Ax + b 0 x 0, where c R n non-zero, A is an m n matrix and b is a m-vector. The dual problem to the above is max b T µ µ R m s.t. A T µ + c 0 µ 0. Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 28 / 31

Linear programming (cont.) Simplex method Interior point method(s) Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 29 / 31

Convergence rates Given a method (e.g. to solve non-linear equations or to optimize) that produces a sequence of iterates (x k ) k=0,1,... converging to the solution of the problem x, we will sometimes be interested how fast does the method converge. The sequence is said to converge linearly, if there exist 0 < q < 1 and k max 0 such that for all k k max x k+1 x q x k x superlinearly, if there exists a sequence q n 0, 0 < q n for all n, and k max 0 such that for all k k max x k+1 x q k x k x quadratically, if there exists a c > 0 and k max 0 such that for all k k max x k+1 x c x k x 2 Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 30 / 31

Parallel computations The trends in hardware design are such that in the near future even ordinary desktops will host dozens of general purpose processors (possibly combined with co-processors and/or GPUs) making the use of parallelization techniques important even for standard users. HPC systems can probably be considered as the most powerful and flexible research instruments available today and allow us to ask questions that would otherwise be impossible to address. Their computational power nowadays often reaches multiple petaflops, with an eleven-year cycle of achieving a three-orders-of-magnitude increase in performance Such systems are difficult to deal with. To use them efficiently, one has to design the software carefully, taking into account the individual advantages that the various (off-the-shelf) hardware components of such machines offer. One needs to move away from Matlab. Felix Kubler Comp.Econ. Gerzensee, Ch1 October 7, 2017 31 / 31