QR Factorization⚓︎
Definition of QR Factorization:
\(\boldsymbol{Q}\) is a unitary matrix and \(\boldsymbol{R}\) is an upper triangular matrix.
Gram-Schmidt Algorithm⚓︎
Introduction to Gram-Schmidt Process⚓︎
Gram-Schmidt is an algorithm to produce \(\boldsymbol{Q}\) and \(\boldsymbol{R}\).
Given \(\left[ \begin{matrix} \boldsymbol{a}_1& \boldsymbol{a}_2& \cdots& \boldsymbol{a}_m\\ \end{matrix} \right]\). Let \(\mathrm{span}\left\{ \boldsymbol{a}_1, \boldsymbol{a}_2, \cdots , \boldsymbol{a}_m \right\} \triangleq \left< \boldsymbol{a}_1, \boldsymbol{a}_2, \cdots , \boldsymbol{a}_m \right>\). We need to find \(\boldsymbol{q}_1, \boldsymbol{q}_2, \cdots , \boldsymbol{q}_m\) such that \(\left< \boldsymbol{q}_1, \boldsymbol{q}_2, \cdots , \boldsymbol{q}_m \right> =\left< \boldsymbol{a}_1, \boldsymbol{a}_2, \cdots , \boldsymbol{a}_m \right>\) and the inner products \(\left( \boldsymbol{q}_i, \boldsymbol{q}_j \right) =0\) if \(i\ne j\), \(\left( \boldsymbol{q}_i, \boldsymbol{q}_i \right) =1\).
Example steps (only 2-norm is used below):
Classical Gram-Schmidt Algorithm⚓︎
Given \(\boldsymbol{A}=\left[ \begin{matrix} \boldsymbol{a}_1& \cdots& \boldsymbol{a}_j& \cdots& \boldsymbol{a}_m\\ \end{matrix} \right]\);
For \(j=1:m\):
- \(\boldsymbol{v}_j=\boldsymbol{a}_j\);
- For \(i=1:(j-1)\):
- \(r_{ij}=\left( \boldsymbol{q}_i, \boldsymbol{a}_j \right)\);
- \(\boldsymbol{v}_j=\boldsymbol{v}_j-r_{ij}\cdot \boldsymbol{q}_i\);
- End
- \(r_{jj}=\left\| \boldsymbol{v}_j \right\|\);
- \(\boldsymbol{q}_j=\frac{\boldsymbol{v}_j}{r_{jj}}\);
End
The outcome: \(\boldsymbol{Q}=\left[ \begin{matrix} \boldsymbol{q}_1& \boldsymbol{q}_2& \cdots& \boldsymbol{q}_m\\ \end{matrix} \right]\) unitary, and \(\boldsymbol{R}=\left[ r_{ij} \right]\) upper triangular.
Claim
: The classical Gram-Schmidt algorithm above is not stable.
Modified Gram-Schmidt Algorithm⚓︎
Given \(\boldsymbol{A}=\left[ \begin{matrix} \boldsymbol{a}_1& \cdots& \boldsymbol{a}_j& \cdots& \boldsymbol{a}_m\\ \end{matrix} \right]\);
For \(i=1:m\):
- \(\boldsymbol{v}_i=\boldsymbol{a}_i\);
End
For \(i=1:m\):
- \(r_{ii}=\left\| \boldsymbol{v}_i \right\|\);
- \(\boldsymbol{q}_i=\frac{\boldsymbol{v}_i}{r_{ii}}\);
- For \(j=(i+1):m\):
- \(r_{ij}=\left( \boldsymbol{q}_i, \boldsymbol{v}_j \right)\);
- \(\boldsymbol{v}_j=\boldsymbol{v}_j-r_{ij}\cdot \boldsymbol{q}_i\);
- End
End
Claim
: The modified Gram-Schmidt algorithm is stable.
Questions:
- Why classical and modified Gram-Schmidt are equivalent?
- Intuitively, why is the classical one not stable, while the modified one stable?
The cost of the modified Gram-Schmidt is \(O(2mn^2)\) for \(\boldsymbol{A}\in \mathbb{R} ^{m\times n}\).
Discussion on QR Factorization⚓︎
Theorem
: Every matrix \(\boldsymbol{A}\in \mathbb{R} ^{m\times n}\,\,\left( m\geqslant n \right)\) has a QR Factorization.
If column vectors of \(\boldsymbol{A}\) are linearly independent(full rank), then
This is Reduced QR Factorization(default). The other one:
is called Full QR Factorization(rarely used).
Theorem
: If \(\boldsymbol{A}\in \mathbb{R} ^{m\times n}\,\,\left( m\geqslant n \right)\) is full rank, the Reduced QR Factorization is unique if we require \(r_{ii}>0, i=1,\cdots ,n\).
We can use QR Factorization to solve linear systems (least square solution):
Matrix explanation of Gram-Schmidt process (Using upper triangular matrices to generate orthogonal matrix):
Two types of orthogonal linear transformation:
- Rotation
- Reflection
Actually, there are other ways to computer QR Factorization using unitary matrices to generate upper triangular matrix (Using unitary transformation):
where \(\boldsymbol{Q}_i\) are unitary. There are two ways for this process: Householder transformation and Givens rotation.
Householder Transformation⚓︎
Basic Steps⚓︎
The overall procedure (recursive):
Example step 1:
where \(\boldsymbol{Q}_1\) is unitary.
We can get:
Question
: why not choose \(\mathbf{H}_2\) and get \(\boldsymbol{v}=\left\| \boldsymbol{x} \right\| \boldsymbol{e}_1-\boldsymbol{x}\)?
We have two choices: \(\boldsymbol{Q}_1\boldsymbol{x}=-\left\| \boldsymbol{x} \right\| \boldsymbol{e}_1, \boldsymbol{Q}_1\boldsymbol{x}=\left\| \boldsymbol{x} \right\| \boldsymbol{e}_1\).
In practice, we select:
\(\boldsymbol{x}_1\) is the first entry of \(\boldsymbol{x}\). We choose it for the stability reason. This results in a larger \(\left\| \boldsymbol{v} \right\|\).
Example step 2:
We can get:
Householder QR Factorization⚓︎
Here is the algorithm for Householder QR Factorization for a matrix \(\boldsymbol{A}\in \mathbb{R} ^{m\times n}\) :
For \(k=1:m\):
- \(\boldsymbol{x}=\boldsymbol{A}_{k:m,k}\);
- \(\boldsymbol{v}_k=-\mathrm{sign}\left( x_1 \right) \cdot \left\| \boldsymbol{x} \right\| \boldsymbol{e}_1-\boldsymbol{x}\);
- \(\boldsymbol{v}_k=\frac{\boldsymbol{v}_k}{\left\| \boldsymbol{v}_k \right\|}\);
- \(\boldsymbol{A}_{k:m,k:n}=\boldsymbol{A}_{k:m,k:n}-2\boldsymbol{v}_k\left( {\boldsymbol{v}_k}^T\boldsymbol{A}_{k:m,k:n} \right)\);
End
Remarks:
- QR by Householder transformation is stable. In practice, it is used more frequently than modified Gram-Schmidt algorithm.
- The cost of this algorithm is \(O\left( 2mn^2-\frac{2}{3}n^3 \right)\).
- \(\boldsymbol{Q}\) has never been formed explicitly.
Givens Rotation as QR Factorization⚓︎
The core element of Givens Rotation:
Transformation pattern: