Here's a somewhat surprising fact about matrix inversion:
The inverse of a rank-one perturbation of
equals a rank-one perturbation of
…assuming all the inverses exist, yada yada. This fact is captured by the Sherman-Morrison formula:
I thought this formula was super opaque and unintuitive. So, on a plane ride back from NYC, I re-derived it using a visual argument. It turns out this argument is on Wikipedia so sadly my derivation isn't that cool. But I wanna show it to you anyways! Plus, I have a widget, so that's extra points for me.
A visual derivation of the Sherman-Morrison formula
We want to invert . Let's factor it out: first, we invert , then we composite it with a correction that comes from the perturbation:
where I defined . The multiplicative correction from the perturbation is the inverse of a perturbation of the identity. This is something we can understand geometrically. The transformation basically says: "Return the original vector , but skewed along direction , and the amount of skew is equal to the overlap of and ." Here's an illustration:
A rank-one perturbation of the identity. Each arrow starts at a point and ends at its image . Every skews along (blue) by . The dashed line is the locus of , so points there don't move, and rows further from it skew further. Drag the tips of and to change them.
Clearly, is the "un-skew" operation: from we should subtract . Of course, we don't know , so we don't immediately know the skew strength . But here's a trick:
This equation tells me that, after skewing along , we might've also moved along the direction , depending on how much and are aligned. This means the overlap between and the image misestimates the original skew strength by that alignment factor. We just need to correct for that misestimation by dividing the factor out. Rewriting this same argument mathematically, we get
That's it! We solved for the inverse using a simple geometric argument. Putting it all together:
We derived the Sherman-Morrison formula. My interpretation is that the perturbed inverse is basically just the original inverse, followed by a rank-one correction along the skew direction. The normalizing term in the denominator ensures that we don't misestimate the effect of the perturbation.
The bias term of generalization in linear regression
We can use the Sherman-Morrison formula to derive the expected bias of linear regression in the heavily overparameterized (limited data) regime. Here's how.
The data matrix is short and stout: , with . Its rows, which index the data samples, are quite outnumbered by its columns, which index the data dimension . We should think of as a random variable: we've drawn some particular samples from a Gaussian distribution with expected covariance . Let's work in the PCA basis of the input distribution, so is diagonal and full-rank.This is quite different from the sample covariance , which is singular due to the overparameterization.
The labels are scalar, noiseless, linear: . You can add noise later if you want, but here I'll keep things simple. The unregularized min-norm estimator is well-known: , where is the projector onto the (strict) subspace spanned by the data samples, and is therefore also a random variable. This spanning subspace has dimension (assuming the data samples are linearly independent, which they should be, unless you got super unlucky somehow). Therefore . This'll be an important fact later.
For a given , the weight-space errorThe typical function-space MSE is almost the same thing, just reweighted by . I'm leaving it out for notational clarity, it's easy to add back in. is . But we want to know what happens on average. Taking expectation over , we get
The variance term is highkey kinda annoying to calculate, since it requires second-order statistics of . We can get a pretty good idea of how generalization works by simply studying the bias term, so let's just do that. We have to evaluate
where I used the formula for the projector onto . A reasonable hunch is that is diagonal, since we're in the PCA basis, so by symmetry the average projector should be aligned with it. To check this, let's study this matrix elementwise. The matrix elements can be extracted by picking out columns of ; e.g., if we denote the -th column of as , then the element of is
Note that the vector contains the -th PCA feature of every in the dataset. If we reflect the -th coordinate of every , , then the sign of flips (assuming ; if then the sign flips twice, no change). However, since is drawn Gaussian, and we're in the PCA basis, this reflection doesn't change the underlying distribution. So, for off-diagonal elements , the distribution of (whatever it may be) has to be symmetric around zero, and so .
Nice, so is diagonal, as we guessed. Let's solve for the diagonal elements . First, it'll be useful to make note of the following facts:
- The quantity we're trying to understand is , where is the sample gram matrix. Clearly, contains a bunch of rank-one components, one for each feature.
- The data is Gaussian with variance along feature , so , where is a standard Gaussian random vector.
- This means that . This is a random quadratic form; if were fully independent of , then in expectation is the trace of . Sadly, is definitely not independent of , because one of its rank-one components is . So, if we wanna use the concentration of random quadratic forms, we have to separate that correlated component.
Here goes:
In the first line, I separated the one correlated component from all the independent ones. In the second line, I interpreted as a sort of "ZCA-like" whitening, and wrote the equation in terms of the whitened vector . (This step isn't really necessary, I just thought it made the calculation look nicer.) The third line is Sherman-Morrison, and the fourth is just simplification.
Now let's take the expectation. The only random variable is . Our first approximation is that this random variable concentrates, so the expectation of depends only on , and not its fluctuations. Now we gotta solve ; this will involve two steps. First is the trace identity for random quadratic forms: . The second part is a leave-one-out approximation: since , removing any one feature leaves essentially unchanged, so for all intents and purposes for any and . In particular, the trace of its inverse is basically independent of , and we can just name it . Plugging it in, we get
All together, we get . Using the projector fact from earlier, we know it satisfies the equation , so this constrains the value of .
Notice that this solution is exactly what ridge regression would give if it had access to the population covariance and was regularized with ridge . For this reason, the constant is called the effective regularization: even though we didn't explicitly regularize, the finite dataset acts like a ridge regularizer. Directions with are learned, and directions with are not.
This is a deep idea: in least-squares linear regression, there is really only one kind of regularization; weight decay, finite dataset, and even early stopping all act in essentially the same way, and the behavior of the final estimator depends mainly on whichever of those constraints is the strongest.
Anyways, plugging this into the (weight-space) bias term,