• No results found

A study of QR decomposition and Kalman filter implementations

N/A
N/A
Protected

Academic year: 2022

Share "A study of QR decomposition and Kalman filter implementations"

Copied!
73
0
0

Loading.... (view fulltext now)

Full text

(1)

A study of QR decomposition and Kalman filter implementations

DAVID FUERTES RONCERO

Master’s Degree Project Stockholm, Sweden September 2014

XR-EE-SB 2014:010

(2)
(3)

A study of QR decomposition and Kalman filter implementations

DAVID FUERTES RONCERO

Stockholm 2014 Signal Processing

School of Electrical Engineering

Kungliga Tekniska Hgskolan

XR-EE-SB 2014:010

(4)
(5)

Abstract

With the rapid development of new technologies during the last decades, the demand of complex algorithms to work in real-time applications has in- creased considerably. To achieve the real time expectations and to assure the stability and accuracy of the systems, the application of numerical meth- ods and matrix decompositions have been studied as a trade-off between complexity, stability and accuracy. In the first part of this thesis, a survey of state-of-the-art QR Decomposition methods applied to matrix inversion is done. Stability and accuracy of these methods are analyzed analytically and the complexity is studied in terms of operations and level of parallelism.

Besides, a new method called Modified Gaussian Elimination (MGE) is pro- posed. This method is shown to have better accuracy and less complexity than the previous methods while keeping good stability in real time appli- cations. In the second part of this thesis, different techniques of extended Kalman Filter implementations are discussed. The EKF is known to be nu- merically unstable and various methods have been proposed in the literature to improve the performance of the filter. These methods include square-root and unscented versions of the filter that make use of numerical methods such as QR, LDL and Cholesky Decomposition. At the end of the analysis, the audience/reader will get some idea about best implementation of the filter given some specifications.

3

(6)
(7)

Acknowledgment

The completion of this thesis would not have been possible without the par- ticipation and support of many people, so I would like to dedicate some words to thank all the people that has make this thesis possible.

First of all, I would like to thank my supervisor Satyam Dwivedi for giving me the opportunity of working in that project with him and helping me in the hard moments. I have enjoyed all the moments of my research, and I really appreciate the opportunity to study state-of-the-art publications that make an actual impact in the real world. My work in this thesis have also encourage me to focus my career in research.

I need also to thank my parents, my sister and the rest of my family for their unconditional support. Without their support during all the years of my life, I would not have become the person that I am today, for which I will be eternally grateful.

Finally, but not less important, I want to thank all my friends and all the people that I have known here and have make me feel like home. Specially, I want to thank to Pedro, Dani, Julia, Cesc, Pablo, Gonzalo and Carles for all the good and bad moments that we have lived together during our five years at university. Thanks to you, this is a period of my life that I will never forget. I can not finish without saying thanks to Xavi, Albert, Adrian, Aida, Marcos, Sergi and Marina for being my friends. I know that no matter the distance, you will always be there if I need you.

I

(8)
(9)

Contents

1 Introduction 1

1.1 Motivation . . . 1

2 QR Decomposition 3 2.1 Algorithms . . . 4

2.1.1 Householder Reflectors (HR) . . . 4

2.1.2 Modified Gram-Schmidt (MGS) . . . 5

2.1.3 Givens Rotations (GR) . . . 6

2.1.4 CORDIC Givens Rotations(CORDIC) . . . 7

2.1.5 Modified Squared Givens Rotations (MSGR) . . . 8

2.1.6 Modified Gaussian Elimination (MGE) . . . 9

2.2 Computation complexity . . . 12

2.3 Numerical properties . . . 14

2.4 Floating Points Results . . . 16

2.5 Fixed Point Results . . . 17

2.5.1 64 bits fixed points . . . 17

2.5.2 32 bits fixed points . . . 19

2.5.3 16 bits fixed points . . . 19

2.6 Implementation of MGE . . . 24

2.7 Conclusions . . . 26

3 Kalman Filter 27 3.1 Vehicle Model . . . 28

3.2 Extended Kalman Filters . . . 29

3.2.1 QR-EKF . . . 30

3.2.2 LDL-EKF . . . 32

3.3 Unscented Kalman Filters . . . 36

3.3.1 UKF . . . 36

3.3.2 SR-UKF . . . 39

3.4 Analysis Complexity . . . 42

3.5 Results . . . 42 III

(10)

IV CONTENTS

3.5.1 QR-EKF . . . 43

3.5.2 LDL-EKF . . . 43

3.5.3 UKF . . . 44

3.5.4 SR-UKF . . . 47

3.6 Study divergence of UKF . . . 47

3.7 Conclusions . . . 50

4 Conclusions 53 4.1 Future Work . . . 54

A Number of operations QR 57

(11)

List of Figures

2.1 Relative errors of R-1 using double precision floating points . . 17

2.2 Relative errors of QH using double precision floating points . . 18

2.3 Relative errors of A-1 using double precision floating points . . 18

2.4 Relative errors of R-1 using 64-bits fixed points . . . 19

2.5 Relative errors of QH using 64-bits fixed points . . . 20

2.6 Relative errors of A-1 using 64-bits fixed points . . . 20

2.7 Relative errors of R-1 using 32-bits fixed points . . . 21

2.8 Relative errors of QH using 32-bits fixed points . . . 21

2.9 Relative errors of A-1 using 32-bits fixed points . . . 22

2.10 Relative errors of R-1 using 16-bits fixed points . . . 22

2.11 Relative errors of QH using 16-bits fixed points . . . 23

2.12 Relative errors of A-1 using 16-bits fixed points . . . 23

2.13 (a) Systolic array for the computation of QR using Gaussian Elimination (3 × 3 matrix), (b) Inputs of the systolic array. . . 24

2.14 Detail of the Circle Block. (a) Inputs and Outputs of the block. (b) Code of the block. . . 25

2.15 Detail of the Square Block. (a) Inputs and Outputs of the block. (b) Code of the block. . . 25

3.1 Unscented Transform. The Figure was obtained from [1] . . . 36

3.2 Predicted variance of the estimates for the QR-EKF . . . 43

3.3 Track estimate for the QR-EKF . . . 44

3.4 Predicted variance of the estimates for the LDL-EKF . . . 45

3.5 Track estimate for the LDL-EKF . . . 45

3.6 Predicted variance of the estimates for the UKF . . . 46

3.7 Track estimate for the UKF . . . 46

3.8 Divergence of the estimate of the track using UKF . . . 47

3.9 Predicted variance of the estimates for the SR-UKF . . . 48

3.10 Track estimate for the SR-UKF . . . 48

3.11 Confidence area of state estimate at iteration 13, 14 and 15 . . 49

3.12 Confidence area of measurements at iteration 16, 17 and 18 . . 50 V

(12)

VI LIST OF FIGURES 3.13 Confidence area of state estimate at iteration 13, 14 and 15

using the modified UKF . . . 51 3.14 Confidence area of measurements at iteration 16, 17 and 18

using the modified UKF . . . 51 3.15 Divergence of track estimate using the modified UKF . . . 52 3.16 Divergence of track estimate using the modified UKF (longer

simulation) . . . 52

(13)

List of Tables

2.1 Asymptotic number of operations for QR based matrix inverse

(n × n matrix) . . . 13

3.1 Number of operations of QR-EKF . . . 32

3.2 Number of operations of LDL-EKF . . . 35

3.3 Number of operations of UKF . . . 39

3.4 Number of operations of SR-UKF . . . 42

3.5 Comparison of the asymptotic cost of the filters . . . 42

A.1 Number of operations to compute QR decomposition . . . 57

VII

(14)

VIII LIST OF TABLES

(15)

List of Algorithms

1 Backward Substitution . . . 4

2 Householder Reflectors . . . 5

3 Modified Gram-Schmidt . . . 6

4 Givens Rotations . . . 8

5 CORDIC Givens Rotations . . . 9

6 MSGR . . . 10

7 Modified Gaussian Elimination . . . 12

8 QR-EKF . . . 31

9 LDL Decomposition . . . 33

10 LDL-EKF . . . 34

11 Modified Givens Rotations . . . 35

12 UKF . . . 37

13 Cholesky Decomposition . . . 38

14 SR-UKF . . . 40

15 Rank-one Update . . . 41

IX

(16)

X LIST OF ALGORITHMS

(17)

Chapter 1 Introduction

1.1 Motivation

With the rapid development of new technologies during the last decades, the demand of complex algorithms to work in real-time applications has increased considerably. To achieve the real time expectations and to assure the stabil- ity and accuracy of the systems, the application of numerical methods and matrix decompositions have been studied as a trade-off between complexity, stability and accuracy.

Matrix inversion is one the most important operations in signal processing and is present in many areas such as positioning systems, wireless communi- cations or image processing. The computation of a matrix inverse grows in exponent with the matrix dimension and can introduce errors and instabilities in the system. For this reason, it is worthy to study all the existing methods to accelerate the computation and assure the stability of the operation. The methods developed during the last decades rely on matrix decompositions to reduce complexity. These decompositions include SVD, QR Decomposition and LU Decomposition. QR Decomposition is the most widely used since assures stability and have less complexity. In the first part of the thesis, a survey of the state-of-the-art QR Decomposition methods applied to matrix inversion is done. The stability and accuracy of these methods are analysed analytically and the complexity is studied in terms of operations and level of parallelism. Besides, a new method called Modified Gaussian Elimination (MGE) is proposed. This method is shown to have better accuracy and less complexity than the previous methods while keeping good stability in real applications.

In the second part of the thesis, different techniques of Extended Kalman Filter implementations are discussed. The EKF is known to be numerically

1

(18)

2 CHAPTER 1. INTRODUCTION unstable and various methods have been proposed in the literature to im- prove the performance of the filter. These methods include square-root and unscented versions of the filter that make use of numerical methods such as QR, LDL and Cholesky Decomposition. Different implementations of these methods applied to EKF have been studied for trade-off between complexity and accuracy. At the end of the analysis, the audience/reader will get some idea about best implementation of the filter given some specifications.

(19)

Chapter 2

QR Decomposition

First of all, lets introduce QR Decomposition. In QR decomposition, an A matrix of size m × n is written as the product of an upper-triangular matrix R of size m × n and an orthogonal matrix Q of size m × m

A = QR. (2.1)

After decomposing matrix A in the QR form, A-1can be easily computed as

A-1 = R-1Q-1 = R-1QH, (2.2) where R-1 can be computed using backward substitution (2.3), leading to a much more faster and efficient computation than the direct inversion of matrix A. The algorithm is given in Alg. 1.

r−1j,i = −Pi−1k=jrj,k+1rk+1,i−1

rj,j . (2.3)

The most common methods to obtain QR are Householder Reflectors (HR) [2], Modified Gram-Schmidt (MGS) [3] and Givens Rotations (GR) [2]. CORDIC functions can also be used to obtain the QR Decomposition using vectoring and rotation mode to perform angle calculations and rotation operations directly [4]. To reduce complexity and improve the numerical properties of the transformation, new methods such as Modified Squared Givens Rotations (MSGR) [5] have been proposed recently to avoid the use of costly operations such as square roots. This method was developed to compute the QR Decomposition and matrix inverse of complex matrices, but can also be applied in the real case.

This chapter is organized as follows. In Section 2.1 all the mentioned methods, as well as MGE, are introduced, the algorithms are given and the

3

(20)

4 CHAPTER 2. QR DECOMPOSITION Algorithm 1: Backward Substitution

1 R0 = 0n×n

2 for i = n to 1 do

3 R0i,i = 1/Ri,i

4 for j = i - 1 to 1 do

5 for k = j to i-1 do

6 R0j,i = R0j,i− Rj,k+1R0k+1,i

7 end

8 R0j,i = R0j,i/Rj,j

9 end

10 end

operations that can introduce errors and instabilities are discussed. In Sec- tion 2.2 the complexity of the methods in terms of number of operations is studied, numerical properties are studied in Section 2.3, an efficient imple- mentation of MGE is proposed in 2.6 and finally the conclusions are given in Section 2.7.

2.1 Algorithms

In this section, the methods for computing QR Decomposition are briefly described, the algorithms are given and the operations involve are discuss in detail with a remark in the operations that can cause over/under-flows and introduce large errors.

2.1.1 Householder Reflectors (HR)

Householder’s method is based on the idea of multiplying matrix A by a set of orthogonal matrices such that every matrix put zeros below the diagonal of each column. The method is detailed in [2]. Doing that we obtain matrix R as

x x x x x x x x x x x x x x x x

 Q1

x x x x 0 x x x 0 x x x 0 x x x

 Q2

x x x x 0 x x x 0 0 x x 0 0 x x

 Q3

x x x x 0 x x x 0 0 x x 0 0 0 x



. (2.4)

To obtain matrix Q we just need to multiply and transpose all the or- thogonal matrices

Q1Q2...Qn = Q-1 = QH. (2.5)

(21)

2.1. ALGORITHMS 5 The computation of Q-1 is very straightforward if we see the transforma- tion as a product of matrices

Q1Q2...QnA = R, (2.6) so

Q-1 = Q1Q2...Qn. (2.7)

Then Q-1 is obtain applying the same transformations to the Identity Matrix than to matrix A

Q-1I = Q-1 = QH. (2.8) The algorithm is given in Alg. 2. Looking at the operations, a large num- ber of multiplications is needed to compute the norm operations in lines 5 and 7 and the vector operation in line 8. These operations not only increase the complexity of the algorithm, they also generate very large numbers that increase the dynamic range of the algorithm, incrementing the quantization errors and leading to overflows if the input is not properly normalized. Be- sides, the square root in line 6 and the division in line 9 are complex to compute in processors.

Algorithm 2: Householder Reflectors

1 R = A

2 Q = In×n

3 for k = 1 to n do

4 v = Rk:n,k

5 a =||v||22

6 v1 = v1+ sign(v1)√ a

7 a =||v||22

8 B =vv0

9 F = I − 2aB

10 Rk:n,k:n = FRk:n,k:n

11 Qk:n,1:n = FQk:n,1:n

12 end

2.1.2 Modified Gram-Schmidt (MGS)

The Gram-Schmidt process is a method for orthonormalising a set of vectors, in our case the columns of matrix A. The process finds orthonormal vectors

(22)

6 CHAPTER 2. QR DECOMPOSITION that span the successive spaces spanned by the columns of A. That means that the first column of A (a1) only depends on one vector (q1), the second column of A (a2) only depends on the previous vector and a new orthogonal vector (q2), the third column of A (a3) only depends on the two previous orthogonal vectors and a new vector orthogonal to the previous ones (q3) and so on. That leads directly to the QR decomposition

(a1 a2 a3 ··· an) = (q1 q2 q3··· qn)

r11 r12 r13 ··· r1n

r22 r23 ··· r2n

r33 ··· r2n

... ...

rnn

. (2.9) The classical Gram-Schmidt process is known to be numerically unstable and very sensible to rounding errors, which cause a lose of orthogonality in the vectors qj. However, a different approach called Modified Gram-Schmidt using the same idea is less sensible to rounding errors and therefore have better numerical properties [3].

The algorithm is given in Alg. 3. In the case of MGS, the most critical operations are the multiplications in lines 6 and 7 and the norm computation in line 9. Divisions and square roots are also computed in lines 9 and 10.

Algorithm 3: Modified Gram-Schmidt

1 R = 0n×n 2 Q = In×n

3 for j = 1 to n do

4 w1:n,j = A1:n,j

5 for i = 1 to j-1 do

6 Ri,j = w01:n,jQ1:n,i

7 w1:n,j = w1:n,j − Ri,jQ1:n,i

8 end

9 Rj,j =qw01:n,jw1:n,j 10 Q1:n,j = wr1:n,j

j,j

11 end

2.1.3 Givens Rotations (GR)

The method introduced by Givens rotates the elements of A in pairs such that one of the elements is set to 0 [2]. After applying rotations to all the elements of the lower triangular part of A, we obtain matrix R. To obtain

(23)

2.1. ALGORITHMS 7 matrix Q we follow the same method as in HR, applying the same trans- formations to the Identity Matrix than to matrix A. A sequence of the transformation for a 4 × 4 matrix is

x x x x

x x x x x x x x x x x x

 Q1

x x x x

x x x x x x x x 0 x x x

 Q2

x x x x x x x x 0 x x x 0 x x x

 Q3

x x x x 0 x x x 0 x x x 0 x x x

 Q4

x x x x 0 x x x 0 x x x 0 0 x x

 Q5

x x x x 0 x x x 0 0 x x 0 0 x x

 Q6

x x x x 0 x x x 0 0 x x 0 0 0 x



.

(2.10) The rotation is performed using a 2 × 2 matrix of the form

c s

−s c

!

. (2.11)

This matrix is orthogonal (|c|2+ |s|2 = 1) and the elements c and s are the sine and cosine of the transformation. To rotate a vector x y into

x0 0, the values of c and s are

c = x

x2+ y2; s = −y

x2+ y2. (2.12)

The algorithm is given in Alg. 4. The products and sum in line 5 generate large numbers and can affect the accuracy of the decomposition. Divisions and square roots are computed in lines 5, 6 and 7. The number of iterations of the algorithm is higher in the case of GR and therefore more square roots and divisions are computed than in the case of HR and MGS. The rotation operation in lines 8 and 9 can also create problems of over/under-flows in the computation of the algorithm if the dynamic range is not well adjusted.

2.1.4 CORDIC Givens Rotations(CORDIC)

As mentioned above, multiplications, divisions and square roots are very costly operations and are a limitation in the computation time of all the pre- vious methods. To avoid the use of these operations, an algorithm called CORDIC was developed in 1959 by Jack Volder [6]. The advantage of CORDIC functions is that compute trigonometric and linear functions using only shifts and additions. On the other hand, CORDIC functions are itera- tive operations and can increase the latency of the system. Besides, the area cost of implementing CORDIC is very high.

CORDIC can be use in two different modes: rotation mode and vectoring mode. The rotation mode can be use to rotate a vector given an angle and

(24)

8 CHAPTER 2. QR DECOMPOSITION Algorithm 4: Givens Rotations

1 R = A

2 Q = In×n

3 for i = j to n do

4 for i = m - 1 to j + 1 do

5 b =qr2i−1,j+ ri,j2

6 a1 = ri−1,jb

7 a2 = −ri,jb

8 Ri−1:i,j:n = [a1, −a2; a2, a1]Ri−1:i,j:n

9 Qi−1:i,1:n= [a1, −a2; a2, a1]Qi−1:i,1:n

10 end

11 end

the vectoring mode can be use to calculate the angle need for the rotation.

Therefore, the CORDIC based Givens Rotations first uses the vectoring mode to calculate the angle of rotation and after that uses the rotation mode to rotate the two rows involve in the rotation. The algorithm is given in Alg. 5 and the rotation and vectoring mode are detailed in [4].

2.1.5 Modified Squared Givens Rotations (MSGR)

An improved version of Givens Rotations was presented in [5]. This algorithm is based in translating the rows to rotate to an U and V-space such that the rotation of the matrices can be done with very simple operations. The equations to translate the rows to the new space and to do the rotation are shown in (2.13) and (2.14) respectively, where r and a are the rows to rotate and ¯u and ¯v are the rotated rows. The constant wacan be set to 1 to simplify the operations without significant loss of accuracy.

u = r1r, a = w

1

a2v, (2.13)

u = u + wv¯ kv, v = v − (¯ uvk

k)u. (2.14)

This new algorithm requires less operations than Givens Rotations and avoid the use of square roots in the computation. In the paper is shown how using this algorithm it is possible to achieve very low latency and high perfor- mance. Besides, stability issues when processing zero values are solved using partial pivoting of rows when the element to process is zero. This algorithm

(25)

2.1. ALGORITHMS 9 Algorithm 5: CORDIC Givens Rotations

1 R = A

2 Q = In×n

3 for i = j to n do

4 for i = m - 1 to j + 1 do

5 CORDIC Vectoring Mode to calculate angle of rotation

6 Input Vector: (Ri−1,j, Ri,j) Output angle: θ

7 for k = 1 to n do

8 CORDIC Rotation Mode to rotate the matrix (x2)

9

Input angle: θ

Input Vector 1: (ri−1,k, ri,k) Output Vector 1: (ri−1,k, ri,k) Input Vector 2: (qi−1,k, qi,k) Output Vector 2: (qi−1,k, qi,k)

10 end

11 end

12 end

does not perform a pure QR decomposition since the resulting matrix Q is not orthogonal. However, the inverse of matrix Q can be computed directly from the algorithm (2.8), so the algorithm is still useful to compute matrix inverses.

The algorithm is given in Alg. 6. In the case of MSGR, the most critical operations that can lead to instabilities and loss of accuracy are the trans- lation to the U space in lines 4 and 5 and the update in lines 22 and 24 for the same reason than in the previous algorithms.

2.1.6 Modified Gaussian Elimination (MGE)

The method to obtain the QR Decomposition that we propose here is based on the idea of computing the triangular matrix R applying Gaussian Elimi- nation. Considering a n × n matrix

(26)

10 CHAPTER 2. QR DECOMPOSITION

Algorithm 6: MSGR

1 R = A

2 Q = In×n

3 for j = 1 to n do

4 u1 =rj,jRj,j:n

5 u2 =rj,jQj,1:n

6 for i = j + 1 to m do

7 v1 = Ri,j:n

8 v2 = Q1,1:m

9 if u1(1) equal to 0 then

10 if v1(1) different to 0 then

11 Ri,j:n= −Rj,j:n

12 Rj,j:n= v1(1)0v1

13 Qi,1:n = −Qi,1:n

14 Qj,1:n = v1(1)0v2

15 else

16 Ri,j:n= −Rj,j:n

17 Rj,j:n= v1

18 Qi,1:n = −Qi,1:n

19 Qj,1:n = v2

20 end

21 else

22 Rj,j:n=u1+ v1(1)v1

23 Ri,j:n = v1vu1(1)

1(1)u1 24 Qj,1:n =u2+ v1(1)v2

25 Qi,1:n = v2uv(1)1

1(1)u2

26 end

27 end

28 end

(27)

2.1. ALGORITHMS 11

A =

a1

a2 ... ai

... an

=

a11 a12 · · · a1j · · · a1n a21 a22 · · · a2j · · · a2n ... ... ... ... ... ... ai1 ai2 · · · aij · · · ain

... ... . .. ... ... an1 an2 · · · anj · · · ann

, (2.15)

to zero out the element in row i and column j we apply the Gaussian Elimination equation

ai= aiai,j

aj, jaj. (2.16)

After applying the transformation we obtain the triangular matrix R. As in MSGR, matrix Q is not orthogonal and Q-1 is directly obtain from the algorithm applying the rotations to the Identity Matrix.

To illustrate how the algorithm works, an example is presented here. Lets consider the following 3 × 3 matrix

A =

1 −2 −6

2 4 12

1 −4 −14

. (2.17)

The intermediate steps to triangularize A applying (2.16) are

1 −2 −6

2 4 12 1 −4 −14

 Q1

1 −2 −6

0 8 24 1 −4 −14

 Q2

1 −2 −6

0 8 24 0 −2 −8

 Q3

1 −2 −6

0 8 24 0 0 −2



= R. (2.18)

As mentioned above, to obtain Q-1 we apply the same transformations to the Identity Matrix

1 0 0

0 1 0 0 0 1

 Q1

 1 0 0

−2 1 0 0 0 1

 Q2

 1 0 0

−2 1 0

−1 0 1

 Q3

 1 0 0

−2 1 0

−1 0.25 1



= Q-1. (2.19) As can be seen in the example, the resulting matrix Q-1is lower-triangular, so the method is similar to an LU Decomposition. The difference is that in this method the algorithm gives us directly the inverse of matrix L and to compute the inverse we just need to compute R-1 using backward substitu- tion and multiply both matrices. This procedure have the advantage that is less complex than previous LU methods to compute inverses and can also be implemented efficiently in parallel structures. To avoid stability issues when

(28)

12 CHAPTER 2. QR DECOMPOSITION processing zero values, a partial pivoting of rows when the element to process is zero is also done.

The Modified Gaussian Elimination algorithm is given in Alg. 7. The MGE algorithm is very similar to MSGR but avoiding the computation of the operations that can produce problems in the system. For that reason, the algorithm have a smaller dynamic range and is robust against over/under- flows.

Algorithm 7: Modified Gaussian Elimination

1 R = A

2 Q = In×n

3 for j = 1 to n do

4 for i = j+1 to n do

5 if Rj,j equal to 0 then

6 v1 = Ri,j:n

7 Ri,j:n = Rj,j:n

8 Rj,j:n= v1

9 v2 = Qi,1:n

10 Qi,1:n = Qj,1:n

11 Qj,1:n = v2

12 end

13 Qi,1:n = Qi,1:nrri,j

j,jQj,1:n

14 Ri,j:n = Ri,j:nrri,j

j,jRj,j:n

15 end

16 end

2.2 Computation complexity

In this section, the complexity of the different methods is compared in terms of number of operations. A remark about the level of parallelism of the algorithms is also done. The number of operations of HR, MGS, GR and MSGR can be found in the literature. To compute the number of operations of MGE we consider the worse case when no pivoting is done. Looking at Alg. 7, we can see that the operations of lines 13 and 14 compute n + j multiplications, n + j subtractions and 1 division every iteration. So, the

(29)

2.2. COMPUTATION COMPLEXITY 13

Method Asymptotic cost HR [2] 4n33

MGS [2] ∼ 2n3

GR [2] ∼ 5n3

CORDIC [4] ∼ 5n3p MSGR [5] 15n63

MGE 10n63

Table 2.1: Asymptotic number of operations for QR based matrix inverse (n × n matrix)

total number of operations computed by the algorithm is Subtractions :Pnj=1Pj−1i=1n + j = 5n63n22n3 M ultiplications : Pnj=1Pj−1i=1n + j = 5n63n22n3

Divisions :Pnj=1Pj−1i=11 = n22n2

(2.20)

In Table 2.1 the asymptotic cost of the different methods is shown. The asymptotic cost have been calculated taking the leader terms of the total number of operations. The detailed number of operations can be found in Annex A.

The results show that the complexity of MGE is very close to HR and is very low compared with the other methods. In particular, compared with MSGR, MGE reduce the number of operations in a 33 %. Besides, MGE, as well as MSGR, avoids the use of square roots.

A deeper discussion about complexity must take into account not only the number of operations, complexity can be reduced with parallel imple- mentations. In that sense, a parallel VLSI architecture for matrix inversion using MGS was proposed in [3] and a systolic array implementation for GR and MSQR were proposed in [7] and [5] respectively. The implementation of GR and MSGR in systolic arrays allows the computation of more opera- tions in parallel than the proposed structure for MGS. As the computation of MGE follows a similar idea than MSGR, it can also be implemented using systolic arrays. A fully parallel implementation of MGE using systolic arrays is presented in Section 2.6.

Regarding CORDIC, the variable p stands for the number of iterations in the CORDIC functions; it is known that generally one additional bit of accuracy is produced for each iteration [4]. Using this method the number of operations is higher than using the others, but with the advantage that

(30)

14 CHAPTER 2. QR DECOMPOSITION all the operations are shifts and additions, much more simple operations to implement in hardware than multiplications, divisions and square roots. The CORDIC algorithm is a good choice when no hardware multiplier is available, but if multipliers are available, the CORDIC algorithm is less efficient, as needs more iterations to convergence and occupy more area.

2.3 Numerical properties

In this section, the stability and accuracy of the computation of a matrix inverse using QR Decomposition is studied. If we denote the QR Decompo- sition affected by rounding errors as

A = ˜˜ Q ˜R, (2.21)

then the errors in the computation of A-1 can be written as

A˜-1 = ˜R-1Q˜-1 = A-1+ δA-1. (2.22) In [8], it is proved that if a backward stable algorithm is used to solve a problem f with condition number κ, the relative errors satisfy

|| ˜f (x) − f (x)||

||f (x)|| = O(κ(x)machine), (2.23) where the condition number is defined as

κ(A) = ||A||||A-1|| = λmax

λmin, (2.24)

and λmax and λmin are the maximum and minimum eigenvalues respec- tively.

So, if we prove that the inverse of a matrix using QR Decomposition is backward stable, then the relative error of the inverse is upper-bound by

||δA-1||

||A-1|| ≤ Cκ(A)machine. (2.25) For a QR Decomposition computed by Householder Reflectors, Givens Rotations, CORDIC Givens Rotations and Modified Gram-Schmidt, the fac- tors ˜Q and ˜R satisfy

Q ˜˜R = A + δA,||δA||

||A|| = O(machine) (2.26)

(31)

2.3. NUMERICAL PROPERTIES 15 due to the orthogonality of Q. However, Gaussian Elimination is known to be numerical unstable for certain matrices. In [8] a deep discussion about the stability issues of Gaussian Elimination was done. The conclusion of the discussion was that the stability of a Gaussian Elimination decomposition with partial pivoting can not be assure for all matrices, but the set of ma- trices that can lead to stability problems in GE are so rarely found in real applications that Gaussian Elimination can be considered as backward stable when a partial pivoting is done. Here, we assume that Gaussian Elimination is backward stable. Regarding MSGR, a discussion about stability has not been done and can not be assure.

To prove that the inverse of a matrix using QR Decomposition is backward stable we must prove that

||δA-1||

||A-1|| = O(machine) (2.27) We consider that the errors affecting the inverse are caused by the errors in the computation and inverse of R and Q, so

A-1+ δA-1 = (R-1+ δR-1)(Q-1+ δQ-1) =

= R-1Q-1+ δR-1Q-1+ R-1δQ-1+ δR-1δQ-1.

(2.28)

Considering the term δR-1δQ-1 negligible we obtain

δA-1 = δR-1Q-1+ R-1δQ-1, (2.29) so the norm of δA-1 is

||δA-1|| = ||δR-1Q-1+ R-1δQ-1|| ≤ ||δR-1||||Q-1|| + ||R-1||||δQ-1||, (2.30) and

||δA-1||

||Q-1||||R-1|| ≤ ||δR-1||||Q-1||

||Q-1||||R-1|| +||R-1||||δQ-1||

||Q-1||||R-1|| = ||δR-1||

||R-1|| +||δQ-1||

||Q-1|| . (2.31) The computation of R-1 is done using backward substitution, which was also proved to be backward stable in [8], so

||δR-1||

||R-1|| = O(κ(A)machine). (2.32)

(32)

16 CHAPTER 2. QR DECOMPOSITION Regarding Q-1, in HR, GR, CORDIC, MSGR and MGE the algorithm gives us directly Q-1 and the orthogonal errors are not affecting, only round- off errors are present. So, Q-1 is also backward stable

||δQ-1||

||Q-1|| = O(machine). (2.33) In the case of Modified Gram-Schmidt, the algorithm gives us Q and we calculate Q-1 as QH. In [3] it is shown that the loss of orthogonality is

||δQ-1||

||Q-1|| = ||δQH||

||QH|| = O(κ(A)machine) (2.34) Now, taking (2.31), (2.32), (2.33) and (2.34) we can say that for HR, GR, CORDIC GR, MGE and MSGR

||δA-1||

||Q-1||||R-1|| ≤ κ(A)C1machine+C2machine = (κ(A)C1+C2)machine, (2.35) and for MGS

||δA-1||

||Q-1||||R-1|| ≤ κ(A)C1machine+ C3κ(A)machine = κ(A)(C1+ C3)machine. (2.36) Equations (2.35) and (2.36) does not assure the backward stability of A-1. Only in the case of orthogonal Q we can affirm that

||δA-1||

||Q-1||||R-1|| = ||δA-1||

||A-1|| . (2.37)

This is always true for HR, GR, CORDIC GR and MGS, but for MSGR and MGE we can not assure the backward stability of the inverse. However, as shown in [8], in real applications is very difficult to find a system when Gaussian Elimination is not stable, so we can say that even if the stability is not completely assure, in most applications the inverse is stable.

2.4 Floating Points Results

In this section, the relative errors of A-1, R-1 and QH for a set of matrices with increasing condition number are presented. The dot-dashed line rep- resent the upper-bound value machine and the dashed line the upper-bound

(33)

2.5. FIXED POINT RESULTS 17

0 0.5 1 1.5 2 2.5 3 3.5 4

x 104 10−19

10−18 10−17 10−16 10−15 10−14 10−13 10−12 10−11

κ(A)

||δR−1 ||/||R−1 || Givens Rotations

MSGR

Gauss Elimination Householder Reflectors Modified Gram−Schmidt

Figure 2.1: Relative errors of R-1 using double precision floating points

value κ(A)machine. The results have been obtained using MATLAB double precision, which have machine= 2.2204 · 10−16.

As shown in Figures 2.1 to 2.3, the relative errors of A-1, R-1 and QH are below the upper-bound values derived above and, in the case of QH, also show that the orthogonalization errors of HR and GR are upper-bound by

machine. The large orthogonalization errors in MGS are making the algorithm the less accurate whereas the most accurate algorithm is MGE.

2.5 Fixed Point Results

The analysis in Section 2.3 is valid for floating point arithmetic and can not be easily extrapolate to fixed points. Hence, here we repeat the simulations using fixed points to find the upper-bounds empirically. The simulations have been done using 64, 32 and 16 bits and normalizing the input to avoid over/under-flows.

2.5.1 64 bits fixed points

In Figure 2.4 we can observe that MGS have less errors than all the other methods. However, the orthogonalization errors (Fig.2.5) introduce an error

(34)

18 CHAPTER 2. QR DECOMPOSITION

0 0.5 1 1.5 2 2.5 3 3.5 4

x 104 10−16

10−15 10−14 10−13 10−12 10−11

κ(A)

||δQH||/||QH||

Givens Rotations Householder Reflectors Modified Gram−Schmidt

Figure 2.2: Relative errors of QH using double precision floating points

0 0.5 1 1.5 2 2.5 3 3.5 4

x 104 10−17

10−16 10−15 10−14 10−13 10−12 10−11

κ(A)

||δA−1||/||A−1||

Givens Rotations MSGR

Gauss Elimination Householder Reflectors Modified Gram−Schmidt

Figure 2.3: Relative errors of A-1 using double precision floating points

(35)

2.5. FIXED POINT RESULTS 19

0 0.5 1 1.5 2 2.5 3 3.5 4

x 104 10−15

10−10 10−5

κ(A)

||δR−1 ||/||R−1 ||

Givens Rotations MSGR

Gauss Elimination CORDIC Givens Rotations Householder Reflectors Modified Gram−Schmidt

Figure 2.4: Relative errors of R-1 using 64-bits fixed points

in the computation of the matrix inverse that is not present in the other methods, as commented above. For this reason, MGS is the method that shows a larger error. In Fig. 2.6 the results show that MGE is the method with less error. All the methods show a similar dependence of the relative error of A-1 with the condition number.

2.5.2 32 bits fixed points

Using a 32-bits representation similar results were obtained. Figures 2.7 to 2.9 show that again MGS have less errors in the computation of R-1 but the orthogonalization errors are also limiting the performance. MSGR is showing less errors in R-1, but this is not reflected in A-1 because the computation of Q-1 is introducing a larger error. MGE is again the method with less error in A-1.

2.5.3 16 bits fixed points

The results obtained in Fig. 2.10 and Fig. 2.11 are the same as using 64 and 32 bits. In Fig. 2.12, however, all the methods show the same error except GR and HR, that show a larger error.

(36)

20 CHAPTER 2. QR DECOMPOSITION

0 0.5 1 1.5 2 2.5 3 3.5 4

x 104 10−7

10−6 10−5 10−4 10−3 10−2 10−1 100

κ(A)

||δQH||/||QH||

Givens Rotations CORDIC Givens Rotations Householder Reflectors Modified Gram−Schmidt

Figure 2.5: Relative errors of QH using 64-bits fixed points

0 0.5 1 1.5 2 2.5 3 3.5 4

x 104 10−9

10−8 10−7 10−6 10−5 10−4 10−3 10−2 10−1

κ(A)

||δA−1||/||A−1||

Givens Rotations MSGR Gauss Elimination CORDIC Givens Rotations Householder Reflectors Modified Gram−Schmidt

Figure 2.6: Relative errors of A-1 using 64-bits fixed points

(37)

2.5. FIXED POINT RESULTS 21

0 0.5 1 1.5 2 2.5 3 3.5 4

x 104 10−16

10−14 10−12 10−10 10−8 10−6 10−4

κ(A)

||δR−1 ||/||R−1 || Givens Rotations

MSGR

Gauss Elimination CORDIC Givens Rotations Householder Reflectors Modified Gram−Schmidt

Figure 2.7: Relative errors of R-1 using 32-bits fixed points

0 0.5 1 1.5 2 2.5 3 3.5 4

x 104 10−8

10−7 10−6 10−5 10−4 10−3 10−2 10−1 100

κ(A)

||δQH||/||QH||

Givens Rotations CORDIC Givens Rotations Householder Reflectors Modified Gram−Schmidt

Figure 2.8: Relative errors of QH using 32-bits fixed points

(38)

22 CHAPTER 2. QR DECOMPOSITION

0 0.5 1 1.5 2 2.5 3 3.5 4

x 104 10−8

10−7 10−6 10−5 10−4 10−3 10−2 10−1

κ(A)

||δA−1||/||A−1||

Givens Rotations MSGR

Gauss Elimination CORDIC Givens Rotations Householder Reflectors Modified Gram−Schmidt

Figure 2.9: Relative errors of A-1 using 32-bits fixed points

0 0.5 1 1.5 2 2.5 3 3.5 4

x 104 10−4

10−3 10−2

κ(A)

||δR−1||/||R−1||

Givens Rotations MSGR

Gauss Elimination CORDIC Givens Rotations Householder Reflectors Modified Gram−Schmidt

Figure 2.10: Relative errors of R-1 using 16-bits fixed points

(39)

2.5. FIXED POINT RESULTS 23

0 0.5 1 1.5 2 2.5 3 3.5 4

x 104 10−2

10−1 100 101 102 103

κ(A)

||δQH||/||QH||

Givens Rotations CORDIC Givens Rotations Householder Reflectors Modified Gram−Schmidt

Figure 2.11: Relative errors of QH using 16-bits fixed points

0 0.5 1 1.5 2 2.5 3 3.5 4

x 104 10−2

10−1 100 101

κ(A)

||δA−1||/||A−1||

Givens Rotations MSGR

Gauss Elimination CORDIC Givens Rotations Householder Reflectors Modified Gram−Schmidt

Figure 2.12: Relative errors of A-1 using 16-bits fixed points

References

Related documents

För att uppskatta den totala effekten av reformerna måste dock hänsyn tas till såväl samt- liga priseffekter som sammansättningseffekter, till följd av ökad försäljningsandel

The increasing availability of data and attention to services has increased the understanding of the contribution of services to innovation and productivity in

Syftet eller förväntan med denna rapport är inte heller att kunna ”mäta” effekter kvantita- tivt, utan att med huvudsakligt fokus på output och resultat i eller från

Generella styrmedel kan ha varit mindre verksamma än man har trott De generella styrmedlen, till skillnad från de specifika styrmedlen, har kommit att användas i större

Parallellmarknader innebär dock inte en drivkraft för en grön omställning Ökad andel direktförsäljning räddar många lokala producenter och kan tyckas utgöra en drivkraft

Närmare 90 procent av de statliga medlen (intäkter och utgifter) för näringslivets klimatomställning går till generella styrmedel, det vill säga styrmedel som påverkar

• Utbildningsnivåerna i Sveriges FA-regioner varierar kraftigt. I Stockholm har 46 procent av de sysselsatta eftergymnasial utbildning, medan samma andel i Dorotea endast

Den förbättrade tillgängligheten berör framför allt boende i områden med en mycket hög eller hög tillgänglighet till tätorter, men även antalet personer med längre än