comparison toolboxes/FullBNT-1.0.7/netlab3.3/gauss.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 y = gauss(mu, covar, x)
2 %GAUSS Evaluate a Gaussian distribution.
3 %
4 % Description
5 %
6 % Y = GAUSS(MU, COVAR, X) evaluates a multi-variate Gaussian density
7 % in D-dimensions at a set of points given by the rows of the matrix X.
8 % The Gaussian density has mean vector MU and covariance matrix COVAR.
9 %
10 % See also
11 % GSAMP, DEMGAUSS
12 %
13
14 % Copyright (c) Ian T Nabney (1996-2001)
15
16 [n, d] = size(x);
17
18 [j, k] = size(covar);
19
20 % Check that the covariance matrix is the correct dimension
21 if ((j ~= d) | (k ~=d))
22 error('Dimension of the covariance matrix and data should match');
23 end
24
25 invcov = inv(covar);
26 mu = reshape(mu, 1, d); % Ensure that mu is a row vector
27
28 x = x - ones(n, 1)*mu;
29 fact = sum(((x*invcov).*x), 2);
30
31 y = exp(-0.5*fact);
32
33 y = y./sqrt((2*pi)^d*det(covar));