Sampling from non i.i.d gaussian data

Here is some really cute 3 lines of matlab code to sample from non i.i.d data. Here it is -
data = rand(n,1); % sample from i.i.d data
[U S V] = svd(C); % C represents the covariance matrix of the data
z = U*sqrt(S)*data;
In order to understand why it works, consider the innermost term of the Gaussian distribution which is .
(x-M)'inv(C)(x -M)
= (x -M)'sqrt(inv(C))(x -M)
= (x -M)'sqrt(inv(U*S*inv(U)))(x -M) %V' = inv(U) as C is symmetric
Solving it further, we get the required answer.

Comments

Popular posts from this blog

MinHash, Bloom Filters and LSH

Perceptron Algorithm

Logistic Regression