annotate toolboxes/FullBNT-1.0.7/KPMstats/gaussian_sample.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 coeffs = randn(nsamp, d)*sqrt(eval);
wolffd@0 24
wolffd@0 25 x = ones(nsamp, 1)*mu + coeffs*evec';