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