comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function x = gsamp(mu, covar, nsamp)
2 %GSAMP Sample from a Gaussian distribution.
3 %
4 % Description
5 %
6 % X = GSAMP(MU, COVAR, NSAMP) generates a sample of size NSAMP from a
7 % D-dimensional Gaussian distribution. The Gaussian density has mean
8 % vector MU and covariance matrix COVAR, and the matrix X has NSAMP
9 % rows in which each row represents a D-dimensional sample vector.
10 %
11 % See also
12 % GAUSS, DEMGAUSS
13 %
14
15 % Copyright (c) Ian T Nabney (1996-2001)
16
17 d = size(covar, 1);
18
19 mu = reshape(mu, 1, d); % Ensure that mu is a row vector
20
21 [evec, eval] = eig(covar);
22
23 coeffs = randn(nsamp, d)*sqrt(eval);
24
25 x = ones(nsamp, 1)*mu + coeffs*evec';