Overview
Cholesky Decomposition
Starting with a vector of uncorrelated, N(0,1) variables, we have
{% \mathbb{E}(ZZ^T) = I %}
Given a covariance matrix {% \Sigma %}, the
Cholesky Decomposition
yields a matrix L such that
{% LL^T = \Sigma %}
Then compute a new vector
{% X = LZ %}
{% \mathbb{E} (XX^T) = \mathbb{E}(LZZ^TL^T) = L\mathbb{E}(ZZ^T)L^T = LIL^T = \Sigma %}
Implementation
let bm = await import('/lib/statistics/simulations/v1.0.0/box-muller.mjs');
let la = await import('/lib/linear-algebra/v1.0.0/linear-algebra.mjs');
let covar = [[1,0.5],[0.5,1]]
let L = la.cholesky(covar);
let sample = [[bm.boxMuller()],[bm.boxMuller()]];
let correlated = la.multiply(L, sample);
Try it!