Debian Codegraph @

contrib/ms-sbvar/switch_dw/state_space/sbvar/VARbase.h

raw
1 /*
2 * Copyright (C) 1996-2011 Daniel Waggoner and Tao Zha
3 *
4 * This free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * It is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * If you did not received a copy of the GNU General Public License
15 * with this software, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef __VAR_BASE_MODEL__
19 #define __VAR_BASE_MODEL__
20
21 #include "dw_switch.h"
22 #include "dw_matrix.h"
23 #include "dw_matrix_array.h"
24
25 #define standard_ordering 1 // for future implementation
26 #define SPEC_RANDOM_WALK 0x00000001
27 #define SPEC_SIMS_ZHA 0x00000002
28
29 //=== Normalization types (must be mutually exclusive) ===//
30 #define VAR_NORMALIZATION_NONE 0x00000000
31 #define VAR_NORMALIZATION_WZ 0x00000001
32 #define VAR_NORMALIZATION_RECURSIVE 0x00000002
33
34 typedef struct
35 {
36 //====== Model specification ======
37 int Specification;
38 int *IsIdentity_V;
39
40 //====== Free parameter specification (for future implementation) ======
41 int FreeParameterType;
42
43 //====== Sizes ======
44 int nvars;
45 int nlags;
46 int npre;
47 int nobs;
48 int nstates;
49 int n_free_parameters;
50
51 //====== State variable translation ======
52 int* n_var_states; // nvars n_var_states[j] is the number of variance states for column j
53 int** var_states; // nvars x n_states Zeta[j][var_states[j][k]] is the jth diagonal element of Zeta(s(t)) when s(t)=k.
54 int* n_coef_states; // nvars n_coef_states[j] is the number of coefficients states for column j
55 int** coef_states; // nvars x n_states A0[j][coef_states[j][k]] is the jth column of A0(s(t)) when s(t)=k.
56 int n_A0_states; // number of distinct matrices A0
57 int* A0_states; // n_states number between 0 and n_A0_states-1, inclusive. A0[j][A0_column_states[j][A0_states[k]]] is the jth column of A0(s(t)) when s(t)=k.
58 int** A0_column_states; // nvars x n_A0_states translation table from determinant of A0 states to coefficient states
59
60 //====== Parameters ======
61 PRECISION** Zeta; // nvars x n_var_states[j]
62 TVector** A0; // nvars x n_coef_states[j] of nvars dimensional vectors
63 TVector** Aplus; // nvars x n_coef_states[j] of npre dimensional vectors
64
65 //====== Free parameters ======
66 int* dim_b0;
67 TVector** b0;
68 int* dim_bplus;
69 TVector** bplus;
70
71 //====== Priors ======
72 TVector zeta_a_prior; // parameter for gamma distribution on zeta
73 TVector zeta_b_prior; // parameter for gamma distribution
74 TMatrix* A0_prior; // A0_prior[j] = constant parameter variance of the normal prior on the jth column of A0
75 TMatrix* Aplus_prior; // Aplus_prior[j] = constant parameter variance of the normal prior on the jth column of Aplus
76
77 //====== Identifying restrictions ======
78 TMatrix *U;
79 TMatrix *V;
80 TMatrix *W;
81
82 //====== Sims-Zha specification parameters and workspace ======
83 TVector** lambda; // nvars x n_coef_states[j] array of nvars dimensional vectors
84 TVector* constant; // nvars array of n_coef_states[j] dimensional vectors : constant[j][k] == psi[j][nvars*nlags + k]
85 TVector* psi; // nvars array of (nvars*nlags + n_coef_states[j]) dimensional vectors
86 PRECISION lambda_prior; // prior variance of each element of lambda
87 PRECISION inverse_lambda_prior;
88 TMatrix* inverse_psi_prior; // inverse_psi_prior[j] is the inverse of the variance of the prior on psi[j]
89
90 //====== Normalization ======
91 int normalization_type; // type of normalization used
92 TVector** Target; // nvar x n_coef_states[j] array of nvars-dimensional vectors
93 int **flipped;
94 int inconclusive_normalizations; // number of normalization inconsistancies encountered
95 PRECISION log_normalization_constant; // log normalization constant
96
97 //====== Workspace ======
98 PRECISION log_prior_constant; // Constant of integration for the log prior
99 PRECISION minus_half_nvars_times_log2pi; // Constant used in LogConditionalProbability functions
100 TVector inverse_zeta_b_prior; // inverse_zeta_b_prior = 1.0/zeta_b_prior
101 TMatrix* inverse_b0_prior; // inverse_b0_prior = U'[j]*Inverse(A0_prior[j])*U[j]
102 TMatrix* inverse_bplus_prior; // inverse_bplus_prior = V'[j]*Inverse(Aplus_prior[j])*V[j]
103
104 TVector log_abs_det_A0; // log(abs(det(A0[k])))
105
106 PRECISION*** A0_dot_products; // A0_dot_products[t][j][k] = Y'[t] * A0[j][k]
107 PRECISION*** Aplus_dot_products; // Aplus_dot_products[t][j][k] = X'[t] * Aplus[j][k]
108
109 // A0 Metropolis Info
110 PRECISION** A0_Metropolis_Scale;
111 int Total_A0_Metropolis_Draws;
112 int** A0_Metropolis_Jumps;
113
114 // State dependent fields
115 TMatrix* YY; // YY[k] = sum(Y[t]*Y'[t], 1 <= t <= nobs and S[t] == k)
116 TMatrix* XY; // YX[k] = sum(X[t]*Y'[t], 1 <= t <= nobs and S[t] == k)
117 TMatrix* XX; // XX[k] = sum(X[t]*X'[t], 1 <= t <= nobs and S[t] == k)
118 int* T; // T[k] = number of t with 1 <= t <= nobs and S[t] == k
119 int *S; // S[t] = state variable used to compute YY, XY, XX, and T
120 TMatrix* yy; // yy[t] = Y[t]*Y'[t]
121 TMatrix* xy; // xy[t] = X[t]*Y'[t]
122 TMatrix* xx; // xx[t] = X[t]*X'[t]
123
124 // Flags for validity of workspace fields
125 int valid_log_abs_det_A0; // Invalid after A0 changes
126 int valid_dot_products; // Invalid after A0 or Aplus changes
127 int valid_state_dependent_fields; // Invalid after states change
128 int valid_state_dependent_fields_previous; // Initially invalid.
129 int valid_parameters; // Initially invalid. Valid after successful read or draw of parameters. Parametes are invalid if Zeta is negative.
130 int valid_normalization; // Initially indeterminate (-1)
131
132 //=== Data ===
133 TVector* Y; // Y[t] nvar vector of time t data for 1 <= t <= T
134 TVector* X; // X[t] npre vector of time t predetermined variables for 1 <= t <= T
135
136 } T_VAR_Parameters;
137
138 // Constructors-Destructors
139 void FreeTheta_VAR(T_VAR_Parameters *p);
140 ThetaRoutines* CreateRoutines_VAR(void);
141 T_VAR_Parameters* CreateTheta_VAR(int flag, int nvars, int nlags, int nexg, int nstates, int nobs, // Specification and Sizes
142 int **coef_states, int **var_states, // Translation Tables
143 TMatrix *U, TMatrix *V, TMatrix *W, // Restrictions
144 TMatrix Y, TMatrix X); // Data
145 int** CreateTranslationMatrix_Flat(int **states, TMarkovStateVariable *sv);
146
147 void SetPriors_VAR(T_VAR_Parameters *theta, TMatrix* A0_prior, TMatrix* Aplus_prior, TVector zeta_a_prior, TVector zeta_b_prior);
148 void SetPriors_VAR_SimsZha(T_VAR_Parameters *theta, TMatrix* A0_prior, TMatrix* Aplus_prior, TVector zeta_a_prior,
149 TVector zeta_b_prior, PRECISION lambda_prior);
150
151
152 TStateModel* CreateConstantModel(TStateModel *model);
153 TStateModel* ExpandModel_VAR(TStateModel *model, TStateModel *restricted_model, int s);
154
155
156 void SetupSimsZhaSpecification(T_VAR_Parameters *p, PRECISION lambda_prior);
157
158 PRECISION LogConditionalProbability_VAR(int i, int t, TStateModel *model);
159 TVector ExpectationSingleStep_VAR(TVector y, int s, int t, TStateModel *model);
160
161
162 void DrawParameters_VAR(TStateModel *model);
163 void InitializeParameters_VAR(T_VAR_Parameters *p);
164 int IsDegenerate_VAR(int *regime_draws, TStateModel *model);
165
166 // Priors
167 void SetLogPriorConstant_VAR(T_VAR_Parameters *p);
168 PRECISION LogPrior_VAR(TStateModel *model);
169
170 // Normalization
171 void Setup_No_Normalization_VAR(T_VAR_Parameters *p);
172 void Setup_Diagonal_Normalization_VAR(T_VAR_Parameters *p);
173 void Setup_Default_Recursive_Normalization_VAR(T_VAR_Parameters *p);
174 void Setup_Recursive_Normalization_VAR(TVector **Target, T_VAR_Parameters *p);
175 void Setup_WZ_Normalization_VAR(TVector **Target, T_VAR_Parameters *p);
176 int IsNormalized_VAR(T_VAR_Parameters *p);
177 int Normalize_VAR(TStateModel *model, PRECISION *buffer);
178
179 // Regime Normalization
180 int NormalizeRegimes_VAR(TPermutation p, TStateModel *model, PRECISION *buffer);
181
182 // Notification
183 void StatesChanged_VAR(TStateModel *model);
184 void ThetaChanged_VAR(TStateModel *model);
185 int InitializeForwardRecursion_VAR(TStateModel *model);
186
187 // Utility Routines
188 int Reset_VAR_Improper_Distribution_Counter(void);
189 int Get_VAR_Improper_Distribution_Counter(void);
190 void Increment_Verbose(void);
191 void SetVerboseFile(FILE *f);
192
193 // Optimization
194 void SetNumberFreeParametersVAR(T_VAR_Parameters *p);
195 int NumberFreeParametersVAR(TStateModel *model);
196 void FreeParametersToVAR(TStateModel *model, PRECISION *f);
197 void VARToFreeParameters(TStateModel *model, PRECISION *f);
198 int ZetaIndex(T_VAR_Parameters *p);
199 int ZetaLength(T_VAR_Parameters *p);
200
201 //PRECISION ComputeConstantSimsZha(TStateModel *model);
202
203 //void PsiDeltaToAplus(TStateModel *model);
204
205 // Forecast
206 TMatrix forecast_base(TMatrix forecast, int horizon, TVector initial, TVector *shocks, int *S, TStateModel *model);
207
208 // Impulse Response
209 TMatrix ComputeImpulseResponseReducedForm(TMatrix R, int h, TMatrix A0_Xi_inv, TMatrix B, int nlags);
210 TMatrix ComputeImpulseResponseStructural(TMatrix R, int h, TMatrix A0, TMatrix Aplus, TVector Xi, int nlags);
211 TMatrix ComputeImpulseResponse(TMatrix R, int h, int k, TStateModel *model);
212 TMatrix ComputeVarianceDecomposition(TMatrix X, TMatrix IR, int nvars);
213
214 // Simulation
215 void DrawZeta_Aplus(TStateModel *model);
216 void DrawZeta_DotProducts(TStateModel *model);
217 void AdaptiveMetropolisScale(TStateModel *model, int iterations, int period, int verbose, FILE *f_posterior);
218 void SetupMetropolisInformation(PRECISION **Scale, T_VAR_Parameters *p);
219 void ResetMetropolisInformation(T_VAR_Parameters *p);
220 PRECISION LogKernel_A0_DotProducts(int j, int k, TStateModel *model);
221 PRECISION LogKernel_A0(int j, int k, TStateModel *model);
222 void DrawA0_Metropolis(TStateModel *model);
223 void DrawAplus(TStateModel *model);
224 void Draw_psi(TStateModel *model);
225 void Draw_lambda(TStateModel *model);
226
227 /* Utilities */
228 void ComputeDotProducts_All(T_VAR_Parameters *p);
229 void ComputeLogAbsDetA0_All(T_VAR_Parameters *p);
230 void ComputeLogAbsDetA0(int j, int k, T_VAR_Parameters *p);
231
232 TMatrix MakeA0(TMatrix A0, int k, T_VAR_Parameters *p);
233 TMatrix* MakeA0_All(TMatrix *A0, T_VAR_Parameters *p);
234 TMatrix MakeAplus(TMatrix Aplus, int k, T_VAR_Parameters *p);
235 TMatrix* MakeAplus_All(TMatrix *Aplus, T_VAR_Parameters *p);
236 TMatrix MakeZeta(TMatrix Zeta, int k, T_VAR_Parameters *p);
237 TMatrix* MakeZeta_All(TMatrix *Zeta, T_VAR_Parameters *p);
238 TMatrix MakeB(TMatrix B, int k, T_VAR_Parameters *p);
239 TMatrix* MakeB_All(TMatrix *Zeta, T_VAR_Parameters *p);
240 TMatrix ConstructMatrixFromColumns(TMatrix X, TVector **, int k);
241
242 void UpdateStateDependentFields(T_VAR_Parameters *p, int *S);
243 void Update_aplus_from_bplus_a0(int j, int k, T_VAR_Parameters *p);
244 void Update_A0_from_b0(T_VAR_Parameters *p);
245 void Update_Aplus_from_bplus_A0(T_VAR_Parameters *p);
246 void Update_bplus_from_lambda_psi(T_VAR_Parameters *p);
247 void Update_b0_bplus_from_A0_Aplus(T_VAR_Parameters *p);
248 void Update_lambda_psi_from_bplus(T_VAR_Parameters *p);
249
250 int GetNumberStatesFromTranslationMatrix(int j, int **states);
251 int **CreateTranslationMatrix(TMarkovStateVariable ***list, TMarkovStateVariable *sv);
252
253 //PRECISION InnerProductSymmetric(TVector x, TMatrix S);
254 //PRECISION InnerProductNonSymmetric(TVector x, TVector y, TMatrix S);
255
256 void update_psi_quadratic_form(TMatrix S, int n, int m, int k, TVector lambda, TMatrix XX);
257 TMatrix MatrixInnerProductSymmetric(TMatrix X, TMatrix Y, TMatrix S);
258 PRECISION InnerProductSymmetric(TVector x, TMatrix S);
259 PRECISION InnerProductNonSymmetric(TVector x, TVector y, TMatrix S);
260 TVector DrawNormal_InverseVariance(TVector x, TVector b, TMatrix S);
261 TVector DrawNormal_InverseVariance_SVD(TVector x, TVector b, TMatrix S);
262 TVector DrawNormal_InverseUpperTriangular(TVector x, TVector b, TMatrix T);
263
264
265 // Obsolete routines
266
267
268 #endif // __VAR_BASE_MODEL__
269
270
271 /********************************************************************************/
272 /************************************ Notes *************************************/
273 /********************************************************************************
274
275 The model:
276
277 y(t)' * A0(s(t)) = x(t)' * Aplus(s(t)) + epsilon(t)' * Inverse(Xi(s(t)))
278
279 where
280 y(t) is nvars x 1
281 x(t) is npre x 1
282 x(t)=[y(t-1),...,y(t-p),z(t)], where z(t) is exogenous
283 epsilon(t) is nvars x 1
284 A0(k) is nvars x nvars
285 Aplus(k) is npre x nvars
286 Xi(k) is an nvars x nvars diagonal matrix with positive entries
287 s(t) is an integer with 0 <= s(t) < nstates
288
289 Furthermore
290
291 A0(j,k) = U(j) * b0(j,k)
292
293 Aplus(j,k) = V(j) * bplus(j,k) - W(j) * A0(j,k)
294
295 and
296
297 Zeta(j,k) = Xi(j,k)*Xi(j,k)
298 where
299
300 A0(j,k) is the jth column of A0(k)
301 Aplus(j,k) is the jth column of A0(k)
302 Xi(j,k) is the jth diagonal element of Xi(k)
303 b0(j,k) is q(j) x 1
304 bplus(j,k) is r(j) x 1
305 U(j) is nvars x q(j) with orthonormal columns
306 V(j) is npre x r(j) with orthonormal columns
307 W(j) is npre x nvar
308
309
310 Normalization:
311 Multiplying b0(j,k) and bplus(j,k) by minus one results in a observationally
312 equivalent model. Thus there is a normalization issue. The default is to
313 normalize using the Waggoner-Zha normalization, though other methods are also
314 supported. The routine LogPrior_VAR() returns minus infinity if the rule is
315 violated. To see if the normalization rule is violated, call the routine
316 IsNormalized_VAR().
317
318 The estimation routine does not normalize internally, but does normalize the
319 final estimate by making the diagonal positive, if possible. If it is not
320 possible to make the diagonal positive because one or more of the diagonal
321 elements are restricted to be zero, see the routine
322 Setup_Default_Recursive_Normalization_VAR()
323 for details.
324
325 Simulation does not normalize during the simulation run, but does normalize
326 the output.
327
328 Recursive normalization: Requires a set of target vectors, Target[j][k] for
329 0 <= j < nvars and 0 <= k < n_coef_states[j]. Given the parameters A0[j][k]
330 and Aplus[j][k], we change the sign of A0[j][k] and Aplus[j][k] if
331 A0[j][k]' * Target[j][k] < 0. If the system is recursive, then the target
332 vectors can be chosen so that this normalization is the same as the Waggoner-
333 Zha normalization. Note that this rule is inconclusive on the set of all
334 A0[j][k] that are perpendicular to Target[j][k], which is a set of measure
335 zero. Furthermore, if the system is recursive and the targets are chosen to
336 give the Waggoner-Zha normalization, then the set parameters on which the rule
337 is inconclusive is equal to the set of parameters on which the likelihood is
338 zero.
339
340 Waggoner-Zha normalization: Requires a set of target vectors, Target[j][k] for
341 0 <= j < nvars and 0 <= k < n_coef_states[j]. Consider the set of all s such
342 that coef_states[j][s] = k. For each such s, form A0(s) and count the number
343 of times {e(j)' * inv(A0(s)) * Target[j][k]} is positive less the number of
344 times it is negative. If this number is negative, change the signs of A0[j][k]
345 and Aplus[j][k]. If this number is zero, then change the signs if
346 A0[j][k]' * Target[j][k] < 0. As for the recursive normalization, the set on
347 which this rule is inconclusive is of measure zero.
348
349 If there is no Markov switching, this is simply the usual Waggoner-Zha
350 normalization. If there is Markov switching, then one should think of this as
351 applying the Waggoner-Zha normalization rule to each contemporaneous matrix
352 A0(s). However, because the vector A0[j][k] could appear in multiple A0(s),
353 this could imply different normalizations of A0[j][k]. So, we normalize
354 A0[j][k] according to what the majority of the A0(s) imply. In the case of a
355 tie, we use an ad-hoc rule.
356
357
358 LogConditionalProbability_VAR
359
360 Sims-Zha Specification (original):
361 This specification imposes that r(j) = npre = nvars*nlags+1, V(j) is the
362 identity matrix, and W(j) is equal to a npre x nvars diagonal matrix with
363 minus ones along the diagonal. The single exogenous variable is taken to be
364 a constant.
365
366 If n_coef_states[j] > 1, further restrictions are imposed of the form:
367
368 bplus(j,k,i*nvars + l) = psi(j,i*nvars + l)*lambda(j,k,l) 0 <= i < nlags, 0 <= l < nvars
369
370 bplus(j,k,nvars*nlags) = psi(j,nlags*nvars+k) = constant(j,k)
371
372 where
373
374 psi(j) - nvars*nlags + n_coef_states[j]
375 lambda(j,k) - nvars
376
377 The specification imposes the normalization that lambda(j,0) be a vector of
378 ones.
379
380 Priors:
381 The prior distribution on psi(j) is normal with mean zero and variance equal
382 to the inverse of inverse_psi_prior(j).
383
384 The prior distribution on lambda(j,k) are independent normal distributions
385 with a mean of zero and a variance of lambda_prior.
386
387 Normalization:
388 Suppose that we change the sign of the vectors a0(j,k) and bplus(j,k). Because
389 lambda(j,0) is a vector of ones, we must change the sign of psi(j
390 normalization
391
392
393
394 Sims-Zha Specification (modified):
395 This specification imposes that r(j) = npre = nvars*nlags+1, V(j) is the
396 identity matrix, and W(j) is equal to a npre x nvars diagonal matrix with
397 minus ones along the diagonal. The single exogenous variable is taken to be
398 a constant. Further restrictions are imposed of the form.
399
400 bplus(j,k,i*nvars + l) = psi(j,i*nvars + l)*lambda(j,k,l) 0 <= i < nlags, 0 <= l < nvars
401
402 bplus(j,k,nvars*nlags) = psi(j,nvar*nlags)*lambda(j,k,nvars)
403
404 where
405
406 psi(j) - nvars*nlags + 1
407 lambda(j,k) - nvars + 1
408
409 This modified specification does not impose the normalization of the original.
410
411 Priors:
412 The prior distribution on psi(j) is normal with mean zero and variance equal
413 to the inverse of inverse_psi_prior(j).
414
415 The prior distribution on lambda(j,k) are independent normal distributions
416 with a mean of zero and a variance of lambda_prior.
417
418
419 Random Walk Specification:
420 This specification imposes that W(j) is equal to a npre x nvars diagonal
421 matrix with minus ones along the diagonal. Though it is not imposed, we
422 usually want Aplus(j,k) to satisfy linear restrictions implicit in the
423 matrix V(j). This means that W(j) must be in the span of V(j) and hence
424 (I - V(j)*V'(j))*W(j) = 0.
425
426
427 Normalization:
428 We normalize by requiring Xi(0) to be the identity matrix and
429 lambda(j,0) to be a vector of ones.
430
431 Prior:
432 A0(j,k) - The prior on A0(j,k) is normal with mean zero and covariance matrix
433 A0_Prior(j). This implies that the prior on b0(j,k) is normal with mean zero
434 and covariance matrix Inverse(U'[j]*Inverse(A0_prior[j])*U[j]).
435
436 Aplus(j,k) - The prior on Aplus(j,k) conditional on A0(j,k) is normal with mean
437 -W(j) * A0(j,k) and covariance Aplus_Prior(j). This implies that the prior on
438 bplus(j,k) is normal with mean zero and covariance matrix
439 Inverse(V'[j]*Inverse(Aplus_prior[j])*V[j]). In the Sims-Zha specifications,
440 prior is placed directly on psi(j) and lambda(j,k).
441
442 Zeta(j,k) - The prior on Zeta(j,k) is Gamma(zeta_a_prior(j),zeta_b_prior(j)).
443
444 ---------------------------------------------------------------------------------
445
446 TVector** A0
447 The length of A0 is nvars. The vector A0[j][k] is the jth column of A0 when
448 the jth coefficient state variable is equal to k. Note that when the Markov
449 state variable is equal to s, the jth coefficient state variable is equal to
450 coef_states[j][s]. The number of distinct values for the jth coefficient state
451 variable is equal to the dimension of A0[j]. This field is created with
452 dw_CreateArray_array() and freed with dw_FreeArray().
453
454 TVector** b0
455 The length of b0 is nvars. The vector b0[j][k] consists of the free parameters
456 in the jth column of A0 when the jth coefficient state variable is equal to k.
457 The dimension of b0[j][k] does not vary across k. Note that when the Markov
458 state variable is equal to s, the jth coefficient state variable is equal to
459 coef_states[j][s]. The dimension of b0[j] is equal to the dimension of A0[j].
460 This field is created with dw_CreateArray_array() and freed with
461 dw_FreeArray().
462
463 TVector** Aplus
464 The length of Aplus is nvars. The vector Aplus[j][k] is the jth column of
465 Aplus when the jth coefficient state variable is equal to k. Note that when
466 the Markov state variable is equal to s, the jth coefficient state variable is
467 equal to coef_states[j][s]. The dimension of Aplus[j] is equal to the
468 dimension of A0[j]. This field is created with dw_CreateArray_array() and
469 freed with dw_FreeArray().
470
471 TVector** bplus
472 The length of bplus is nvars. The vector bplus[j][k] consists of the free
473 parameters in the jth column of Aplus when the jth coefficient state variable
474 is equal to k. The dimension of bplus[j][k] does not vary across k. Note that
475 when the Markov state variable is equal to s, the jth coefficient state
476 variable is equal to coef_states[j][s]. The dimension of bplus[j] is equal to
477 the dimension of A0[j]. This field is created with dw_CreateArray_array() and
478 freed with dw_FreeArray().
479
480 PRECISION** Zeta
481 The length of Zeta is nvars. The value of Zeta[j][k] is the square of the
482 value of the jth diagonal element of Xi when the jth variance state variable is
483 equal to k. Note that the the Markov state variable is equal to s, the jth
484 variance state variable is equal to var_states[j][s]. The number of distinct
485 values for the jth variance state variable is equal to the dimension of
486 Zeta[j]. This field is created with dw_CreateArray_array() and freed with
487 dw_FreeArray().
488
489 TVector** lambda
490 The length of lambda is nvars, the length of lambda[j] is n_coef_states[j] and
491 the length of lambda[j][k] is nvars. The vector bplus[j][k] is a non-linear
492 function of lambda[j][k] and psi[k]. This field is non-null only when using
493 the Sims-Zha specification.
494
495 TVector* psi
496 The length of psi is nvars and the length of psi[j] is npre-1+n_coef_states[j].
497 The vector bplus[j][k] is a non-linear function of psi[j] and lambda[j][k].
498 This field is non-null only when using the Sims-Zha specification.
499
500
501 =============================== State Translation ===============================
502
503 int* n_var_states
504 An integer array of dimension nvars. The value of n_var_states[j] is the
505 number of variance states for column j.
506
507 int** var_states
508 An integer array of dimension nvars by nstates. The value of var_states[j][k]
509 is the value of the variance state for column j when the overall Markov state
510 variable is equal to k. It is used as an index into Xi[j]. It must be the
511 case that
512
513 0 <= var_states[j][k] < n_var_states[j].
514
515 int* n_coef_states
516 An integer arrary of dimension nvars. The value of n_coef_states[j] is the
517 number of coefficient states for column j.
518
519 int** coef_states
520 An integer array of dimension nvar by nstates. The value of coef_states[j][k]
521 is the value of the coefficient state for column j when the overall Markov
522 state variable is equal to k. It is used as an index into A0[j], b0[j],
523 Aplus[j] or bplus[j]. It must be the case that
524
525 0 <= coef_states[j][k] < n_coef_states[j].
526
527 int n_A0_states
528 The number of distinct values for the matrix A0.
529
530 int* A0_states
531 An integer array of dimension nstates. The value of A0_states[k] is the value
532 of the state variable controlling A0 when the value of the overall Markov state
533 variable is k. It is used as an index into the vector log_abs_det_A0. It must
534 be the case that
535
536 0 <= A0_states[k] < n_A0_states.
537
538 int** A0_column_states
539 An integer array of dimension nvars by n_A0_states. The value of
540 A0_column_states[j][k] is the value of the coefficient state for column j when
541 value of the state variable controlling the matrix A0 is k. It is used as an
542 index into A0[j]. It must be the case that
543
544 0 <= A0_column_states[j][k] < n_coef_states[j].
545
546
547 ================================= Normalization =================================
548 For 0 <= k < n_A0_states, the contemporaneous coefficient matrix A[k] is formed.
549 For 0 <= j < nvars and 0 <= k < n_A0_states, the number
550
551 e[j]*Inverse(A[k])*Target[j][A0_column_states[j][k]]
552
553 is computed. If this number is negative, then the sign of
554
555 A0[j][A0_column_states[j][k]]
556
557 is flipped. If the sign of any element of A0[j][.] is flipped more than once,
558 this event is recorded.
559
560 ********************************************************************************/