


GAUSSIANVECTORS Returns vectors whose components are Gaussian RV's. DATA = GAUSSIANVECTORS(NUMVECTORS, MEANVECTOR, DATACOVARIANCE) returns an (M x N) matrix DATA, where M is NUMVECTORS and N is the number of columns in MEANVECTOR. The columns of DATA are each drawn from a Gaussian distribution with mean given by the corresponding column in MEANVECTOR. The covariance of the various columns is specified by the DATACOVARIANCE input, which must be a symmetric positive definite matrix with dimension matching the number of columns in MEANVECTOR.


0001 function data = gaussianvectors(numvectors, meanvector, datacov) 0002 %GAUSSIANVECTORS Returns vectors whose components are Gaussian RV's. 0003 % DATA = GAUSSIANVECTORS(NUMVECTORS, MEANVECTOR, DATACOVARIANCE) returns 0004 % an (M x N) matrix DATA, where M is NUMVECTORS and N is the number of 0005 % columns in MEANVECTOR. The columns of DATA are each drawn from a 0006 % Gaussian distribution with mean given by the corresponding column in 0007 % MEANVECTOR. 0008 % 0009 % The covariance of the various columns is specified by the 0010 % DATACOVARIANCE input, which must be a symmetric positive definite 0011 % matrix with dimension matching the number of columns in MEANVECTOR. 0012 0013 numdims = size(meanvector, 2); 0014 0015 % error checking 0016 if ((size(datacov, 1) ~= size(datacov, 2)) || (size(datacov, 1) ~= numdims)) 0017 error('Covariance matrix dimensions inconsistent with mean vector.'); 0018 end 0019 if (all(all((datacov ~= datacov'))) || (det(datacov) <= 0)) 0020 error('Covariance matrix must be symmetric positive definite.'); 0021 end 0022 0023 % We start with random vectors W, where W_k = N(0,1) and W_i and W_j 0024 % are indpendent random variables for all i ~= j. These vectors can 0025 % be made to have the desired covariance by premultiplying them with 0026 % the Cholesky factorization of the (symm pos def) covariance matrix. 0027 % The desired mean is then added in to give Gaussian vectors with the 0028 % desired statistics. 0029 data = randn(numvectors, numdims) * chol(datacov) + repmat(meanvector, [numvectors, 1]);