33 Linear Algebra
Every neural network in this book is built out of matrix products: a linear layer multiplies its input by a weight matrix, attention multiplies queries by keys, and a recurrent network multiplies its hidden state by the same matrix at every step. In Section 1.3, we computed these products without asking what a matrix actually does to the vectors it acts on. This optional chapter takes up that geometric question, proofs included; nothing in the main text depends on it, yet seeing the geometry behind matrix products changes how you read almost every model in the book.
Consider a 784-pixel Fashion-MNIST image mapped to 256 features. How similar are two images, how much information does the layer discard, and what happens if we apply the same linear map fifty times in a row? Because we cannot draw in 784 dimensions, our answers come from algebra that carries plane geometry into any dimension.
A complicated matrix becomes transparent once viewed along the right directions. Around 1810, Gauss fitted the orbit of the asteroid Pallas to more observations than unknowns via least squares, a problem our first section solves and our last revisits. In orthonormal axes, lengths and angles reduce to dot products; along eigenvectors, a square matrix scales each direction by a single scalar; and in a pair of singular bases, any matrix decomposes into independent stretches. These ideas explain why attention divides scores by \(\sqrt{d}\) (Section 10.2), when recurrent gradients explode (Section 8.5), and what a low-rank adapter can represent.
The chapter moves in two stages. First, we apply a matrix once: Section 33.1 extends lengths, angles, and orthogonal projections (giving the closest point in a subspace), while Section 33.2 tracks which directions collapse to zero and when a map is invertible. Next, we choose coordinates tailored to the matrix: eigenvectors and the spectral theorem for symmetric matrices (Section 33.3), non-normal behavior that eigenvalues alone miss (Section 33.4), and singular vectors with optimal low-rank truncation for any shape (Section 33.5). Two small matrices keep us honest throughout: \(\mathbf{A}=\left(\begin{smallmatrix}1&2\\-1&3\end{smallmatrix}\right)\), with complex eigenvalues, and the shear \(\mathbf{T}=\left(\begin{smallmatrix}1&1\\0&1\end{smallmatrix}\right)\), whose eigenvectors fail to span the plane.
On a first reading, feel free to skim \(n\)-dimensional determinants and the discussions of Gershgorin discs, PageRank, and pseudospectra in Section 33.4. Numerical eigensolvers and linear solvers are surveyed in Section 33.6.