annotate toolboxes/FullBNT-1.0.7/netlab3.3/gsamp.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function x = gsamp(mu, covar, nsamp)
Daniel@0 2 %GSAMP Sample from a Gaussian distribution.
Daniel@0 3 %
Daniel@0 4 % Description
Daniel@0 5 %
Daniel@0 6 % X = GSAMP(MU, COVAR, NSAMP) generates a sample of size NSAMP from a
Daniel@0 7 % D-dimensional Gaussian distribution. The Gaussian density has mean
Daniel@0 8 % vector MU and covariance matrix COVAR, and the matrix X has NSAMP
Daniel@0 9 % rows in which each row represents a D-dimensional sample vector.
Daniel@0 10 %
Daniel@0 11 % See also
Daniel@0 12 % GAUSS, DEMGAUSS
Daniel@0 13 %
Daniel@0 14
Daniel@0 15 % Copyright (c) Ian T Nabney (1996-2001)
Daniel@0 16
Daniel@0 17 d = size(covar, 1);
Daniel@0 18
Daniel@0 19 mu = reshape(mu, 1, d); % Ensure that mu is a row vector
Daniel@0 20
Daniel@0 21 [evec, eval] = eig(covar);
Daniel@0 22
Daniel@0 23 deig=diag(eval);
Daniel@0 24
Daniel@0 25 if (~isreal(deig)) | any(deig<0),
Daniel@0 26 warning('Covariance Matrix is not OK, redefined to be positive definite');
Daniel@0 27 eval=abs(eval);
Daniel@0 28 end
Daniel@0 29
Daniel@0 30 coeffs = randn(nsamp, d)*sqrt(eval);
Daniel@0 31
Daniel@0 32 x = ones(nsamp, 1)*mu + coeffs*evec';