Mercurial > hg > camir-aes2014
annotate toolboxes/FullBNT-1.0.7/netlab3.3/gsamp.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
rev | line source |
---|---|
wolffd@0 | 1 function x = gsamp(mu, covar, nsamp) |
wolffd@0 | 2 %GSAMP Sample from a Gaussian distribution. |
wolffd@0 | 3 % |
wolffd@0 | 4 % Description |
wolffd@0 | 5 % |
wolffd@0 | 6 % X = GSAMP(MU, COVAR, NSAMP) generates a sample of size NSAMP from a |
wolffd@0 | 7 % D-dimensional Gaussian distribution. The Gaussian density has mean |
wolffd@0 | 8 % vector MU and covariance matrix COVAR, and the matrix X has NSAMP |
wolffd@0 | 9 % rows in which each row represents a D-dimensional sample vector. |
wolffd@0 | 10 % |
wolffd@0 | 11 % See also |
wolffd@0 | 12 % GAUSS, DEMGAUSS |
wolffd@0 | 13 % |
wolffd@0 | 14 |
wolffd@0 | 15 % Copyright (c) Ian T Nabney (1996-2001) |
wolffd@0 | 16 |
wolffd@0 | 17 d = size(covar, 1); |
wolffd@0 | 18 |
wolffd@0 | 19 mu = reshape(mu, 1, d); % Ensure that mu is a row vector |
wolffd@0 | 20 |
wolffd@0 | 21 [evec, eval] = eig(covar); |
wolffd@0 | 22 |
wolffd@0 | 23 deig=diag(eval); |
wolffd@0 | 24 |
wolffd@0 | 25 if (~isreal(deig)) | any(deig<0), |
wolffd@0 | 26 warning('Covariance Matrix is not OK, redefined to be positive definite'); |
wolffd@0 | 27 eval=abs(eval); |
wolffd@0 | 28 end |
wolffd@0 | 29 |
wolffd@0 | 30 coeffs = randn(nsamp, d)*sqrt(eval); |
wolffd@0 | 31 |
wolffd@0 | 32 x = ones(nsamp, 1)*mu + coeffs*evec'; |