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