In many high-dimensional linear problems, I want to calculate how one variable (or coordinate) responds to constraints on the remaining. Here are some examples.
- High-dimensional linear regression. We have a random function "vector" whose expected covariance is known. We want to find an equation that predicts a single element conditioned on observations at several other training points.
- Disordered linear dynamical systems. We have a large system of sites, arranged into a vector , which undergo random coupled dynamics. We want to find an equation to describe the dynamics of a single site after marginalizing out the effects of the other sites. This is a rich system; Blake gives a nice introduction in his 2026 review paper with Cengiz Pehlevan, and Mark wrote up a detailed walkthrough of it on his blog.
- Gaussian free field. We have a free field with kinetic operator . We place a point source at the endpoint of a semi-infinite 1D lattice. What's ?
These might sound like very different problems, but they're not. They are all linear problems that can be solved by the matrix block inversion formula. Sadly, this formula is pretty opaque imo, and I wanted to better understand where it comes from. There are a few derivations on Wikipedia that didn't shed much light for me. So, on a plane ride back from NYC, I re-derived it using the Sherman-Morrison formula for inverting a rank-one perturbation of a given matrix.
The point of this blog post is to give an intuitive and geometric walkthrough of this derivation. First, I'll show you why these problems boil down to blockwise matrix inversion, which is itself equivalent to a Sherman-Morrison problem. Then, I'll show you how to derive the Sherman-Morrison identity using fairly simple geometric arguments. As a fun exercise, we'll use Sherman-Morrison to derive the bias term for the generalization error of over-parameterized linear regression. Then we'll use it to finally derive the block-inversion formula. At the end, I'll use the block-inversion formula to show you how to solve those three problems above.
Block inversion
The core of all three motivating examples lies in the linear relation
where and are both only partially-known to us (the problem will be to solve for some unknown part of one of them), and the interaction matrix is symmetric and known.
The problems we're interested in concern isolating the behavior of a single site (wlog, index 0), which I've depicted separated from all the rest. This extra structure makes the problem a bit more interesting than standard linear regression — in some sense it precludes spectral approaches, since we have fixed a particular basis (the site basis). Due to its basis dependence, this setting invites analysis of linear interactions between "system" or "site" variables (the scalars and ) and the remaining "bath" variables (the subvectors and ). In this framing, is the site-site interaction, and are site-bath couplings, and is the bath-bath interaction.
Let's be concrete.
High-dimensional linear regression. Here, is more commonly written as , where is the gram matrix:
The vector contains the dual/representer coefficients; we don't know them, although we do know the training labels , and we know (since the test point shouldn't influence ). We want to solve for .
Disordered linear dynamical systems. We have , where is the random interaction matrix and is an external drive:
Thus each block is an operator on functions of time. Since acts on each site independently, it only appears in the diagonal blocks, and the site-bath blocks are just the couplings and . We don't know the bath trajectories , although we do know the drive at every site. We want to solve for in terms of .
Gaussian free field. We have , where is the kinetic operator on a semi-infinite 1D lattice and is an external source:
Concretely, , , and all other entries are zero; is the endpoint of the lattice. The source is localized: and . We don't know the field anywhere; we want to solve for .
Clearly, to solve these problems, we must invert in terms of the blocks of . One way to do it, which is algebraically straightforward but not very intuitive to me, is to just solve blockwise. Here, I'll show another way, using the Sherman-Morrison formula.
For simplicity of notation, I'll write the blocks of like this:
where (for "site") is a scalar, (for "coupling") is a vector, and (for "bath") is a matrix.
If you try to invert this, you'll quickly realize that the site-bath coupling is the annoying part. If we nixed it, , then we'd have
since that's how block-diagonal matrices work. This is intuitive — the site and the bath don't talk, so their inverses are independent. Can we just sneak the coupling back in somehow? A useful starting observation is that the uncoupled interaction matrix is a low-rank perturbation of the full interaction matrix:
where and is the first canonical basis vector. The problem has now transformed: we want to invert a low-rank perturbation of a matrix whose inverse we already know. This is where the Sherman-Morrison formula comes in.
A visual derivation of the Sherman-Morrison formula
Let's start with a simpler problem:
where I defined . Clearly, the inverse of a rank-one perturbation of can be interpreted as a composition: first the unperturbed inverse, then a multiplicative correction from the perturbation. This correction is the inverse of a rank-one perturbation of the identity. (We're assuming that everything is invertible when we need it to be. Sue me.)
Ok, so what's that multiplicative correction? Let's understand what's going on 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 ."
The transformation in 2D. Each hollow dot is a point , and its arrow points to its image (solid dot). Every skews along (blue) with magnitude , so the points on the dashed line don't move, and points further from it skew further. Drag the tips of and to change them.
So then is the "un-skew" operation: from we should subtract . Of course, we need to express this in terms of , not . We can do this by just computing
which immediately gives . Basically, we're measuring the overlap of and the original input by first measuring the overlap between and the transformed , and then correcting for the extra skew, which would've pushed further along , if it isn't orthogonal to . 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 is critical: it ensures that we don't overestimate the effect of the perturbation.
The bias term of generalization in linear regression
This is an aside unrelated to the rest of the blog post, so you can safely skip it, but I thought it was cool. We can use the Sherman-Morrison formula to describe the expected bias of linear regression in the overparameterized (limited data) regime. Here's how.
The data matrix is . It is short and stout: the rows (which index the data samples) are quite outnumbered by the columns (which index the input 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. We'll assume is 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 estimator, without regularization, is well-known: , where is the projector onto the subspace spanned by the data samples. This projector has a null space due to the overparameterization.
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 . However, we want to know what happens on average. Taking expectation over , we get
The variance term is highkey kinda annoying to calculate. We can get a pretty good idea of how generalization works by simply studying the bias term, so let's just do that. The object we need to understand is , since
using the formula for the projector onto . Let the -th column of be denoted ; this vector contains the -th PCA component of every in the dataset. Then the element of is
The first thing to notice is that if we reflect the -th coordinate of every , , then for every we've just flipped the sign of . However, since is drawn Gaussian, and we're in the PCA basis, this reflection doesn't change the underlying distribution. So, by symmetry, the expectation of every off-diagonal element must be zero.
So, is diagonal. Let's solve for the diagonal elements:
In the second step I used Sherman-Morrison and simplified. In the third step I just renamed and simplified more. With enough samples, we expect the quantity to concentrate, since contains random Gaussian variables of size , and is independent of them. Let's separate the -dependent part () from the rest, which concentrates to a quantity we'll call :
All together, we get , and it satisfies the equation since is a projector onto the -dimensional subspace spanned by the samples. Notice that this solution is exactly what ridge regression with ridge would give if it had access to the population covariance . For this reason, the constant is called the effective regularization: even though we didn't explicitly regularize, the finite dataset acts like a ridge. Directions with are learned, and directions with are not. Plugging this into the (weight-space) bias term,
Deriving the block inverse formula
Recall that the problem we're actually interested in is
where contains the couplings, and is the first canonical basis vector. Now we'll do the same thing as before. First we factor out the uncoupled part:
where contains the coupling as seen through the uncoupled inverse, and . I'll leave it as an exercise to go through the same steps as before; as a hint, it's useful to observe that and . It's also useful to define . If you do the calculation, you find that
That's it — the block inverse formula! We took many more steps than direct computation with Gaussian elimination, but in exchange we learn what each term means:
- Our quantity is exactly analogous to the from the Sherman-Morrison derivation. It represents the coupling that remains after we factor out the uncoupled inverse. That's why it shows up in the off-diagonals of .
- Since skews the bath variables according to the first site's activity, and skews the site variable according to the bath's activity, the quantity is a gain, or echo: it measures the strength of the round-trip effect of the site on itself through the bath.
- Therefore is the cumulative effect of all the echoes, cycling through the site and the bath and back to the site again, multiple times.
- It's worth noting that is the Schur complement. I think this whole exercise gives some intuition for the meaning of this quantity.
Solving those problems
Now I'll show you how to solve the problems at the beginning of the blogpost.
Linear regression
We have , where is the gram matrix:
The vector contains the dual/representer coefficients; we don't know them, although we do know the training labels , and we know (since the test point shouldn't influence ). We want to solve for .
Easy peasy. Let's invert, , and just read off the top row. We get
This gives the kernel regression formula:
It's super easy to add a ridge regularizer and get the general KRR formula.
Disordered linear dynamical systems
We have , where is a vector function of time whose elements are the site activities, is the per-site external drive, and is the time-independent interaction matrix. We don't know the bath trajectories , although we do know the drive at every site. We want to solve for the site activity in terms of .
Of course, we do the same thing as before: invert and read off the equation block-by-block. The trouble here is that contains , which is a bit hard to handle. Things will get a lot easier if we Fourier transform, since this takes to , i.e., just a scalar times the identity matrix:
Here I'm using tildes to denote Fourier-space variables, i.e., functions of . Now this we can easily invert blockwise, using , , and , and reading off the top row:
where I've introduced . A few comments on . Since , you can think of it as a rescaled gain/echo factor. Also, since is independent of , in the large-bath limit the quadratic form concentrates and becomes the "deterministic equivalent" . Finally, a note on nomenclature: in this particular problem, is often called the memory kernel (it'll become clear why later).
Our equation for is, in some sense, complete: it does not directly depend on the other site trajectories. But, the annoying thing about our equation is that it still depends on all the other bath variables. We'd like to simplify this somehow, to "average out" the effect of the bath. To do this, I'll refer you back to point 1 in the earlier numbered list, which says that is the coupling to the counterfactual uncoupled bath activities (since, if , then ). So then we get
where is called the cavity field: it contains the counterfactual bath activities if we removed entirely. If contains random interaction couplings, then its dot product with the cavity field converges to a Gaussian process in the large-bath limit by central limit theorem. The covariance of the GP is just the covariance of . More on this later.
We've now killed all the bath variables. After rearranging, here's what's left:
Now we finally Fourier transform back, using the convolution theorem for the product :
This is quite amazing: we have an ODE for a single site's dynamics that explicitly depends only on the site's own history (through the memory kernel ) and its own external drive . The dependence on the bath is implicit; it lives in the covariance of the Gaussian process noise term, and in the functional form of . To actually solve this ODE, we need to pin both of these down. This is where we finally use the cavity approximation: we assert that all elements of are essentially the same in character (i.e., they share the same noise covariance and the same memory kernel), and we can use a self-consistency argument to solve for both. This is beyond the scope of this blog post, so I'll refer you to Mark's blogpost and Blake's paper for more info.
(Left.) A system of interacting sites. Each site's color is its activity , and the size of its halo is its external drive . The cavity site is circled, and one of its neighbors has a dashed circle. (Top Right.) The cavity site's true trajectory (solid) is well predicted by the single-site equation we derived (dashed). The faint envelope shows the memory kernel . (Bottom right.) The neighbor site's true trajectory (solid) stays close to the counterfactual sans-cavity-site field (dashed).
To recap, the main cavity idea here is exact: it follows from the block-inverse formula, which is straight up correct. Then, to simplify even more, we make the following extra approximations:
- concentration of the memory kernel to a deterministic limit (as bath gets large)
- cavity approximation: when we remove the site, nothing much changes in the bath (at least, as far as its correlations are concerned). This gives self-consistency: noise covariance and memory kernel are shared across all sites.
Gaussian free field
We have , where is the discretized on a semi-infinite 1D lattice with endpoint : , , and zero otherwise. The source is and zero otherwise. We want . I'll leave this one as an exercise :—) Hint: solving for will involve a self-consistency argument (note that the bath itself is self-similar to the site+bath system). Another hint: make sure the system is well-behaved in the large-mass limit.
In the end, you should get
As an extra challenge, try to find the field everywhere.
As another extra challenge, try the full infinite chain, with somewhere in the middle. You should get .