Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Woodbury Solve Step by Step

The Woodbury matrix identity turns an n×nn \times n solve into a cheap k×kk \times k solve when the matrix has low-rank structure:

(L+UDV⊤)−1=L−1−L−1U C−1 V⊤L−1(L + U D V^\top)^{-1} = L^{-1} - L^{-1} U \, C^{-1} \, V^\top L^{-1}

where C=D−1+V⊤L−1UC = D^{-1} + V^\top L^{-1} U is the k×kk \times k capacitance matrix.

This notebook walks through each step and shows that gaussx.solve does it automatically.

Background

The Woodbury identity (also known as the matrix inversion lemma or Sherman-Morrison-Woodbury formula) is one of the most important identities in computational linear algebra. It appears in:

  • Sparse GP inference — the Nystrom approximation yields a low-rank + diagonal covariance, and the Woodbury identity turns the n×nn \times n inversion into a k×kk \times k problem where k≪nk \ll n.
  • Kalman filtering — sequential rank-1 updates to the state covariance are applied via the matrix inversion lemma at each time step.
  • Online learning — rank-1 covariance updates (e.g. recursive least squares) use the Sherman-Morrison special case.
  • Ridge regression with feature space formulations — the kernel trick relates the n×nn \times n and p×pp \times p solutions through Woodbury.

The identity was first published by Woodbury (1950) and independently by Sherman & Morrison (1950) for the rank-1 case.

Setup

We construct A=diag(d)+UU⊤A = \mathrm{diag}(d) + U U^\top where d∈R100d \in \mathbb{R}^{100} and U∈R100×3U \in \mathbb{R}^{100 \times 3} (rank 3).

Operator: diag(100) + rank-3 update
  Full matrix size: 100x100 = 10,000 entries
  Low-rank storage: 100 + 100x3 = 400 entries

Step-by-step Woodbury

Step 1: L^{-1} b  — diagonal solve, O(n)
Step 2: L^{-1} U  — 3 diagonal solves, O(nk)
Step 3: C = I + U^T L^{-1} U  — 3x3 matrix
Step 4: C^{-1} (V^T L^{-1} b)  — 3x3 solve
Step 5: x = L^{-1} b - L^{-1} U z  — final answer

Verify against gaussx.solve

Woodbury vs dense:  max|diff| = 5.55e-15
gaussx  vs dense:   max|diff| = 5.55e-15
Woodbury vs gaussx: max|diff| = 0.00e+00

Matrix determinant lemma

Similarly, the logdet decomposes. This follows from the identity

∣A+UDV⊤∣=∣D−1+V⊤A−1U∣⋅∣D∣⋅∣A∣|A + UDV^\top| = |D^{-1} + V^\top A^{-1} U| \cdot |D| \cdot |A|

which is a direct consequence of the Schur complement determinant identity. Taking logarithms:

log⁡∣A+UDV⊤∣=log⁡∣A∣+log⁡∣C∣+log⁡∣D∣\log|A + UDV^\top| = \log|A| + \log|C| + \log|D|

where C=D−1+V⊤A−1UC = D^{-1} + V^\top A^{-1} U is the capacitance matrix. In our case (D=ID = I, V=UV = U):

gaussx logdet:  27.039277
dense logdet:   27.039277
match: True

Visualizing the decomposition

<Figure size 1400x300 with 4 Axes>

Cost comparison

OperationDenseWoodbury
SolveO(n^3)O(nk^2 + k^3)
LogdetO(n^3)O(nk^2 + k^3)
StorageO(n^2)O(nk)

For n=100, k=3: dense does ~10^6 ops, Woodbury does ~900.

References

  • Hager, W. W. (1989). Updating the inverse of a matrix. SIAM Review, 31(2), 221--239.
  • Henderson, H. V. & Searle, S. R. (1981). On deriving the inverse of a sum of matrices. SIAM Review, 23(1), 53--60.
  • Woodbury, M. A. (1950). Inverting Modified Matrices. Statistical Research Group Memo Report 42, Princeton University.