- Householder Qr Factorization Calculator
- Qr Factorization Householder
- Qr Householder Method
- Householder Qr Decomposition
Thus, it would be benecial if the QR factorization can be implementated as the successive application of unitary transformations. The Householder QR factorization accomplishes this. The rst fundamental insight is that the product of unitary matrices is itself unitary. If, given A2Cm n(with mn), one could nd a sequence of unitary matrices, fH. A = QR: This factorization can be constructed by three methods: 1. Givens † Property 3.3 (Reduced QR) Suppose the rank of A 2 Rm£n is n for which A = QR is known. Then A = QR where Q and R are submatrices of Q and R given respectively by Q = Q = Q(1: m;1: n); R = R(1: n;1: n): Moreover Q has. Householder transformation and QR decomposition A Householder transformation of a vector is its reflection with respect a plane (or hyperplane) through the origin represented by its normal vector of unit length, which can be found as where is the projection of onto. In general, the projection of onto any vector is. How can you implement Householder based QR decomposition in Python? Ask Question Asked 2 years, 2 months ago. Active 9 months ago. Viewed 4k times 2.
The more common approach to QR decomposition is employing Householder reflections rather than utilizing Gram-Schmidt. In practice, the Gram-Schmidt procedure is not recommended as it can lead to cancellation that causes inaccuracy of the computation of [latex]q_j[/latex], which may result in a non-orthogonal [latex]Q[/latex] matrix. Householder reflections are another method of orthogonal transformation that transforms a vector [latex]x[/latex] into a unit vector [latex]y[/latex] parallel with [latex]x[/latex]. The Householder reflection matrix with normal vector [latex]v[/latex] takes the form:
[latex display='true'] H = I – 2vv^T [/latex]
Thus we need to build [latex]H[/latex] so that [latex]Hx = alpha e_1[/latex] for some constant [latex]alpha[/latex] and [latex]e_1 = begin{bmatrix} 1 & 0 & 0 end{bmatrix}^T[/latex].
Since [latex]H[/latex] is orthogonal, [latex]||Hx|| = ||x||[/latex] and [latex]||alpha e_1|| = |alpha| ||e_1|| = |alpha|[/latex]. Therefore, [latex]alpha = pm ||x||[/latex]. The sign is selected so it has the opposite sign of [latex]x_1[/latex] (we'll use [latex]+[/latex] for the remaining definitions). The vector [latex]u[/latex] we seek is thus:
V-Slot is made with 6063 T-5 Aluminum Extrusion and has a Beautiful, Shiny, Super Smooth, Clear Anodized Finished. V-Slot's finish is much shinier than standard T-Slot extrusion which allows for a smoother ride for the Dual V Wheels. Use the Low Profile M5 Screws in conjunction with V-Slot.
[latex display='true'] u = begin{bmatrix} x_1 + sign(x_1) ||x_1|| x_2 vdots x_n end{bmatrix} [/latex]
With the unit vector [latex]v[/latex] defined as [latex]u = frac{v}{||v||}[/latex]. The corresponding Householder reflection is then:
[latex display='true'] H(x) = I – 2vv^T = I – 2 frac{uu^T}{u^Tu} [/latex]
QR Decomposition with Householder ReflectionsThe Householder reflection method of QR decomposition works by finding appropriate [latex]H[/latex] matrices and multiplying them from the left by the original matrix [latex]A[/latex] to construct the upper triangular matrix [latex]R[/latex]. As we saw earlier, unlike the Gram-Schmidt procedure, the Householder reflection approach does not explicitly form the [latex]Q[/latex] matrix. However, the [latex]Q[/latex] matrix can be found by taking the dot product of each successively formed Householder matrix.
[latex display='true'] Q = H_1 H_2 cdots H_{m-2}H_{m-1}[/latex]
Consider the matrix [latex]A[/latex].
[latex display='true']A = begin{bmatrix} 2 & – 2 & 18 2 & 1 & 0 1 & 2 & 0 end{bmatrix}[/latex]
We find the reflection of the first column vector [latex]a_1 = begin{bmatrix}2 & 2 & 1 end{bmatrix}^T[/latex], [latex]v_1 = a_1 + sign(a_{11})||a_1||e_1[/latex].
[latex display='true'] v_1 = begin{bmatrix}2 2 1 end{bmatrix} + sqrt{sum^m_{k=1}{a_1}^2} begin{bmatrix}1 0 0 end{bmatrix} = begin{bmatrix} 5 2 1 end{bmatrix} [/latex]
With a corresponding Householder matrix:
Householder Qr Factorization Calculator
[latex display='true'] H_1 = begin{bmatrix} 1 & 0 & 0 0 & 1 & 0 0 & 0 & 1 end{bmatrix} – 2 frac{begin{bmatrix} 2 & 2 & 1 end{bmatrix}begin{bmatrix} 2 2 1 end{bmatrix}}{begin{bmatrix} 2 2 1 end{bmatrix}begin{bmatrix} 2 & 2 & 1 end{bmatrix}} = [/latex]
[latex display='true'] H_1 = begin{bmatrix} -frac{2}{3} & -frac{2}{3} & -frac{1}{3} -frac{2}{3} & 0.7333 & -0.1333 -frac{1}{3} & -0.1333 & 0.9333 end{bmatrix} [/latex]
With [latex]H_1[/latex], we then find [latex]R[/latex] by [latex]H_1 A[/latex]:
[latex display='true'] H_1 A = begin{bmatrix} -frac{2}{3} & -frac{2}{3} & -frac{1}{3} -frac{2}{3} & 0.7333 & -0.1333 -frac{1}{3} & -0.1333 & 0.9333 end{bmatrix} begin{bmatrix} 2 & – 2 & 18 2 & 1 & 0 1 & 2 & 0 end{bmatrix} [/latex]
[latex display='true'] H_1 A = begin{bmatrix} -3 & 0 & -12 0 & 1.8 & 12 0 & 2.4 & -6 end{bmatrix} [/latex]
[latex]H_1A[/latex] replaces [latex]A[/latex] in the next iteration. Now we move to [latex]a_2[/latex] and [latex]H_2[/latex]. To this end we only consider the submatrix of [latex]A[/latex]:
[latex display='true'] A^{(1)} = begin{bmatrix} 1.8 & 12 2.4 & -6 end{bmatrix} [/latex]
Thus, [latex]v_2[/latex] is equal to:
[latex display='true'] begin{bmatrix} 1.8 2.4 end{bmatrix} + sqrt{sum^m_{j=1} a_2^2} begin{bmatrix} 1 0 end{bmatrix} = begin{bmatrix} 4.8 2.4 end{bmatrix}[/latex]
Therefore, the corresponding Householder matrix [latex]H_2[/latex] is equal to:
[latex display='true'] H_2 = begin{bmatrix} 1 & 0 0 & 1 end{bmatrix} – 2 frac{begin{bmatrix} 4.8 & 2.4 end{bmatrix} begin{bmatrix} 4.8 2.4 end{bmatrix}}{begin{bmatrix} 4.8 2.4 end{bmatrix} begin{bmatrix} 4.8 & 2.4 end{bmatrix}} [/latex]
[latex display='true'] H_2 = begin{bmatrix} 1 & 0 & 0 0 & -0.6 & -0.8 0 & -0.8 & 0.6 end{bmatrix} [/latex]
The first column [latex]begin{bmatrix}1 0 0 end{bmatrix}[/latex] and first row [latex]begin{bmatrix}1 & 0 & 0 end{bmatrix}[/latex] are added to the resulting [latex]H_2[/latex] matrix to keep it [latex]n times n[/latex].
Then we find [latex]H_2 A[/latex]:
[latex display='true'] begin{bmatrix} 1 & 0 & 0 0 & -0.6 & -0.8 0 & -0.8 & 0.6 end{bmatrix} begin{bmatrix} -3 & 0 & -12 0 & 1.8 & 12 0 & 2.4 & -6 end{bmatrix} [/latex]
[latex display='true'] H_2 A = begin{bmatrix} -3 & 0 & -12 0 & -3 & 12 0 & 0 & 6 end{bmatrix}[/latex]
Moving to [latex]a_3[/latex] and [latex]H_3[/latex], the submatrix of [latex]H_2 A[/latex] is thus [latex][6][/latex]. Therefore, [latex]v_3[/latex] is equal to:
[latex display='true'] begin{bmatrix} 6 end{bmatrix} – sqrt{sum^m_{j=1} a_3^2} begin{bmatrix} 1 end{bmatrix} = 12 [/latex]
The corresponding Householder matrix [latex]H_3[/latex] is then:
[latex display='true'] H_3 = begin{bmatrix} 1 end{bmatrix} – 2 frac{begin{bmatrix} 12 end{bmatrix}begin{bmatrix} 12 end{bmatrix}}{begin{bmatrix} 12 end{bmatrix}begin{bmatrix} 12 end{bmatrix}} = begin{bmatrix}1 & 0 & 0 0 & 1 & 0 0 & 0 & -1 end{bmatrix}[/latex]
[latex display='true']H_3 A = begin{bmatrix}1 & 0 & 0 0 & 1 & 0 0 & 0 & -1 end{bmatrix} begin{bmatrix} -3 & 0 & -12 0 & -3 & 12 0 & 0 & 6 end{bmatrix} [/latex]
[latex display='true'] H_3 A = R = begin{bmatrix} -3 & 0 & -12 0 & -3 & 12 0 & 0 & -6 end{bmatrix} [/latex]
Which is the [latex]R[/latex] factorization in the QR decomposition method. The [latex]Q[/latex] factorization of QR decomposition is found by multiplying all the [latex]H[/latex] matrices together as mentioned earlier.
[latex display='true'] H_1 H_2 H_3 = Q [/latex]
[latex display='true'] Q = begin{bmatrix} -frac{2}{3} & -frac{2}{3} & -frac{1}{3} -frac{2}{3} & 0.7333 & -0.1333 -frac{1}{3} & -0.1333 & 0.9333 end{bmatrix} begin{bmatrix} 1 & 0 & 0 0 & -0.6 & -0.8 0 & -0.8 & 0.6 end{bmatrix} begin{bmatrix}1 & 0 & 0 0 & 1 & 0 0 & 0 & -1 end{bmatrix} [/latex]
[latex display='true'] Q = begin{bmatrix} -frac{2}{3} & frac{2}{3} & -frac{1}{3} -frac{2}{3} & -frac{1}{3} & frac{2}{3} -frac{1}{3} & -frac{2}{3} & -frac{2}{3} end{bmatrix} [/latex]
Thus we obtain the same result as we did utilizing the Gram-Schmidt procedure.
[latex display='true'] QR = begin{bmatrix} -frac{2}{3} & frac{2}{3} & -frac{1}{3} -frac{2}{3} & -frac{1}{3} & frac{2}{3} -frac{1}{3} & -frac{2}{3} & -frac{2}{3} end{bmatrix} begin{bmatrix} -3 & 0 & -12 0 & -3 & 12 0 & 0 & -6 end{bmatrix} [/latex]
The following function implements the Householder reflections approach to QR decomposition. The bdiag()
function in the Matrix package is used in constructing the [latex]H[/latex] matrices as seen above in the calculation of [latex]H_2[/latex].
Use the function to compute the QR decomposition of the following matrix [latex]A[/latex] with Householder reflections.
The only package that I found that directly implements the Householder reflection approach to QR is the pracma package.
ReferencesEn.wikipedia.org. (2017). QR decomposition. [online] Available at: https://en.wikipedia.org/wiki/QR_decomposition#Using_Householder_reflections [Accessed 10 Apr. 2017].
Trefethen, L. and Bau, D. (1997). Numerical linear algebra. 1st ed. Philadelphia: SIAM.
The post QR Decomposition with Householder Reflections appeared first on Aaron Schlegel.
$initialize$So far, we have only shown existence , but How do we compute QR decompositions?
Householder Reflections
Householder reflection is $H=I-2vv'$ where $norm v2=1$ which reflects over hyperplane orthogonal to $v$
Lemma. Householder reflections are orthogonal matrices
Proof. $~$ HOMEWORK
We use a series of Householder reflections to reduce $APi$ to an upper triangular matrix, and the resultant product of Householder matrices gives us $Q,$, i.e. $$underbrace{H_rcdots H_1}_{Q'}APi=R$$
First, find $H_1$ that makes every entry below $R_{11}$ zero,
begin{align*}
H_1a_1&=R_{11}e_1
R_{11}e_1&=a_1-2v_1v_1'a_1
v_1(underbrace{2v_1'a_1}_text{scalar})&=a_1-R_{11}e_1
implies~v_1&=frac{a_1-R_{11}e_1}{norm{a_1-R_{11}e_1}2}
implies~R_{11}e_1&=pmnorm{a_1}2
v_1&=frac{a_1-norm{a_1}{}e_1}{norm{vphantom{big|};!a_1-norm{a_1}{}e_1}2}
implies H_1&=I-frac{(a_1-norm{a_1}{}e_1)(a_1-norm{a_1}{}e_1)'}{norm{vphantom{big|};!a_1-norm{a_1}{}e_1}{}_2^2}
end{align*}
Then, we have
$$H_aAPi~=~defhmatres{{begin{matrix}begin{matrix}R_{11}&text{--------------}~~end{matrix}begin{matrix}begin{matrix}0vdots0&end{matrix}&!!!!!!mat{&&&tilde{A}_2&&&}end{matrix}end{matrix}}}left[{begin{matrix}begin{matrix}R_{11}&text{--------------}~~end{matrix}begin{matrix}begin{matrix}0vdots0&end{matrix}&!!!!!!underbrace{mat{&&&tilde{A}_2&&&}}_text{repeat on these}end{matrix}end{matrix}}^{vphantom{Big|}}right]$$
Givens Rotations
Givens rotations $Gij$ where $Gij$ is the identity matrix except
- $Gij_{ii}=Gij_{jj}=lambda$
- $Gij_{ij}=sigma$
- $Gij_{ji}=-sigma$
$$text{for example, },G^{(2,4)}=mat{1&0&0&00&lambda&0&sigma0&0&1&00&-sigma&0&lambda}$$
HOMEWORK $~$ Show that Givens rotation is orthogonal when $sigma^2+lambda^2=1$
We can also use Givens rotations to compute the decomposition, so that $$underbrace{G_Tcdots G_1}_{Q'}APi=R$$
To find $G_1$, we look for a Givens rotation $G^{(1,2)}$ that will make the entry in row 2 column 1 of the product equal to zero. Consider the product with the following matrix $M$ $$mat{lambda&sigma-sigma&lambda},mat{M_{11}&M_{12}&cdots&M_{1m}M_{21}&M_{22}&cdots&M_{2m}}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=mat{hphantom{-}lambda M_{11}+sigma M_{21}&hphantom{-1}lambda M_{12}+sigma M_{22}&cdots&hphantom{-1}lambda M_{1m}+sigma M_{2m}-sigma M_{11}+lambda M_{21}&-sigma M_{12}+lambda M_{22}&cdots&-sigma M_{1m}+lambda M_{2m}}$$
To find $G_1$, we solve $$begin{matrix}begin{split}-sigma M_{11}+lambda M_{21}&=0text{s.t. }~~~~~~~~~~~~~sigma^2+lambda^2&=1end{split}end{matrix}~~~~~~~implies~~~~~~~begin{matrix}lambda=frac{M_{11}}{sqrt{M_{11}^2+M_{21}^2}}~~~text{and}~~~sigma=frac{M_{21}}{sqrt{M_{11}^2+M_{21}^2}}end{matrix}$$
Now, we can repeat this process to successively make all entries below the diagonal zero, giving us a QR decomposition.
Since [latex]H[/latex] is orthogonal, [latex]||Hx|| = ||x||[/latex] and [latex]||alpha e_1|| = |alpha| ||e_1|| = |alpha|[/latex]. Therefore, [latex]alpha = pm ||x||[/latex]. The sign is selected so it has the opposite sign of [latex]x_1[/latex] (we'll use [latex]+[/latex] for the remaining definitions). The vector [latex]u[/latex] we seek is thus:
V-Slot is made with 6063 T-5 Aluminum Extrusion and has a Beautiful, Shiny, Super Smooth, Clear Anodized Finished. V-Slot's finish is much shinier than standard T-Slot extrusion which allows for a smoother ride for the Dual V Wheels. Use the Low Profile M5 Screws in conjunction with V-Slot.
[latex display='true'] u = begin{bmatrix} x_1 + sign(x_1) ||x_1|| x_2 vdots x_n end{bmatrix} [/latex]
With the unit vector [latex]v[/latex] defined as [latex]u = frac{v}{||v||}[/latex]. The corresponding Householder reflection is then:
[latex display='true'] H(x) = I – 2vv^T = I – 2 frac{uu^T}{u^Tu} [/latex]
QR Decomposition with Householder ReflectionsThe Householder reflection method of QR decomposition works by finding appropriate [latex]H[/latex] matrices and multiplying them from the left by the original matrix [latex]A[/latex] to construct the upper triangular matrix [latex]R[/latex]. As we saw earlier, unlike the Gram-Schmidt procedure, the Householder reflection approach does not explicitly form the [latex]Q[/latex] matrix. However, the [latex]Q[/latex] matrix can be found by taking the dot product of each successively formed Householder matrix.
[latex display='true'] Q = H_1 H_2 cdots H_{m-2}H_{m-1}[/latex]
Consider the matrix [latex]A[/latex].
[latex display='true']A = begin{bmatrix} 2 & – 2 & 18 2 & 1 & 0 1 & 2 & 0 end{bmatrix}[/latex]
We find the reflection of the first column vector [latex]a_1 = begin{bmatrix}2 & 2 & 1 end{bmatrix}^T[/latex], [latex]v_1 = a_1 + sign(a_{11})||a_1||e_1[/latex].
[latex display='true'] v_1 = begin{bmatrix}2 2 1 end{bmatrix} + sqrt{sum^m_{k=1}{a_1}^2} begin{bmatrix}1 0 0 end{bmatrix} = begin{bmatrix} 5 2 1 end{bmatrix} [/latex]
With a corresponding Householder matrix:
Householder Qr Factorization Calculator
[latex display='true'] H_1 = begin{bmatrix} 1 & 0 & 0 0 & 1 & 0 0 & 0 & 1 end{bmatrix} – 2 frac{begin{bmatrix} 2 & 2 & 1 end{bmatrix}begin{bmatrix} 2 2 1 end{bmatrix}}{begin{bmatrix} 2 2 1 end{bmatrix}begin{bmatrix} 2 & 2 & 1 end{bmatrix}} = [/latex]
[latex display='true'] H_1 = begin{bmatrix} -frac{2}{3} & -frac{2}{3} & -frac{1}{3} -frac{2}{3} & 0.7333 & -0.1333 -frac{1}{3} & -0.1333 & 0.9333 end{bmatrix} [/latex]
With [latex]H_1[/latex], we then find [latex]R[/latex] by [latex]H_1 A[/latex]:
[latex display='true'] H_1 A = begin{bmatrix} -frac{2}{3} & -frac{2}{3} & -frac{1}{3} -frac{2}{3} & 0.7333 & -0.1333 -frac{1}{3} & -0.1333 & 0.9333 end{bmatrix} begin{bmatrix} 2 & – 2 & 18 2 & 1 & 0 1 & 2 & 0 end{bmatrix} [/latex]
[latex display='true'] H_1 A = begin{bmatrix} -3 & 0 & -12 0 & 1.8 & 12 0 & 2.4 & -6 end{bmatrix} [/latex]
[latex]H_1A[/latex] replaces [latex]A[/latex] in the next iteration. Now we move to [latex]a_2[/latex] and [latex]H_2[/latex]. To this end we only consider the submatrix of [latex]A[/latex]:
[latex display='true'] A^{(1)} = begin{bmatrix} 1.8 & 12 2.4 & -6 end{bmatrix} [/latex]
Thus, [latex]v_2[/latex] is equal to:
[latex display='true'] begin{bmatrix} 1.8 2.4 end{bmatrix} + sqrt{sum^m_{j=1} a_2^2} begin{bmatrix} 1 0 end{bmatrix} = begin{bmatrix} 4.8 2.4 end{bmatrix}[/latex]
Therefore, the corresponding Householder matrix [latex]H_2[/latex] is equal to:
[latex display='true'] H_2 = begin{bmatrix} 1 & 0 0 & 1 end{bmatrix} – 2 frac{begin{bmatrix} 4.8 & 2.4 end{bmatrix} begin{bmatrix} 4.8 2.4 end{bmatrix}}{begin{bmatrix} 4.8 2.4 end{bmatrix} begin{bmatrix} 4.8 & 2.4 end{bmatrix}} [/latex]
[latex display='true'] H_2 = begin{bmatrix} 1 & 0 & 0 0 & -0.6 & -0.8 0 & -0.8 & 0.6 end{bmatrix} [/latex]
The first column [latex]begin{bmatrix}1 0 0 end{bmatrix}[/latex] and first row [latex]begin{bmatrix}1 & 0 & 0 end{bmatrix}[/latex] are added to the resulting [latex]H_2[/latex] matrix to keep it [latex]n times n[/latex].
Then we find [latex]H_2 A[/latex]:
[latex display='true'] begin{bmatrix} 1 & 0 & 0 0 & -0.6 & -0.8 0 & -0.8 & 0.6 end{bmatrix} begin{bmatrix} -3 & 0 & -12 0 & 1.8 & 12 0 & 2.4 & -6 end{bmatrix} [/latex]
[latex display='true'] H_2 A = begin{bmatrix} -3 & 0 & -12 0 & -3 & 12 0 & 0 & 6 end{bmatrix}[/latex]
Moving to [latex]a_3[/latex] and [latex]H_3[/latex], the submatrix of [latex]H_2 A[/latex] is thus [latex][6][/latex]. Therefore, [latex]v_3[/latex] is equal to:
[latex display='true'] begin{bmatrix} 6 end{bmatrix} – sqrt{sum^m_{j=1} a_3^2} begin{bmatrix} 1 end{bmatrix} = 12 [/latex]
The corresponding Householder matrix [latex]H_3[/latex] is then:
[latex display='true'] H_3 = begin{bmatrix} 1 end{bmatrix} – 2 frac{begin{bmatrix} 12 end{bmatrix}begin{bmatrix} 12 end{bmatrix}}{begin{bmatrix} 12 end{bmatrix}begin{bmatrix} 12 end{bmatrix}} = begin{bmatrix}1 & 0 & 0 0 & 1 & 0 0 & 0 & -1 end{bmatrix}[/latex]
[latex display='true']H_3 A = begin{bmatrix}1 & 0 & 0 0 & 1 & 0 0 & 0 & -1 end{bmatrix} begin{bmatrix} -3 & 0 & -12 0 & -3 & 12 0 & 0 & 6 end{bmatrix} [/latex]
[latex display='true'] H_3 A = R = begin{bmatrix} -3 & 0 & -12 0 & -3 & 12 0 & 0 & -6 end{bmatrix} [/latex]
Which is the [latex]R[/latex] factorization in the QR decomposition method. The [latex]Q[/latex] factorization of QR decomposition is found by multiplying all the [latex]H[/latex] matrices together as mentioned earlier.
[latex display='true'] H_1 H_2 H_3 = Q [/latex]
[latex display='true'] Q = begin{bmatrix} -frac{2}{3} & -frac{2}{3} & -frac{1}{3} -frac{2}{3} & 0.7333 & -0.1333 -frac{1}{3} & -0.1333 & 0.9333 end{bmatrix} begin{bmatrix} 1 & 0 & 0 0 & -0.6 & -0.8 0 & -0.8 & 0.6 end{bmatrix} begin{bmatrix}1 & 0 & 0 0 & 1 & 0 0 & 0 & -1 end{bmatrix} [/latex]
[latex display='true'] Q = begin{bmatrix} -frac{2}{3} & frac{2}{3} & -frac{1}{3} -frac{2}{3} & -frac{1}{3} & frac{2}{3} -frac{1}{3} & -frac{2}{3} & -frac{2}{3} end{bmatrix} [/latex]
Thus we obtain the same result as we did utilizing the Gram-Schmidt procedure.
[latex display='true'] QR = begin{bmatrix} -frac{2}{3} & frac{2}{3} & -frac{1}{3} -frac{2}{3} & -frac{1}{3} & frac{2}{3} -frac{1}{3} & -frac{2}{3} & -frac{2}{3} end{bmatrix} begin{bmatrix} -3 & 0 & -12 0 & -3 & 12 0 & 0 & -6 end{bmatrix} [/latex]
Householder Reflection QR Decomposition in RThe following function implements the Householder reflections approach to QR decomposition. The bdiag()
function in the Matrix package is used in constructing the [latex]H[/latex] matrices as seen above in the calculation of [latex]H_2[/latex].
Use the function to compute the QR decomposition of the following matrix [latex]A[/latex] with Householder reflections.
The only package that I found that directly implements the Householder reflection approach to QR is the pracma package.
ReferencesEn.wikipedia.org. (2017). QR decomposition. [online] Available at: https://en.wikipedia.org/wiki/QR_decomposition#Using_Householder_reflections [Accessed 10 Apr. 2017].
Trefethen, L. and Bau, D. (1997). Numerical linear algebra. 1st ed. Philadelphia: SIAM.
The post QR Decomposition with Householder Reflections appeared first on Aaron Schlegel.
$initialize$So far, we have only shown existence , but How do we compute QR decompositions?
Householder Reflections
Householder reflection is $H=I-2vv'$ where $norm v2=1$ which reflects over hyperplane orthogonal to $v$
Lemma. Householder reflections are orthogonal matrices
Proof. $~$ HOMEWORK
We use a series of Householder reflections to reduce $APi$ to an upper triangular matrix, and the resultant product of Householder matrices gives us $Q,$, i.e. $$underbrace{H_rcdots H_1}_{Q'}APi=R$$
First, find $H_1$ that makes every entry below $R_{11}$ zero,
begin{align*}
H_1a_1&=R_{11}e_1
R_{11}e_1&=a_1-2v_1v_1'a_1
v_1(underbrace{2v_1'a_1}_text{scalar})&=a_1-R_{11}e_1
implies~v_1&=frac{a_1-R_{11}e_1}{norm{a_1-R_{11}e_1}2}
implies~R_{11}e_1&=pmnorm{a_1}2
v_1&=frac{a_1-norm{a_1}{}e_1}{norm{vphantom{big|};!a_1-norm{a_1}{}e_1}2}
implies H_1&=I-frac{(a_1-norm{a_1}{}e_1)(a_1-norm{a_1}{}e_1)'}{norm{vphantom{big|};!a_1-norm{a_1}{}e_1}{}_2^2}
end{align*}
Then, we have
$$H_aAPi~=~defhmatres{{begin{matrix}begin{matrix}R_{11}&text{--------------}~~end{matrix}begin{matrix}begin{matrix}0vdots0&end{matrix}&!!!!!!mat{&&&tilde{A}_2&&&}end{matrix}end{matrix}}}left[{begin{matrix}begin{matrix}R_{11}&text{--------------}~~end{matrix}begin{matrix}begin{matrix}0vdots0&end{matrix}&!!!!!!underbrace{mat{&&&tilde{A}_2&&&}}_text{repeat on these}end{matrix}end{matrix}}^{vphantom{Big|}}right]$$
Givens Rotations
Givens rotations $Gij$ where $Gij$ is the identity matrix except
- $Gij_{ii}=Gij_{jj}=lambda$
- $Gij_{ij}=sigma$
- $Gij_{ji}=-sigma$
$$text{for example, },G^{(2,4)}=mat{1&0&0&00&lambda&0&sigma0&0&1&00&-sigma&0&lambda}$$
HOMEWORK $~$ Show that Givens rotation is orthogonal when $sigma^2+lambda^2=1$
We can also use Givens rotations to compute the decomposition, so that $$underbrace{G_Tcdots G_1}_{Q'}APi=R$$
To find $G_1$, we look for a Givens rotation $G^{(1,2)}$ that will make the entry in row 2 column 1 of the product equal to zero. Consider the product with the following matrix $M$ $$mat{lambda&sigma-sigma&lambda},mat{M_{11}&M_{12}&cdots&M_{1m}M_{21}&M_{22}&cdots&M_{2m}}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=mat{hphantom{-}lambda M_{11}+sigma M_{21}&hphantom{-1}lambda M_{12}+sigma M_{22}&cdots&hphantom{-1}lambda M_{1m}+sigma M_{2m}-sigma M_{11}+lambda M_{21}&-sigma M_{12}+lambda M_{22}&cdots&-sigma M_{1m}+lambda M_{2m}}$$
To find $G_1$, we solve $$begin{matrix}begin{split}-sigma M_{11}+lambda M_{21}&=0text{s.t. }~~~~~~~~~~~~~sigma^2+lambda^2&=1end{split}end{matrix}~~~~~~~implies~~~~~~~begin{matrix}lambda=frac{M_{11}}{sqrt{M_{11}^2+M_{21}^2}}~~~text{and}~~~sigma=frac{M_{21}}{sqrt{M_{11}^2+M_{21}^2}}end{matrix}$$
Now, we can repeat this process to successively make all entries below the diagonal zero, giving us a QR decomposition.
Qr Factorization Householder
HOMEWORK
- Determine the computational complexity for QR decomposition using
- Gram-Schmidt
- Modified Gram-Schmidt
- Householder reflections
- Givens rotations
- Compare the complexity of Householder vs Givens for a sparse matrix
- Implement QR decomposition using Householder reflections, (input matrix A of full column rank and output Q,R)
- Repeat 3 using Givens rotations
$$~$$
Qr Householder Method
'Large' data least squares
$AinRnm$, where $ngg m~~$ (which is a different situation than $mgg n$)
Optional reference : 'Incremental QR Decomposition' , by Gentleman.
We can apply QR decomposition to solving the least squares equation $Ax=b$ since
begin{align*}
hat{x}&=(A'A)inv A'b
&=((QR)'(QR))inv(QR)'b
&=(R'cancel{Q'Q}R)inv R'Q'b
&=(R'R)inv R'Q'b
&=Rinvcancel{(R')inv R'}Q'b
&=Rinv Q'b
end{align*}
Householder Qr Decomposition
We need to find $Rinv$ and $Q'b$. To do so, consider just the first $m!+!1$ rows of the matrix $mat{A&b},$ and perform QR decomposition to get $$mat{tilde{R}&tilde{Q}'tilde{b}0&tilde{s}}$$ Then, we add one row at a time to the bottom and perform Givens rotations so that $$mat{tilde{R}&tilde{Q}'tilde{b}0&tilde{s}a_{m+2}&b_{m+2}}~~~implies~~~mat{tilde{R}_{m+2}&tilde{Q}_{m+2}'tilde{b}_{m+2}0&tilde{s}_{m+2}0&0}$$
$$~$$