Step 3 of 6
Determinants, inverses & rank
The determinant as an area scale factor, when inverses exist, and what rank tells you about information loss - with direct connections to regularization and covariance matrices.
14 min read
Every linear transformation either preserves, scales, or destroys information. The determinant is the single number that tells you which - and knowing it unlocks the ideas of invertibility, rank, and regularization.
The determinant - an area scale factor#
Apply a 2 × 2 matrix to the unit square and you get a parallelogram. The determinant is the signed area of that parallelogram - it tells you how much the transformation scales area:
For a 2 × 2 matrix: the determinant is ad − bc. In higher dimensions, it scales volume.
det = 3 (areas triple)
[[2, 0], [0, 1.5]] · det 3
det = 1 (area preserved)
[[1, 1], [0, 1]] · det 1
det = −1 (flipped)
[[-1, 0], [0, 1]] · det -1
det = 0 (squashed flat)
[[1, 0.5], [2, 1]] · det 0
| det | Meaning |
|---|---|
| det > 1 | Areas grow - the transformation expands space |
| det = 1 | Areas preserved - rotations, shears |
| 0 < det < 1 | Areas shrink - the transformation compresses |
| det = 0 | Space is squashed to a lower dimension - information is lost |
| det < 0 | Orientation flips - like looking in a mirror, plus possible scaling |
Singular matrices - when det = 0#
A matrix with determinant zero squashes space flat - a 2D transformation collapses the plane onto a line (or a point), and a 3D transformation flattens a volume onto a plane, line, or point. Different inputs map to the same output. This is why:
- The matrix has no inverse - you can't un-flatten a pancake
- The system of equations Ax = b may have no solution or infinitely many
- The matrix is called singular or degenerate
The inverse - undoing a transformation#
The inverse A⁻¹ is the transformation that reverses A: A⁻¹A = I (the identity, which changes nothing). It exists if and only if det A ≠ 0.
For a 2 × 2 matrix: swap the diagonal, negate the off-diagonal, divide by the determinant.
Computing inverses for large matrices is expensive and numerically fragile. In practice, ML frameworks solve the linear system Ax = b directly (via LU decomposition or similar) rather than computing A⁻¹ explicitly.
Rank - the dimension of the output#
The rank of a matrix is the dimension of its column space - the number of linearly independent columns. It tells you how much of the output space the transformation actually reaches:
| Rank | Situation |
|---|---|
| Full rank (rank = min(m,n)) | The transformation is as expressive as possible; if square, it's invertible |
| Rank-deficient (rank < min(m,n)) | Some directions are collapsed; the output lives in a subspace |
| Rank 1 | Everything maps onto a single line |
| Rank 0 | Everything maps to the zero vector (the zero matrix) |
rank(A) = dim(column space of A) = number of linearly independent columns.
In ML:
- LoRA explicitly constrains the rank: ΔW = BA where B is n × r and A is r × n, so rank(ΔW) ≤ r. A rank-16 adapter captures the most important 16 directions of weight change.
- A low-rank approximation (via SVD) keeps only the top-k singular values - the best rank-k summary of the matrix.
- Attention matrices in practice often have low effective rank, which is why techniques like low-rank attention and sparse attention work.
- LoRA
- Low-Rank Adaptation - constrains weight updates to a low-rank matrix (rank r ≪ n), capturing the most important directions of change with far fewer parameters.
- SVD
- Singular Value Decomposition - factors any matrix into rotation × scaling × rotation, revealing how much information each component carries.
- Singular values
- The diagonal entries in SVD that measure each component's importance - truncating the smallest ones gives the best low-rank approximation of a matrix.
Regularization - making matrices invertible#
When XᵀX is nearly singular (some eigenvalues close to zero), inverting it amplifies noise. Ridge regression adds λI to the diagonal:
Ridge regression: add λI to guarantee the matrix is invertible and the solution is stable.
This shifts every eigenvalue by λ, pulling them away from zero. The determinant of (XᵀX + λI) is the product of (λᵢ + λ) for each eigenvalue λᵢ - guaranteed positive. The trade-off: larger λ means more bias but less variance.
- Ridge regression
- Linear regression with an L2 penalty - adds λI to make the system invertible and the solution stable, at the cost of slight bias.
- Eigenvalue
- The factor by which an eigenvector is scaled when a matrix acts on it - eigenvalues near zero signal near-singularity and numerical instability.
- Weight decay
- Shrinks all weights slightly toward zero at each training step - the neural network equivalent of ridge regression's λ penalty.
Where it shows up in ML#
Regularization prevents singularity
Adding λI to XᵀX (ridge) or penalizing ‖w‖² (weight decay) keeps the system well-conditioned.
LoRA controls rank
ΔW = BA with inner dimension r ≪ n: a deliberate rank constraint that makes fine-tuning efficient.
Covariance matrices must be invertible
Gaussian mixture models, Mahalanobis distance, and GPs all need to invert covariance matrices - singularity breaks them.
Numerical stability matters
In practice, libraries use decompositions (LU, Cholesky, QR) rather than explicit inverses to avoid determinant-related instability.