Debian Codegraph @

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

raw
1 function [cT,vR,kdf] = gibbsglb(Sbd,idmat0,nvar,fss)
2 % [cT,vR,kdf] = gibbsglb(Sbd,idmat0,nvar,fss)
3 % Global setup outside the Gibbs loop -- c.f. gibbsvar
4 % Ref.: D.F. Waggoner and T.A. Zha: "Does Normalization Matter for Inference?"
5 % See Note Forecast (2) pp. 44-51
6 %
7 % Sbd: cell(nvar,1). Sbd=diag(S(1), ..., S(m)). Already divided by 'fss' for the
8 % posterior of a0 or A0(:) in Waggoner and Zha when one has asymmetric prior.
9 % Note,"bd" stands for block diagonal.
10 % idmat0: identification matrix for A0 with asymmetric prior; column -- equation.
11 % nvar: rank of A0 or # of variables
12 % fss: effective sample size (in the exponential term) --
13 % # of observations + # of dummy observations
14 % (or nSample - lags + # of dummy observations)
15 %-------------
16 % cT{i}: nvar-by-nvar where T'*T=Sbd{i} which is kind of covariance martrix
17 % divided by fss already
18 % vR{i}: nvar-by-q{i} -- orthonormral basis for T*R, which is obtained through
19 % single value decomposition of Q*inv(T)
20 % kdf: the polynomial power in the Gamma or 1d Wishart distribution, used in
21 % "gibbsvar.m"
22 %
23 % Written by Tao Zha;
24 %
25 %
26 % Copyright (C) 1997-2012 Daniel Waggoner and Tao Zha
27 %
28 % This free software: you can redistribute it and/or modify
29 % it under the terms of the GNU General Public License as published by
30 % the Free Software Foundation, either version 3 of the License, or
31 % (at your option) any later version.
32 %
33 % It is distributed in the hope that it will be useful,
34 % but WITHOUT ANY WARRANTY; without even the implied warranty of
35 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 % GNU General Public License for more details.
37 %
38 % If you did not received a copy of the GNU General Public License
39 % with this software, see <http://www.gnu.org/licenses/>.
40 %
41
42
43 kdf = fss; %2; %fss;
44
45 cT = cell(nvar,1);
46 for k=1:nvar
47 cT{k} = chol(Sbd{k}); % upper triangular but lower triangular Choleski
48 end
49
50 Q = cell(nvar,1);
51 % Q{i}: nvar-by-nvar with rank nvar-q(i) with ith equation a and
52 % q(i) which is # of non-zero elements in a. Note: Q*a=0.
53
54 vR = cell(nvar,1);
55 for k=1:nvar
56 Q{k} = diag(idmat0(:,k)==0); % constructing Q{k}
57 %
58 [jnk1,d1,v1] = svd(Q{k}/cT{k});
59 d1max=max(diag(d1));
60 if d1max==0
61 Idxk=1:nvar;
62 else
63 Idxk = find(diag(d1)<eps*d1max);
64 end
65 lenk = length(find(idmat0(:,k)));
66 if ( length(Idxk)<lenk )
67 warning('Dimension of non-zero A0(:,k) is different from svd(Q*inv(T))')
68 disp('Press ctrl-c to abort')
69 pause
70 else
71 jnk1 = v1(:,Idxk);
72 vR{k} = jnk1(:,1:lenk); % orthonormal basis for T*R
73 end
74 end