We learnt Cholesky decomposition and QR decomposition approaches for solving linear regression.
The popular statistical software SAS uses sweep operator for linear regression and matrix inversion.
Assume $\mathbf{A}$ is symmetric and positive semidefinite.
Sweep on the $k$-th diagonal entry $a_{kk} \ne 0$ yields $\widehat A$ with entries
$n^2$ flops (taking into account of symmetry).
$n^2$ flops (taking into account of symmetry).
$\check{\hat{\mathbf{A}}} = \mathbf{A}$.
Successively sweeping all diagonal entries of $\mathbf{A}$ yields $- \mathbf{A}^{-1}$.
Exercise: invert a $2 \times 2$ matrix, say
on paper using sweep operator.
If possible, sweep on the diagonal entries of $\mathbf{A}_{11}$ yields
Order dose not matter. The block $\mathbf{A}_{22} - \mathbf{A}_{21} \mathbf{A}_{11}^{-1} \mathbf{A}_{12}$ is recognized as the Schur complement of $\mathbf{A}_{11}$.
Sweep on the Gram matrix
$$
\begin{pmatrix}
\mathbf{X}^T \mathbf{X} & \mathbf{X}^T \mathbf{y} \\
\mathbf{y}^T \mathbf{X} & \mathbf{y}^T \mathbf{y}
\end{pmatrix}
$$
yields
In total $np^2 + p^3$ flops.
$n^3$ flops. Recall that inversion by Cholesky costs $(1/3)n^3 + (4/3) n^3 = (5/3) n^3$ flops and needs to allocate a matrix of same size.
# Pkg.add("SweepOperator")
using SweepOperator
srand(280)
X = randn(5, 3) # predictor matrix
y = randn(5) # response vector
# form the augmented Gram matrix
G = [X y]' * [X y]
4×4 Array{Float64,2}: 9.589 -4.98208 -5.70052 -1.83933 -4.98208 4.94476 3.81663 2.82462 -5.70052 3.81663 5.45442 2.46008 -1.83933 2.82462 2.46008 4.98343
sweep!(G, 1:3)
4×4 Array{Float64,2}: -0.312747 -0.136595 -0.231278 0.379547 -4.98208 -0.499383 0.206676 0.650887 -5.70052 3.81663 -0.569668 0.39225 -1.83933 2.82462 2.46008 2.87807
# least squares solution by QR
X \ y
3-element Array{Float64,1}: 0.379547 0.650887 0.39225
# inverse sweep to restore original matrix
sweep!(G, 1:3, true)
4×4 Array{Float64,2}: 9.589 -4.98208 -5.70052 -1.83933 -4.98208 4.94476 3.81663 2.82462 -5.70052 3.81663 5.45442 2.46008 -1.83933 2.82462 2.46008 4.98343
Section 7.4-7.6 of Numerical Analysis for Statisticians by Kenneth Lange (2010). Probably the best place to read about sweep operator.
The paper A tutorial on the SWEEP operator by James H. Goodnight (1979). Note this version (anti-symmetry matrix) is slightly different from ours.
versioninfo()
Julia Version 0.6.2 Commit d386e40c17 (2017-12-13 18:08 UTC) Platform Info: OS: macOS (x86_64-apple-darwin14.5.0) CPU: Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz WORD_SIZE: 64 BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell) LAPACK: libopenblas64_ LIBM: libopenlibm LLVM: libLLVM-3.9.1 (ORCJIT, skylake)