QR factorisation

QR factorisation

For any (rectangular) matrix $A \in \R^{m\times n}$, find $Q,R$ such that $$ \begin{align*} A = QR \end{align*} $$ where

  • $Q\in \R^{m\times m}$ is orthogonal (i.e. $Q^TQ = I$); and

  • $R\in \R^{m\times n}$ is upper triangular (i.e. $r_{ij} = 0$ for $i>j$).

If $m>n$, the bottom $m-n$ rows of $R$ are zero, so we can write $Q\in \R^{m\times n}$ and $R^{n\times n}$ instead. This is the reduced QR factorisation.

Theorem (existence and uniqueness of QR factorisation) open_in_new

Any matrix $A$ has a QR factorisation.

If $A$ is square and non-singular, then $A$ admits a unique factorisation $A = QR$ with $R$ having a positive diagonal.

Proof of existence: see Gram-Schmidt, Givens rotations, or Householder reflections.

Proof of uniqueness

QR factorisation using the Gram-Schmidt process open_in_new

Let $\v a_1, \ldots, \v a_n\in \R^m$ be the columns of $A$. By performing the Gram-Schmidt process on $\v a_1, \ldots, \v a_n$, we find an orthonormal set $\v q_1, \ldots, \v q_k \in \R^m$ ($k\leq n$) and coefficients $r_{ij}\in \R$ such that $$ \begin{align*} \v a_i = \sum_{j=1}^{i} r_{ji} \v q_j. \end{align*} $$ Then $$ \begin{align*} A = \underbrace{\pmat{\v q_1 & \ldots & \v q_k}}_{Q} \underbrace{\pmat{r_{11} & r_{12} & \ldots & r_{1k} & \ldots & r_{1n} \\ & r_{22} & \ldots & r_{2k} & \ldots & r_{2n} \\ &&\ddots & \vdots & & \vdots\\ &&&r_{kk} & \ldots & r_{kn}}}_{R}. \end{align*} $$

Example (QR factorisation using the Gram-Schmidt process)

However Gram-Schmidt is very numerically unstable.

Givens rotations open_in_new

For any vector $\v a\in \R^m$, the Givens rotation matrix $Ω^{[p,q]}\in \R^{m\times m}$ is an orthogonal transformation that makes the $q$-th component zero and preserves all components other than the $p$ and $q$-th ones: $$ \begin{align*} \underbrace{\pmat{1\\&\ddots\\&&\frac{a_p}{\sqrt{a_p^2+a_q^2}} && \frac{a_q}{\sqrt{a_p^2+a_q^2}} \\ &&&\ddots \\&&-\frac{a_q}{\sqrt{a_p^2+a_q^2}}&&\frac{a_p}{\sqrt{a_p^2+a_q^2}} \\ &&&&&\ddots \\ &&&&&&1}}_{Ω^{[p,q]}} \underbrace{\pmat{a_{1} \\ \vdots \\ a_p \\ \vdots \\ a_q \\ \vdots \\ a_m}}_{\v a} = \pmat{a_1 \\ \vdots \\ a_p^2 + a_q^2 \\ \vdots \\ 0 \\ \vdots \\a_m} \end{align*} $$

Applying $Ω^{[p,q]}$ to a matrix $A$, all rows other than rows $p$ and $q$ are unchanged, one entry in row $p$ is killed, and the span of rows $p$ and $q$ is preserved.

Thus after at most $mn$ Givens rotations, we can annihilate all subdiagonal elements: $$ \begin{align*} \pmat{*&*&*\\ *&*&* \\ *&*&* \\ *&*&*} &\xrightarrow{Ω^{[1,2]}} \pmat{\bullet &\bullet&\bullet\\ 0 &\bullet&\bullet \\ *&*&* \\ *&*&*} \xrightarrow{Ω^{[1,3]}} \pmat{\bullet &\bullet&\bullet\\ 0 &*&* \\ 0&\bullet&\bullet \\ *&*&*} \xrightarrow{Ω^{[1,4]}} \pmat{\bullet &\bullet&\bullet\\ 0 &*&* \\ 0&*&* \\ 0&\bullet&\bullet} \\ &\xrightarrow{Ω^{[2,3]}} \pmat{*&*&* \\ 0 &\bullet&\bullet \\ 0&0&\bullet \\ 0&*&*} \xrightarrow{Ω^{[2,4]}} \pmat{*&*&* \\ 0 &\bullet&\bullet \\ 0&0&* \\ 0&0&\bullet} \\ &\xrightarrow{Ω^{[3,4]}} \pmat{*&*&* \\ 0 &*&* \\ 0&0&\bullet \\ 0&0&0} \\ \end{align*} $$ (Legend: $*$ remains the same as the previous matrix; $\bullet$ has changed through a rotation.)

Therefore $$ \begin{align*} & R = (Ω^{[m-1,m]})\cdot (Ω^{[m-2,m]} Ω^{[m-2, m-1]}) \cdot \ldots \cdot (Ω^{[1,m]} \ldots Ω^{[1,3]} Ω^{[1,2]}) \cdot A \\ \implies & A = \underbrace{\Bigl[(Ω^{[m-1,m]})\cdot (Ω^{[m-2,m]} Ω^{[m-2, m-1]}) \cdot \ldots \cdot (Ω^{[1,m]} \ldots Ω^{[1,3]} Ω^{[1,2]})\Bigr]^T}_{Q} R. \end{align*} $$

Example (QR factorisation using Givens rotations)

Cost:

  • Computing $R$: $O(mn\cdot n)$.

  • Computing an explicit form of $Q$ (usually not necessary): perform all the Given rotations on $I_m$. This gives an extra cost of $O(mn\cdot m)$.

  • Computing $Q^T \v b$: $O(mn)$.

Householder reflections open_in_new

Definition (Householder reflection) open_in_new

Given a non-zero vector $\v u\in \R^m$, the $m\times m$ matrix $$ \begin{align*} H_\v u = I - \frac{2}{\|\v u\|^2} \v u \v u^T \end{align*} $$ is called a Householder transformation or reflection.

  • $H_\v u$ reflects a vector about the $(m-1)$-dimensional hyperplane normal to $\v u$. (Derivation)

  • $H_{\v u}$ is orthogonal.

  • If $\|\v a\|=\|\v b\|$, then $H_{\v a - \v b}(\v a) = \v b$.

Given any vector $\v a = (a_1, \ldots, a_{k-1}, a_k, a_{k+1}, \ldots, a_m)\in \R^m$, we can get $\v b = (a_1, \ldots, a_{k-1}, γ, 0, \ldots, 0)\in \R^m$ where $γ = \pm\sqrt{a_k^2 + a_{k+1}^2 + \ldots + a_m^2}$ by applying the Householder reflection for $\v u = \v a - \v b = (0,\ldots,0, a_k - γ, a_{k+1}, \ldots, a_m)$. Note that $H_u$ has the block matrix form $$ \begin{align*} H_\v u = \pmat{I_{k-1} & 0 \\ 0 & *} \end{align*} $$ so the first $k-1$ components are preserved under $H_\v u$.

Therefore we can kill off all subdiagonal entires of a matrix this way: $$ \begin{align*} \pmat{*&*&* \\ *&*&* \\ *&*&* \\ *&*&*} \xrightarrow{H_1} \pmat{\bullet&\bullet&\bullet \\ 0&\bullet&\bullet \\ 0&\bullet&\bullet \\ 0&\bullet&\bullet} \xrightarrow{H_2} \pmat{*&*&* \\ 0&\bullet&\bullet \\ 0&0&\bullet \\ 0&0&\bullet} \xrightarrow{H_3} \pmat{*&*&* \\ 0&*&* \\ 0&0&\bullet \\ 0&0&0} \end{align*} $$ (Legend: $*$ remains the same as the previous matrix; $\bullet$ has changed through a rotation.)

Hence $$ \begin{align*} R = H_m\ldots H_2 H_1 A \implies A = \underbrace{(H_m \ldots H_2H_1)^T}_{Q} R. \end{align*} $$

Example (QR factorisation using Householder reflections)

Practicality:

  • Numerically, don't compute the matrix of $H_\v u$! Always perform vector products $\v v - \frac{2}{\|u\|^2}\v u \v u^T \v v$ instead.

  • How to choose the sign of $γ$?

    • For hand computation, choose $\sign γ = \sign a_k$ to make numbers smaller.

    • For numerical computation, choose $\sign γ = -\sign a_k$ to make numbers larger for stability.

Choosing between Givens and Householder transformations: