blob: 509b12905d665083e46e16ebd71fe826f46b5eb5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
function p=gaussian(x,m,C);
% p=gaussian(x,m,C);
%
% Evaluate the multi-variate density with mean vector m and covariance
% matrix C for the input vector x.
%
% p=gaussian(X,m,C);
%
% Vectorized version: Here X is a matrix of column vectors, and p is
% a vector of probabilities for each vector.
d=length(m);
if size(x,1)~=d
x=x';
end
N=size(x,2);
detC = det(C);
if rcond(C)<eps
% fprintf(1,'Covariance matrix close to singular. (gaussian.m)\n');
p = zeros(N,1);
else
m=m(:);
M=m*ones(1,N);
denom=(2*pi)^(d/2)*sqrt(abs(detC));
mahal=sum(((x-M)'*inv(C)).*(x-M)',2); % Chris Bregler's trick
numer=exp(-0.5*mahal);
p=numer/denom;
end
|