Mercurial > hg > camir-ismir2012
annotate toolboxes/FullBNT-1.0.7/netlab3.3/gauss.m @ 0:cc4b1211e677 tip
initial commit to HG from
Changeset:
646 (e263d8a21543) added further path and more save "camirversion.m"
author | Daniel Wolff |
---|---|
date | Fri, 19 Aug 2016 13:07:06 +0200 |
parents | |
children |
rev | line source |
---|---|
Daniel@0 | 1 function y = gauss(mu, covar, x) |
Daniel@0 | 2 %GAUSS Evaluate a Gaussian distribution. |
Daniel@0 | 3 % |
Daniel@0 | 4 % Description |
Daniel@0 | 5 % |
Daniel@0 | 6 % Y = GAUSS(MU, COVAR, X) evaluates a multi-variate Gaussian density |
Daniel@0 | 7 % in D-dimensions at a set of points given by the rows of the matrix X. |
Daniel@0 | 8 % The Gaussian density has mean vector MU and covariance matrix COVAR. |
Daniel@0 | 9 % |
Daniel@0 | 10 % See also |
Daniel@0 | 11 % GSAMP, DEMGAUSS |
Daniel@0 | 12 % |
Daniel@0 | 13 |
Daniel@0 | 14 % Copyright (c) Ian T Nabney (1996-2001) |
Daniel@0 | 15 |
Daniel@0 | 16 [n, d] = size(x); |
Daniel@0 | 17 |
Daniel@0 | 18 [j, k] = size(covar); |
Daniel@0 | 19 |
Daniel@0 | 20 % Check that the covariance matrix is the correct dimension |
Daniel@0 | 21 if ((j ~= d) | (k ~=d)) |
Daniel@0 | 22 error('Dimension of the covariance matrix and data should match'); |
Daniel@0 | 23 end |
Daniel@0 | 24 |
Daniel@0 | 25 invcov = inv(covar); |
Daniel@0 | 26 mu = reshape(mu, 1, d); % Ensure that mu is a row vector |
Daniel@0 | 27 |
Daniel@0 | 28 x = x - ones(n, 1)*mu; |
Daniel@0 | 29 fact = sum(((x*invcov).*x), 2); |
Daniel@0 | 30 |
Daniel@0 | 31 y = exp(-0.5*fact); |
Daniel@0 | 32 |
Daniel@0 | 33 y = y./sqrt((2*pi)^d*det(covar)); |