Debian Codegraph @

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

raw
1 function [GS,pickn,ok,uis,uiu,vs]=gstate(G1,impact,pick)
2 %function [GS,pickn,ok,uis,vs]=gstate(G1,impact,pick)
3 % G1: the coefficient on lagged y from the output of gensys.m.
4 % impact:the coefficient on exogenous shocks from the output of gensys.m
5 % pick: an optional guess at a matrix of coefficients that extracts
6 % the state vector from y
7 % ok: 0 if pick matrix is just no good.
8 % 1 if pick matrix is usable forward, but loses initial date information
9 % 2 if pick matrix is not usable forward, is part of a correct state vector, but is not complete
10 % 3 if pick matrix is usable forward, is part of a correct state vector, but is not complete
11 % 4 if pick matrix is not usable forward, summarizes past, but is redundant
12 % 5 if pick matrix is usable forward, summarizes past, but is redundant
13 % 6 if pick matrix summarizes past and is not redundant, but is not usable forward
14 % 7 if pick matrix is perfect, both forward and as history summary
15 % pickn: a matrix of coefficients that extracts the state vector from y. Equal
16 % to pick if pick is supplied and ok=1; otherwise, an ok-maximizing pick matrix that
17 % is somewhat similar to pick.
18 % GS: the matrix of coefficients on the lagged state variable
19 % uis,vs: If uis'*vs is square and full rank, ok=7 is possible, otherwise not. If ok<2, an ok>2 can be found by trying
20 % a pick in the row space of vs'. Any pick with pick*uis full column rank will provide a foward state
21 % (i.e. ok an odd number).
22 % uiu: uiu'y(t)=0, and this is interpretable as the decision rule setting controls as functions of the states.
23 % The solution was in the form y(t)=G1*y(t-1)+impact*z(t). Now it's in the form y(t)=GS*pickn*y(t-1)+impact*z(t).
24 % In general, pickn is mxn with m<n.
25
26 %
27 % Copyright (C) 1997-2012 Tao Zha
28 %
29 % This free software: you can redistribute it and/or modify
30 % it under the terms of the GNU General Public License as published by
31 % the Free Software Foundation, either version 3 of the License, or
32 % (at your option) any later version.
33 %
34 % It is distributed in the hope that it will be useful,
35 % but WITHOUT ANY WARRANTY; without even the implied warranty of
36 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 % GNU General Public License for more details.
38 %
39 % If you did not received a copy of the GNU General Public License
40 % with this software, see <http://www.gnu.org/licenses/>.
41 %
42
43 REALSMALL=1e-9;
44 [nr,nc]=size(G1);
45 %if nr<nc
46 % G1=[G1;zeros(nc-nr,nc)];
47 %end
48 [u d v]=svd(G1);
49 top=find(diag(d)>REALSMALL);
50 nd=top(end);
51 us=u(:,top);
52 uu=u(:,top+1:end);
53 d=d(top,top);
54 vs=v(:,top);
55 if nargin<=2
56 pick=vs';
57 vp=v;
58 vps=vs;
59 dp=eye(nd);
60 ups=eye(nr,nd);
61 ndp=nd;
62 else
63 [up dp vp]=svd(pick);
64 topp=find(diag(dp)>REALSMALL);
65 ndp=topp(end);
66 vps=vp(:,topp);
67 dp=dp(topp,topp);
68 ups=up(:,topp);
69 end
70 % If we were worried about efficiency, we'd skip some of this when pick=vs.
71 %Does pick summarize history? (pick in v' row space, v in vp' row space).
72 pinv=all(all((pick'-vs*vs'*pick').^2<REALSMALL));
73 vinp=all(all((vs-vps*vps'*vs).^2<REALSMALL));
74 okpast=pinv+vinp;
75 % Does pick summarize all current info? (impact in us column space, pick*uu full rank)
76 [ui,di,vi]=svd([impact us]);
77 topi=find(diag(di)>REALSMALL);
78 ndi=length(topi);
79 uis=ui(:,topi);
80 uiu=ui(:,ndi+1:size(ui,2));
81 if ndi<size(G1,1)
82 if(size(pick,1)<size(uis,2))
83 oknow=0;
84 else
85 [ut,dt,vt]=svd(pick*uis);
86 toppu=find(diag(dt)>REALSMALL);
87 if length(toppu)<size(us,2)
88 oknow=0;
89 else
90 oknow=1;
91 end
92 end
93 else
94 oknow=0;
95 end
96 if vinp
97 GS=G1/pick;
98 pickn=pick;
99 elseif pinv
100 r=vs-vps*vps'*vs;
101 [ur,dr,vr]=svd(r);
102 topr=find(dr>REALSMALL);
103 p2=ur(:,topr);
104 pickn=[pick;p2'];
105 GS=G1/pickn;
106 elseif oknow
107 GS=G1/[pick;uiu'];
108 GS=GS(:,1:size(pick,1));
109 pickn=pick;
110 else
111 pickn=vs';
112 GS=us*d;
113 end
114 ok=oknow+2*pinv+4*vinp;