Hi i’m not sure if my algorithm is correct i’m trying to replicate the mvnrnd function of matlab but in gsl. I found an algorithm in some journal articles that produces a vector of multivariate normal, but i need a matrix of multivariate normal random numbers
lets say the distribution is Z~(mu,sigma);
assuming sigma is a matrix already positive definite.
an algorithm i found off the web says to
1. cholskey(sigma) = A
2. generate uniform gaussian vector r
3. matrix vector triangular product with gsl_blas_dtrmv A * r
4. add mu to Ar and that will be a vector of multivariate normal random numbers
my method below
are the following changes belowcorrect to product a Matrix of random variables
1. cholskey(sigma) = A
2. generate uniform gaussian matrix R
3. matrix matrix scalar product AR
4. add mu to AR and that will be a matrix of multivariate normal random numbers
Yes, that is correct. See e.g. this Wikipedia entry on multivariate normal RNGs which has this section:
which describes the same algorithm.
There are also several implementations for R, for example
mvrnormin the MASS package which comes with every R installation.