wolffd@0: function y = gauss(mu, covar, x) wolffd@0: %GAUSS Evaluate a Gaussian distribution. wolffd@0: % wolffd@0: % Description wolffd@0: % wolffd@0: % Y = GAUSS(MU, COVAR, X) evaluates a multi-variate Gaussian density wolffd@0: % in D-dimensions at a set of points given by the rows of the matrix X. wolffd@0: % The Gaussian density has mean vector MU and covariance matrix COVAR. wolffd@0: % wolffd@0: % See also wolffd@0: % GSAMP, DEMGAUSS wolffd@0: % wolffd@0: wolffd@0: % Copyright (c) Ian T Nabney (1996-2001) wolffd@0: wolffd@0: [n, d] = size(x); wolffd@0: wolffd@0: [j, k] = size(covar); wolffd@0: wolffd@0: % Check that the covariance matrix is the correct dimension wolffd@0: if ((j ~= d) | (k ~=d)) wolffd@0: error('Dimension of the covariance matrix and data should match'); wolffd@0: end wolffd@0: wolffd@0: invcov = inv(covar); wolffd@0: mu = reshape(mu, 1, d); % Ensure that mu is a row vector wolffd@0: wolffd@0: x = x - ones(n, 1)*mu; wolffd@0: fact = sum(((x*invcov).*x), 2); wolffd@0: wolffd@0: y = exp(-0.5*fact); wolffd@0: wolffd@0: y = y./sqrt((2*pi)^d*det(covar));