LU decomposition
Matrix decompositions
Matrix factorisations play a key role in the solution of problems of the type . Often (e.g. ODE solvers), you have a fixed matrix that must be solved with many different vectors. A matrix factorisation is effectivly a pre-processing step that allows you to partition into multiple factors (e.g. in the case of decomposition), so that the actual solve is as quick as possible. Different decompositions have other uses besides solving , for example:
the , and Cholesky decomposition can be used to quickly find the determinant of a large matrix, since and the determinant of a triangular matrix is simply the product of its diagonal entries.
The Cholesky decomposition can be used to sample from a multivariate normal distribution, and is a very efficient technique to solve for the specific case of a positive definite matrix.
The decomposition can be used to solve a minimum least squares problem, to find the eigenvalues and eigenvectors of a matrix, and to calulcate the Singular Value Decomposition (SVD), which is itself another very useful decomposition!
decomposition
The decomposition is closely related to gaussian elimination. It takes the original equation to be solved and splits it up into two separate equations involving a unit lower triangular matrix , and the row echelon matrix :
where . The matrix is a unit lower triangular matrix and thus has ones on the diagonal, whereas is in row echelon form with pivot values in the leading coefficients of each row.
Thus, we have converted our original problem of solving into two separate solves, first solving the equation , and then using the result to solve .
However, each of those solves is very cheap to compute, in this case for the 4x4 matrix shown above the solution of only needs 6 multiplication and 6 additions, whereas requires 4 divisions, 6 multiplications and 6 additions, leading to a total of 28 arithmetic operations, much fewer in comparison with the 62 operations required to solve the original equation . In general, decomposition for an matrix takes about flops, or floating point operations, to compute.
factorisation without pivoting
A relativly simple algorithm can be described if we assume that no pivoting is required during a gaussian elimination. In this case, the gaussian elimination process is a sequence of linear operations , with each operation being a row replacement that adds a multiple of one row to another below it (i.e. is lower triangular). The final matrix after applying the sequence of row reductions is in row echelon form, that is:
Since we have , we can show that the sequence of operations is also the sequence that reduces the matrix to an identity matrix:
therefore,
and,
This implies how we can build up the matrix . We choose values for such that the series of row operations convert the matrix to the identity matrix. Since each is lower triangular, we know that both and are also lower triangular.
For example, consider the following matrix
After three row reductions, , , and , we have the following result:
To build the 1st column of , we simply divide the 1st column of by the pivot value 3, giving
For the next column we do the same, using the new pivot value in row 2 to reduce and to zero, and then dividing the column vector under the pivot by the pivot value 2 to obtain the next column of .
Repeating this process for all the columns in , we obtain the final factorisation. You can verify for yourself that repeating the same row operations we did to form to the matrix reduces it to the identity matrix.
Pivoting
Of course, for any practial factorisation we need to consider pivoting. Any matrix can be factorised into , where is a permutation matrix, and and are defined as before. During the gaussian elimination steps we store an array of row indices indicating that row is interchanged with row , and the resultant array of can be used to build the permutation matrix (It would be wasteful to store the entire martix so the array is stored instead).
Thus, the LU algorithm proceeds as follows:
Begin with the left-most column , find an appropriate pivot (e.g. maximum entry in the column) and designate this row as the pivot row. Interchange this row with row , and store the pivot row index as . Use row replacements to create zeros below the pivot. Create the corresponding column for by dividing by the pivot value.
Continue along to the next column , again choosing a pivot row , interchanging it with row and creating zeros below the pivot, creating the new column in , and making sure to record which pivot row has been chosen for each column. Repeat this step for all the columns of the matrix.
Once the last column has been done, should be in row echlon form and should be a unit lower triangular matrix. The array implicitly defines the permutation matrix
In practice, most library implementation store and in the same matrix since they are lower and upper triangular respectivly.
decomposition
It is often very benificial when solving linear systems to consider and take advantage of any special structure that the matrix might possesses. The decomposition is a varient on LU decomposition which is only applicable to a symmetric matrix (i.e. ). The advantage of using this decomposition is that it takes advantage of the redundent entries in the matrix to reduce the amount of computation to , which is about a half that required for the decomposition.
Other Reading
Linear algebra and its applications by David C. Lay. Chaper 2.5
Golub, G. H. & Van Loan, C. F. Matrix Computations, 3rd Ed. (Johns Hopkins University Press, 1996). Chapter 3.2 & 4.1
Software
Problems
LU decomposition
Take your gaussian elimination code that you wrote in the previous lesson and use it to
write an LU decomposition function that takes in a martix , and returns , and
the array . You can check your answer using
scipy.linalg.lu_factor
.
Hint: the permutation matrix is tricky to construct, so you might want to use the test
given in the documentation for lu_factor
.