-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmndpdf.m
37 lines (30 loc) · 781 Bytes
/
mndpdf.m
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
32
33
34
35
36
37
function p = mndpdf(x, X)
% mndpdf
%
% Probability density function of a multivariate normal distribution.
% Returns the likelihood corresponding to each vector of |x|.
%
% Inputs:
%
% x Matrix whose columns are the vector locations of each point at which
% to evalaute the PDF (nx-by-n)
% X Covariance matrix of the distribution (strictly positive-definite)
% (nx-by-nx)
%
% Outputs:
%
% p Probability density at each point (1-by-n)
%
% Copyright 2016 An Uncommon Lab
%#codegen
% Dimensions
[nd, n] = size(x);
% Scale factor
invR = inv(X);
s = 1/sqrt((2*pi)^nd * det(X));
% PDF at each point.
p = zeros(1, n);
for k = 1:n
p(k) = s * exp(-0.5 * x(:,k).' * invR * x(:,k)); %#ok<MINV>
end
end % mndpdf