Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/fn_mtpdf.m

raw
1 function y = fn_mtpdf(x,xm,C,v,covIx,constIx)
2 % y = mtpdf(x,xm,C,v,covIx,constIx)
3 % The pdf value for multivariate Student t distribution allowing many values (draws) stored in columns.
4 %
5 % x: p-by-draws matrix of values evaluated at where p=size(x,1) is # of variables
6 % xm: p-by-draws matrix of the mean of x
7 % C: p-by-p Choleski square root of PDS S, which is the covariance matrix in the normal case
8 % so that S = C*C'. That is, C=chol(S)' (notice the transpose ' here).
9 % v (>0): A scalar value for the degrees of freedom.
10 % covIx: An index for a decomposition of the covariance matrix. If 1, C=chol(S)' (notice the transpose ');
11 % if 0, C=chol(inv(S)) (note that there is no transpose here).
12 % constIx: An index for the constant. 1: constant (normalized); 0: no constant (unnormalized)
13 %----------
14 % y: p-by-draws matrix of pdf's for multivariate Student t distribution with v degrees of freedom
15 %
16 % Christian P. Robert, "The Bayesian Choice," Springer-Verlag, New York, 1994,
17 % p. 382.
18 %
19 % Tao Zha, December 1998; Revised, January 2002.
20 %
21 % Copyright (C) 1997-2012 Tao Zha
22 %
23 % This free software: you can redistribute it and/or modify
24 % it under the terms of the GNU General Public License as published by
25 % the Free Software Foundation, either version 3 of the License, or
26 % (at your option) any later version.
27 %
28 % It is distributed in the hope that it will be useful,
29 % but WITHOUT ANY WARRANTY; without even the implied warranty of
30 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 % GNU General Public License for more details.
32 %
33 % If you did not received a copy of the GNU General Public License
34 % with this software, see <http://www.gnu.org/licenses/>.
35 %
36
37 [p,nx]=size(x);
38 if covIx
39 z = C\(x-xm);
40 else
41 z = C*(x-xm);
42 end
43
44
45 if constIx
46 dSh=sum(log(diag(C))); % (detSigma)^(1/2)
47 %* Use gammaln function to avoid overflows.
48 term = exp(gammaln((v + p) / 2) - gammaln(v/2) - dSh);
49 y = (term*(v*pi)^(-p/2)) * (1 + sum(z.*z,1)/v).^(-(v + p)/2);
50 y = y';
51 else
52 y = (1 + sum(z.*z,1)/v).^(-(v + p)/2);
53 y = y';
54 end