The Moore-Penrose Pseudoinverse
A generalized 'inverse' that works even for matrices too tall, too wide, or too redundant to invert normally — the operation underneath ordinary least squares regression.
Prerequisites: Matrix Inverses and Linear Systems, Singular Value Decomposition
Ordinary matrix inverses only exist for square, full-rank matrices, but real data almost never comes that neatly shaped. A regression with 500 daily returns and 5 factors has a design matrix — not square, so it has no ordinary inverse at all. The Moore-Penrose pseudoinverse is the fix: a generalized inverse that exists for any matrix, square or not, full rank or not, and that produces the best possible approximate answer when an exact one doesn't exist.
An analogy: fitting a line through scattered points
You can't draw a single straight line that passes exactly through every point of a noisy scatter of stock returns against a factor — there are more data points (equations) than there is freedom in the line (two unknowns: slope and intercept), so no exact solution exists. But you can find the line that comes closest, in a precise least-squares sense, minimizing the total squared vertical distance from the points to the line. The pseudoinverse is the machinery that produces exactly this "closest possible" answer whenever a system is over- or under-determined, rather than giving up because no exact solution exists.
The mathematics, one symbol at a time
For a matrix that is tall (more rows than columns, an over-determined system) and full column rank, the pseudoinverse is
read as: transpose , multiply it by to get a square matrix that (unlike itself) usually is invertible, invert that, then multiply by again. Applying to a target vector that has no exact solution to gives , the vector that minimizes — the total squared error between what actually produces and the target you wanted. In words: when no can hit exactly, finds the that gets closest, in the sense of smallest total squared miss. For a square, invertible , the pseudoinverse reduces exactly to the ordinary inverse — it's a strict generalization, not a different concept.
Worked example 1: least-squares regression by hand
Three data points relate a factor to a return : , and we fit (no intercept, for simplicity). Here , . Then , and . So . This is exactly the ordinary least-squares slope — the pseudoinverse and OLS are the same computation. Checking fit: predicted values are against actual — close but not exact, exactly as expected since three points can't lie perfectly on one line through the origin.
Worked example 2: an under-determined system
Now the opposite case: fewer equations than unknowns, e.g. one equation (a single constraint, two unknowns) — infinitely many solutions exist (; ; and everywhere between). The pseudoinverse picks out the minimum-norm solution: the one closest to the origin among all valid solutions, which here is (by symmetry, splitting the constraint evenly minimizes ). This "smallest, most conservative solution among the valid ones" behavior is why the pseudoinverse is also used to regularize under-determined systems, like allocating weight across many correlated factors with no unique answer.
What this means in practice
Whenever numpy.linalg.lstsq or a regression library fits coefficients, it's computing (a numerically stable version of) the pseudoinverse under the hood — this is the actual mechanism behind ordinary least squares. It's essential when the design matrix isn't full rank (near-duplicate factors) or isn't square (more or fewer observations than parameters), both extremely common situations in factor models and signal construction.
The pseudoinverse generalizes the matrix inverse to any matrix: applied to a target with no exact solution it returns the least-squares best fit, and applied to an under-determined system it returns the minimum-norm solution — and it reduces exactly to the ordinary inverse when one already exists.
Computing literally, as written, is numerically dangerous in practice: forming squares the matrix's condition number (see The Matrix Condition Number), amplifying any near-collinearity in the columns into serious numerical error before you even invert anything. Production code computes the pseudoinverse via a QR or SVD-based algorithm (see QR Decomposition and Singular Value Decomposition) instead of literally forming , even though the formula above is the right way to understand what it computes.
Related concepts
Practice in interviews
Further reading
- Golub & Van Loan, Matrix Computations, ch. 5
- Strang, Introduction to Linear Algebra, ch. 7