Revision 168
(checked in by cbc, 16 years ago)
|
Adding diwasp customizations.
|
Line | |
---|
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) Christopher M Bishop, Ian T Nabney (1996, 1997) |
---|
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'; |
---|