Debian Codegraph @

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

raw
1 function [g,badg] = pmddg236(x,idmat0,idmatp,fss,nvar, ...
2 ncoef,phi,y,A0b,sg0bid,sgpbid);
3 %
4 % Leeper-Sims-Zha BVAR setup, analytical gradient for "csminwel.m"
5 % general program to setup A0 matrix and compute the likelihood
6 % requires x (parameter vector), a0indx (matrix indicating the free
7 % parameters in A0), fss (forecast sample size), nvar (number of variables),
8 % ncoef (number of coefficients in a single equation in A+), phi (r.h.s.
9 % observations in the system for A+), y (l.h.s. observations for A0),
10 % ymy (Y'*M*Y), xd0 (X(0) for dummy observations y*(1)), ys1 (dummy initial
11 % observations y*(1)), xtx (X'X or phi'*phi), A0b (initial prior on A0),
12 % sg0bid (diagonal of Sigma0_bar on the parameters in i-th equation in A0,
13 % initial prior covariace matrix), sgpbid (diagonal of Sigma+_bar on the
14 % parameters in i-th equation in A0, initial prior covariance matrix).
15 %
16 % Copyright (C) 1997-2012 Tao Zha
17 %
18 % This free software: you can redistribute it and/or modify
19 % it under the terms of the GNU General Public License as published by
20 % the Free Software Foundation, either version 3 of the License, or
21 % (at your option) any later version.
22 %
23 % It is distributed in the hope that it will be useful,
24 % but WITHOUT ANY WARRANTY; without even the implied warranty of
25 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 % GNU General Public License for more details.
27 %
28 % If you did not received a copy of the GNU General Public License
29 % with this software, see <http://www.gnu.org/licenses/>.
30 %
31
32 global vaha0 vaMMa0 FRESHFUNCTION
33 % CAS added FRESHFUNCTION 8/20/96 to allow use of pmddg23 in a numerical Hessian calculation, where
34 % it is invoked repeatedly without new function evaluations.
35 if ~FRESHFUNCTION
36 fjnk = pmddf236(x,idmat0,idmatp,fss,nvar,ncoef,phi,y,A0b,sg0bid,sgpbid);
37 end
38 FRESHFUNCTION=0;
39 badg = 0;
40 %
41 a0indx=find(idmat0);
42 nhp = 0; % <<>> 4 hyperparameters
43 na0p = length(a0indx); % <<>> number of A0 parameters
44 nfp = na0p+nhp;
45 g = zeros(nfp,1);
46 A0h= zeros(nvar);
47 A0h(a0indx) = x(1:na0p);
48 % restrictions on A0
49
50 %disp(sprintf('Starting loop (gradient): %g',toc))
51
52
53 %%%%%%%
54 %%% analytical gradient for A0 below
55 %%%%%%%
56 %
57 % ** dla0 = dlog|A0|/d(a0??)
58 vdla0 = zeros(na0p,1);
59 dla0 = inv(A0h)';
60 dla0 = dla0(:);
61 vdla0 = dla0(a0indx);
62
63 % without the prior |A0|^k
64 g = -fss*vdla0 + 0.5*vaha0 + 0.5*vaMMa0;
65
66 %disp(sprintf('Loop end (gradient): %g', toc))