Qm
Core

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 500×5500 \times 5 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 AA that is tall (more rows than columns, an over-determined system) and full column rank, the pseudoinverse is

A+=(ATA)1AT,A^{+} = (A^T A)^{-1} A^T,

read as: transpose AA, multiply it by AA to get a square matrix that (unlike AA itself) usually is invertible, invert that, then multiply by ATA^T again. Applying A+A^+ to a target vector bb that has no exact solution to Ax=bAx=b gives x=A+bx^* = A^+ b, the vector xx^* that minimizes Axb2\|Ax - b\|^2, the total squared error between what AxAx^* actually produces and the target bb you wanted. In words: when no xx can hit bb exactly, A+bA^+ b finds the xx that gets closest, in the sense of smallest total squared miss. For a square, invertible AA, the pseudoinverse reduces exactly to the ordinary inverse A1A^{-1}, it's a strict generalization, not a different concept.

Worked example 1: least-squares regression by hand

Three data points relate a factor ff to a return rr: (f,r)=(1,2),(2,3),(3,5)(f,r) = (1, 2), (2, 3), (3, 5), and we fit r=βfr = \beta f (no intercept, for simplicity). Here A=(123)A = \begin{pmatrix}1\\2\\3\end{pmatrix}, b=(235)b=\begin{pmatrix}2\\3\\5\end{pmatrix}. Then ATA=12+22+32=14A^TA = 1^2+2^2+3^2=14, and ATb=1(2)+2(3)+3(5)=2+6+15=23A^Tb = 1(2)+2(3)+3(5)=2+6+15=23. So β=A+b=(ATA)1ATb=23/141.643\beta = A^+b = (A^TA)^{-1}A^Tb = 23/14 \approx 1.643. This is exactly the ordinary least-squares slope, the pseudoinverse and OLS are the same computation. Checking fit: predicted values are 1.64,3.29,4.931.64, 3.29, 4.93 against actual 2,3,52, 3, 5, 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 x1+x2=4x_1 + x_2 = 4 (a single constraint, two unknowns), infinitely many solutions exist (x1=4,x2=0x_1=4,x_2=0; x1=0,x2=4x_1=0,x_2=4; and everywhere between). The pseudoinverse picks out the minimum-norm solution: the one closest to the origin among all valid solutions, which here is x1=x2=2x_1=x_2=2 (by symmetry, splitting the constraint evenly minimizes x12+x22x_1^2+x_2^2). 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.

best-fit line
No line passes through all three points exactly, so the pseudoinverse chooses the one minimizing total squared vertical distance, the dashed segments, to every point at once.
x1+x2=4 min-norm solution (2,2)
Every point on the constraint line is a valid solution; the pseudoinverse selects the one closest to the origin, the minimum-norm choice, rather than an arbitrary one.

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 A+=(ATA)1ATA^+ = (A^TA)^{-1}A^T 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 (ATA)1AT(A^TA)^{-1}A^T literally, as written, is numerically dangerous in practice: forming ATAA^TA 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 ATAA^TA, even though the formula above is the right way to understand what it computes.

Discussion

Sign in to join the discussion · reading is open to everyone

💡 Discussion rules

  1. Ask and answer about this concept. Off-topic gets removed.
  2. No homework dumps. Show what you tried first.
  3. Corrections are welcome. Cite a source when you claim an error.

Loading discussion…

Related concepts

Practice in interviews

Further reading

  • Golub & Van Loan, Matrix Computations, ch. 5
  • Strang, Introduction to Linear Algebra, ch. 7
ShareTwitterLinkedIn