Debian Codegraph @

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

raw
1 function [cT,vR,kdf] = fn_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 %
24 % Copyright (C) 1997-2012 Daniel Waggoner and Tao Zha
25 %
26 % This free software: you can redistribute it and/or modify
27 % it under the terms of the GNU General Public License as published by
28 % the Free Software Foundation, either version 3 of the License, or
29 % (at your option) any later version.
30 %
31 % It is distributed in the hope that it will be useful,
32 % but WITHOUT ANY WARRANTY; without even the implied warranty of
33 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 % GNU General Public License for more details.
35 %
36 % If you did not received a copy of the GNU General Public License
37 % with this software, see <http://www.gnu.org/licenses/>.
38 %
39
40
41 kdf = fss; %2; %fss;
42
43 cT = cell(nvar,1);
44 for k=1:nvar
45 cT{k} = chol(Sbd{k}); % upper triangular but lower triangular Choleski
46 end
47
48 Q = cell(nvar,1);
49 % Q{i}: nvar-by-nvar with rank nvar-q(i) with ith equation a and
50 % q(i) which is # of non-zero elements in a. Note: Q*a=0.
51
52 vR = cell(nvar,1);
53 for k=1:nvar
54 Q{k} = diag(idmat0(:,k)==0); % constructing Q{k}
55 %
56 [jnk1,d1,v1] = svd(Q{k}/cT{k});
57 d1max=max(diag(d1));
58 if d1max==0
59 Idxk=1:nvar;
60 else
61 Idxk = find(diag(d1)<eps*d1max);
62 end
63 lenk = length(find(idmat0(:,k)));
64 if ( length(Idxk)<lenk )
65 warning('Dimension of non-zero A0(:,k) is different from svd(Q*inv(T))')
66 disp('Press ctrl-c to abort')
67 pause
68 else
69 jnk1 = v1(:,Idxk);
70 vR{k} = jnk1(:,1:lenk); % orthonormal basis for T*R
71 end
72 end