The Kronecker trick: why weave is fast
kronecker.RmdA weave model has one cell per site and week: cells in total. The Gaussian-process covariance over those cells is an matrix — at 1000 sites and five years of weeks that is around 67 billion entries. weave never forms it, never inverts it, and never approximates it. Everything in the walkthrough — fitting the hyperparameters and computing the exact part of the prediction interval — stays exact because the covariance is separable, and separable covariances can be handled through their small factors alone. This article explains the two identities that make that work.
One small matrix per dimension
The model assumes the covariance factorises into a spatial part and a temporal part:
where is , is , and is the Kronecker product — a recipe that builds the one enormous matrix from the two small ones: the covariance between cell and cell is simply .
Seeing the structure
A toy problem makes the recipe concrete: 3 sites × 8 weeks, so 24 cells and a 24 × 24 covariance. We build it from the two small pieces.
The spatial kernel holds one correlation per pair of sites. In the toy, sites 1 and 2 sit close together and site 3 sits far away — and the matrix says exactly that:

The temporal kernel holds one correlation per pair of weeks. Its banded shape says that nearby weeks look alike and the resemblance fades with lag:

The Kronecker product assembles the full covariance from those two. Lay out a 3 × 3 grid of blocks — one block per pair of sites — and make each block a copy of the whole 8 × 8 temporal kernel, dimmed by that site pair’s spatial correlation. Sites 1 and 2 are highly correlated (0.78), so their off-diagonal blocks are nearly as strong as the diagonal; site 3 is far from site 1 (0.14), so their block — outlined in deep green below — is the same temporal pattern, just faint:

Read any single entry the same way: the covariance between cell and cell is — always a product of one number from each small matrix. That is all means, and it is why the 24 × 24 matrix (or the 67-billion-entry one) never needs to exist: the two small matrices carry every entry implicitly.
Statistically, separability says the shape of the temporal correlation is the same at every site (and vice versa) — a modelling assumption, and the price of everything below.
Identity 1: determinants and quadratic forms (used in fitting)
Fitting the hyperparameters requires the log marginal likelihood of the plug-in field , which needs and — normally hopeless at size . Because the covariance is a Kronecker product plus a diagonal nugget, eigendecomposing the small factors (size ) and (size ) is enough:
with the eigenvalues, , and the field reshaped to . This works because the Kronecker product’s eigenvectors are themselves a Kronecker product (), and a nugget only shifts the eigenvalues. The cost is instead of — for the 1000-site example above, that is the difference between a second and centuries.
The same eigendecomposition gives the exact complete-grid posterior variance used by the prediction interval — the term in the walkthrough — again without ever forming .
Identity 2: multiplying by K without forming it (used in prediction)
Predicting needs solves of the form (one for the posterior mean, one per perturbation draw). weave uses the conjugate-gradient method, which never needs itself — only the ability to compute for a given vector . For a Kronecker product that is a reshape away:
where
is
reshaped to an
matrix (weave’s vector layout puts time fastest, and the kernels are
symmetric). Each product costs two small matrix multiplications instead
of one enormous one — this is the package’s kron_mv()
building block, and it is what makes each conjugate-gradient iteration
cheap even at large
.
What this buys
A separable kernel means space and time can be handled separately. So instead of one enormous matrix we work with two small ones — one for space, one for time — which is dramatically cheaper and gives the exact same answer. This is why the estimate takes a second rather than hours.
Everything downstream inherits the speed: hyperparameter fitting evaluates the exact likelihood thousands of times inside the optimiser (identity 1), the exact part of the prediction interval is closed-form (identity 1 again), and the gap-correction draws each cost a handful of cheap matrix-vector products (identity 2). None of it is an approximation — the only approximations in weave are the statistical ones listed at the end of the walkthrough.