QR Factorisation and Pseudoinverse of Rank-Deficient Matrices
QR Factorisation and Pseudoinverse of Rank-Deficient Matrices
deficient matrices
Peter Moylan
Glendale, NSW
[email protected] http://www.pmoylan.org
April 2016
1. Introduction
The QR factorisation of a (real or complex) matrix is defined to be the
decomposition
=
where has the property = , and is a (not necessarily square) upper triangular
matrix. Here, the superscript star indicates the adjoint (complex conjugate transpose) of a
matrix. The size of the matrices is not specified, except to the extent that the matrix product
must make sense. In practice there are three important ways of defining a QR factorisation.
In the traditional definition is an unitary matrix ( = = ), and is an
upper triangular matrix. This is called the full QR decomposition. It turns out, however,
that some of the most useful applications of QR factorisation are when . In such cases
the traditional definition leads to unreasonably large matrices.
If > , the traditional factorisation has the form
= [1 2 ] [1 ] = 1 1
0
where 1 still has the property 1 1 = , and 1 is still upper triangular. Now 1 is
and 1 is . In this case we choose to say that the pair (1,1 ) is still a QR factorisation
of , one that is computationally more convenient because the matrices are smaller. Because
1 is not square it is technically not unitary, but for our purposes that does not matter. In the
literature this is called the thin QR factorisation or the reduced QR factorisation. It is unique
if has full column rank and we restrict attention to those solutions where the diagonal
elements of 1 are positive. Obviously 2 is not unique, but that does not matter because we
have no interest in computing 2 .
page 1 of 10
QR factorisation and pseudoinverse of rank-deficient matrices
The goal of the present paper is to present an algorithm that can also handle rank-deficient
matrices. Specifically, we will find a factorisation where the number of rows of is equal to
the rank of . Clearly, no smaller decomposition is possible, so we will call this the minimal
or fully reduced QR factorisation.
Our approach is not the same as in rank-revealing QR factorisations, see e.g. [Ming96].
Those use a modified full or thin QR factorisation, and then look at the matrix to look for a
small or zero subblock. The goal in the present paper is not to generate the negligible part of
at all. This give computational savings, and also ensures that the rows of are linearly
independent.
One motivation for using a QR factorisation is that triangular matrices are easy to invert. This
does not appear to help in the rank-deficient case, but for some applications it turns out that a
pseudoinverse can be used instead of an inverse. For this reason, we show at the end of the
paper how to computer a pseudoinverse, cheaply, using the minimal QR factorisation as an
intermediate step.
page 2 of 10
QR factorisation and pseudoinverse of rank-deficient matrices
where 1 is the first column of and 1 is a scalar. The fact that = means that 1 1 =
1 and 1 2 = 0 and 2 2 = . This implies
1
1 = 1 1 1 = 1
1
and these values are unique because of the constraint that 1 be real and positive. There are
now two subcases to consider. For reasons that will become clear below, define
= 1 2 2 = 2 1
If 2 = 0 (which, it is easy to show, occurs iff has rank 1), we have
= [1 2 ] = [1 1 1 ] = 1 [1 ]
Observe that in this case the matrix has a single row, which is trivially in row echelon
form. This solution is unique, because any other factorisation would have more rows in
than the rank of .
Finally, consider the general case where 1 0 and 2 0. By the inductive hypothesis,
and the fact that 2 has fewer columns than , there exist unique matrices 2 and 2 such
that 2 = 2 2 , 2 2 = , and 2 is in fully reduced row echelon form. Define
1
= [1 2 ] = [0 ]
2
Then
2 ] [ 01 2 ] = [1 1
= [1 1 + 2 ] = [1 2 ] =
3. A practical implementation
The proof in the last section is a constructive one, so to turn it into software we need only
copy the steps of the proof. The result appears to be a recursive algorithm, but in practice no
recursion is involved: we are simply stepping through the columns of , at the same time
filling in columns of and rows and columns of , and modifying the remaining columns of
. The calculation is complete when we have finished processing either the last row or the
last column of the modified .
page 3 of 10
QR factorisation and pseudoinverse of rank-deficient matrices
Pivoting can be added to the algorithm, if desired. The only change this requires is to find, at
each step, the largest of the columns not yet processed, and if necessary to swap that with the
current column. This, however, does mean that the factorisation now has the form =
or equivalently = , where is a permutation matrix. Depending on the application,
this might not be desirable, because will not be a triangular matrix.
Note that the special case 2 = 0 does not require any special handling, other than
detecting that that matrix is zero. At that point in the calculation 1 and have already had
their values assigned, so all that remains to be done is to exit from the calculation loop.
Let be an matrix. The fully reduced decomposition is most beneficial when ,
but it is also valid for the case . We start the calculation by implicitly assuming that
has min(, ) rows, but we omit one or more rows each time we meet a special case (1 = 0
or 2 = 0). This does imply discarding partial rows of that we have set in previous
steps, but no information is lost, because the discarded entries are merely some of the zero
entries below the main diagonal.
An in-place calculation is possible, where each column of that we calculate replaces a
column of . If we are doing an in-place calculation, we need to watch out for one detail. In
the case 1 = 0, where we step to the next column of without adding a column to , we
might have to be prepared to shift the remainder of one column left. Alternatively, and
perhaps more efficiently, we just need to keep track of the fact that the current column of is
not necessarily the same as the current column of .
page 4 of 10
QR factorisation and pseudoinverse of rank-deficient matrices
Observe that is an matrix. That means that, regardless of the rank of , we have a
full QR decomposition, which is not really acceptable if . In this case, the last
rows of are zero, so we can get a thin QR decomposition by deleting the last
columns of .
This, unfortunately, does not translate into deleting rows or columns of the Householder
matrices . We have no alternative but to retain an matrix until the end of the
calculation; only at the end can we discard the redundant columns. For a long thin matrix ,
this can create serious storage problems.
But can we modify the Householder approach to get a minimal factorisation? Luckily, we
can. Partway through the calculation, we have
1
= = [ ]
0 22
Uniqueness of the solution for means that 1 and are precisely the matrices obtained by
our Section 2 calculations. That means that we can use the Section 2 insights to work out how
to modify the Householder approach to produce a minimal decomposition.
Let the upper left corner of 22 be at row and column (0 , 0 ). In the full-rank case we have
0 = 0 , but for our algorithm this is no longer true. From Section 2 we know that we have to
deal with two special cases:
(a) If the first column of 22 is zero, then we should increment 0 without incrementing
0 for the next step.
(b) Otherwise, if the updated 22 is zero, then we have finished the calculation.
It turns out that we do not need to check for case (b). If the case (b) condition is satisfied,
then on the following iterations we will immediately run into case (a), so the calculations will
be terminated in any case. Whether we do this check is purely a matter of software efficiency,
and does not affect the final answer.
So does the Householder approach give a more accurate answer? If running a test suite, we
should check (which should be zero), and (which should be zero). Our tests
on random matrices shows that the Householder approach gives better values of , but
worse values of . In other words, the Householder approach is better at producing
orthogonal columns of the matrix, but is not as good at producing a QR factorisation. If our
goal is to produce a good matrix, then the Householder approach is less desirable.
5. LQ decomposition
An LQ decomposition of a matrix has the form
=
where is lower triangular and has the property that = . As in the QR case, we can
have full, thin, or fully reduced version. The details are exactly as in the QR case, except that
we swap the labelling of rows and columns.
page 5 of 10
QR factorisation and pseudoinverse of rank-deficient matrices
6. Pseudoinverses
A pseudoinverse calculation is typically done via a singular value decomposition [SVD], but
this is computationally expensive. In this section we show that the minimal
decomposition can be used as a computationally cheap way to compute the result. The
pseudoinverse (Moore-Penrose inverse) # of a real or complex matrix is defined
uniquely by the properties [Pen55]:
# and # are both Hermitian
# =
# # = #
The pseudoinverse arises in connection with solving equations like
=
The solution = # has the properties
1. If one or more exact solutions exist, then the given solution is the one of least norm.
2. If no exact solution exists, then the pseudoinverse solution is the one that comes
closest to being a solution in that it minimises .
3. If is invertible then # = 1.
The following properties can be confirmed by substitution into the above conditions for a
pseudoinverse.
The operation of taking the Hermitian (complex conjugate transpose) of a matrix
commutes with the pseudoinverse operation. That is, ( )# = (# ) .
If has full column rank, then # = ( )1 .
If has full row rank, then # = ( )1 .
page 6 of 10
QR factorisation and pseudoinverse of rank-deficient matrices
Hermitian matrix is via the Cholesky decomposition [Cho]. A Cholesky decomposition works
by factoring the matrix in a certain way. Below, we show a cheaper method.
Suppose we do a QR factorisation of the matrix . The result is
= 1 1
where 1 is now a square upper triangular matrix, and 1 is , i.e. it has more
rows than columns. Then
( )1 = (1 1 1 1 )1 = (1 1 )1 = 11 (11 )
# = ( )1 = 1 1 11 (11 ) = 1 (11 )
This is a significant gain, because now the only inversion we have to deal with is the
inversion of a triangular matrix. The cost is that we have had to do a new QR factorisation,
but this is still cheaper than doing a full matrix inversion.
The conclusion is that we can calculate the pseudoinverse of any arbitrary matrix using at
most two QR factorisations and inverting a triangular matrix (which is easy). This appears to
be computationally more efficient than, for example, using a singular value decomposition.
Computational accuracy can be improved by using pivoting in the course of the
calculation. This is a minor change to the calculation, and results in finding a permutation
matrix such that = . With this change, we have = and # = # . That
is, it is the same calculation plus a final permutation.
page 7 of 10
QR factorisation and pseudoinverse of rank-deficient matrices
9. Conclusions
It is possible, with a fairly simple change to the conventional Gram-Schmidt approach, to do
a QR decomposition where the matrix is guaranteed to have full row rank. One
consequence of this is that we can calculate pseudoinverses far more efficiently than by using
a singular value decomposition.
The software for the algorithms described here are available for download [Moy16].
References
page 8 of 10
QR factorisation and pseudoinverse of rank-deficient matrices
() = =
=1
and because we know that some of the terms are zero, this reduces to
=
=
For row , we already know that = 1 and that = 0 for all < . For > ,
1
+ = 0
=
or
1
1
=
=
If we move from left to right through the array, the right side of this equation involves only
quantities we have already calculated.
An alternative approach, starting from the equation = , leads to the formula
1
=
=+1
for > , which is appropriate if we want to move backwards through the rows. These two
methods are of equal complexity and apparently equal accuracy, so either method should
work equally well.
The results for a lower triangular matrix are similar. If is a nonsingular lower triangular
matrix and is its inverse, then is also lower triangular, with
1
=
and
page 9 of 10
QR factorisation and pseudoinverse of rank-deficient matrices
1
1
=
=
for > . This is in a form suitable for working through the rows from first to last. There is a
second formula which also works, but is less convenient because it requires working
backwards through the columns.
page 10 of 10