-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmvtpdfln_fast.m
42 lines (37 loc) · 1.56 KB
/
mvtpdfln_fast.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
38
39
40
41
42
function y = mvtpdf(X, C, df)
%MVTPDF Multivariate t probability density function (pdf).
% Y = MVTPDF(X,C,DF) returns the probability density of the multivariate t
% distribution with correlation parameters C and degrees of freedom DF,
% evaluated at each row of X. Rows of the N-by-D matrix X correspond to
% observations or points, and columns correspond to variables or
% coordinates. Y is an N-by-1 vector.
%
% C is a symmetric, positive definite, D-by-D correlation matrix. DF is a
% scalar, or a vector with N elements.
%
% Note: MVTPDF computes the PDF for the standard multivariate Student's t,
% centered at the origin, with no scale parameters. If C is a covariance
% matrix, i.e. DIAG(C) is not all ones, MVTPDF rescales C to transform it
% to a correlation matrix. MVTPDF does not rescale X.
%
% Example:
%
% C = [1 .4; .4 1]; df = 2;
% [X1,X2] = meshgrid(linspace(-2,2,25)', linspace(-2,2,25)');
% X = [X1(:) X2(:)];
% p = mvtpdf(X, C, df);
% surf(X1,X2,reshape(p,25,25));
%
% See also MVNPDF, MVTCDF, MVTRND, TPDF.
% Copyright 2005-2011 The MathWorks, Inc.
% Get size of data. Column vectors provisionally interpreted as multiple scalar data.
[n,d] = size(X);
% Make sure C is a valid covariance matrix
%[R,err] = cholcov(C,0);
df = df(:);
% Create array of standardized data, and compute log(sqrt(det(Sigma)))
Z = X;
logSqrtDetC = sum(log(size(diag(C),1)));
logNumer = -((df+d)/2) .* log(1+sum(Z.^2, 2)./df);
logDenom = logSqrtDetC + (d/2)*log(df*pi);
y = gammaln((df+d)/2) - gammaln(df/2) + logNumer - logDenom;