Commit 601c087b authored by Houtan Bastani's avatar Houtan Bastani
Browse files

conform to ANSI-C (C90) standard (for -ansi flag under Linux)

parent 341e6a29
This diff is collapsed.
This diff is collapsed.
......@@ -7,7 +7,7 @@
#include "modify_for_mex.h"
//====== Static Global Variables ======
/* //====== Static Global Variables ====== ansi-c*/
static TStateModel *Model=(TStateModel*)NULL;
static PRECISION *buffer=(PRECISION*)NULL;
static PRECISION *ModifiedFreeParameters=(PRECISION*)NULL;
......@@ -48,25 +48,25 @@ PRECISION PosteriorObjectiveFunction(PRECISION *x, int n)
ConvertFreeParametersToTheta(Model,FreeParameters_Theta);
return -LogPosterior_StatesIntegratedOut(Model);
//PRECISION lp_Q, lp_Theta, li;
//FILE *f_out;
//lp_Q=LogPrior_Q(Model);
//lp_Theta=LogPrior_Theta(Model);
//li=LogLikelihood_StatesIntegratedOut(Model);
//if (isnan(lp_Q) || isnan(lp_Theta) || isnan(li))
// {
// f_out=fopen("tmp.tmp","wt");
// Write_VAR_Specification(f_out,(char*)NULL,Model);
// WriteTransitionMatrices(f_out,(char*)NULL,"Error: ",Model);
// Write_VAR_Parameters(f_out,(char*)NULL,"Error: ",Model);
// fprintf(f_out,"LogPrior_Theta(): %le\n",lp_Theta);
// fprintf(f_out,"LogPrior_Q(): %le\n",lp_Q);
// fprintf(f_out,"LogLikelihood_StatesIntegratedOut(): %le\n",li);
// fprintf(f_out,"Posterior: %le\n\n",lp_Q+lp_Theta+li);
// fclose(f_out);
// exit(0);
// }
//return -(lp_Q+lp_Theta+li);
/* //PRECISION lp_Q, lp_Theta, li; ansi-c*/
/* //FILE *f_out; ansi-c*/
/* //lp_Q=LogPrior_Q(Model); ansi-c*/
/* //lp_Theta=LogPrior_Theta(Model); ansi-c*/
/* //li=LogLikelihood_StatesIntegratedOut(Model); ansi-c*/
/* //if (isnan(lp_Q) || isnan(lp_Theta) || isnan(li)) ansi-c*/
/* // { ansi-c*/
/* // f_out=fopen("tmp.tmp","wt"); ansi-c*/
/* // Write_VAR_Specification(f_out,(char*)NULL,Model); ansi-c*/
/* // WriteTransitionMatrices(f_out,(char*)NULL,"Error: ",Model); ansi-c*/
/* // Write_VAR_Parameters(f_out,(char*)NULL,"Error: ",Model); ansi-c*/
/* // fprintf(f_out,"LogPrior_Theta(): %le\n",lp_Theta); ansi-c*/
/* // fprintf(f_out,"LogPrior_Q(): %le\n",lp_Q); ansi-c*/
/* // fprintf(f_out,"LogLikelihood_StatesIntegratedOut(): %le\n",li); ansi-c*/
/* // fprintf(f_out,"Posterior: %le\n\n",lp_Q+lp_Theta+li); ansi-c*/
/* // fclose(f_out); ansi-c*/
/* // exit(0); ansi-c*/
/* // } ansi-c*/
/* //return -(lp_Q+lp_Theta+li); ansi-c*/
}
PRECISION PosteriorObjectiveFunction_csminwel(double *x, int n, double **args, int *dims)
......
......@@ -146,16 +146,16 @@ TMarkovStateVariable* ReadMarkovSpecification_SV(FILE *f_in, char *idstring, int
int *FreeDim, **NonZeroIndex;
TMarkovStateVariable *sv=(TMarkovStateVariable*)NULL, **sv_array;
// Get nobs if necessary
/* // Get nobs if necessary ansi-c*/
if ((nobs > 0) || !(err=ReadInteger(f_in,idformat="//== Number observations ==//",trailer,&nobs)))
{
// Construct trailer
/* // Construct trailer ansi-c*/
if (idstring[0])
sprintf(trailer=(char*)malloc(24+strlen(idstring)),"for state_variable%s ==//",idstring);
else
strcpy(trailer=(char*)malloc(5),"==//");
// Read number of state variables
/* // Read number of state variables ansi-c*/
if (!(err=ReadInteger(f_in,idformat="//== Number independent state variables %s",trailer,&n_state_variables)))
{
if (n_state_variables > 1)
......@@ -176,10 +176,10 @@ TMarkovStateVariable* ReadMarkovSpecification_SV(FILE *f_in, char *idstring, int
}
else
{
// Read number states
/* // Read number states ansi-c*/
if (!(err=ReadInteger(f_in,idformat="//== Number states %s",trailer,&nstates)))
{
// Read number of lags to encode
/* // Read number of lags to encode ansi-c*/
switch (err=ReadInteger(f_in,idformat="//== Number of lags encoded %s",trailer,&nlags_encoded))
{
case SWITCHIO_ERROR_READING_DATA:
......@@ -193,7 +193,7 @@ TMarkovStateVariable* ReadMarkovSpecification_SV(FILE *f_in, char *idstring, int
break;
}
// Read number of base states
/* // Read number of base states ansi-c*/
if (nlags_encoded > 0)
{
if (err=ReadInteger(f_in,idformat="//== Number of base states %s",trailer,&nbasestates))
......@@ -206,21 +206,21 @@ TMarkovStateVariable* ReadMarkovSpecification_SV(FILE *f_in, char *idstring, int
}
}
// Read prior
/* // Read prior ansi-c*/
Prior=CreateMatrix(nstates,nstates);
if (!(err=ReadMatrix(f_in,idformat="//== Prior %s",trailer,Prior)))
{
// Read free Dirichlet dimensions
/* // Read free Dirichlet dimensions ansi-c*/
if (!(err=ReadInteger(f_in,idformat="//== Number free Dirichlet variables %s",trailer,&i)))
{
FreeDim=dw_CreateArray_int(i);
if (!(err=ReadIntArray(f_in,idformat="//== Free Dirichlet dimensions %s",trailer,FreeDim)))
{
// Read free Dirichlet index
/* // Read free Dirichlet index ansi-c*/
NonZeroIndex=dw_CreateRectangularArray_int(nstates,nstates);
if (!(err=ReadIntArray(f_in,idformat="//== Free Dirichlet index %s",trailer,NonZeroIndex)))
{
// Read free Dirichlet multipliers
/* // Read free Dirichlet multipliers ansi-c*/
MQ=CreateMatrix(nstates,nstates);
if (!(err=ReadMatrix(f_in,idformat="//== Free Dirichlet multipliers %s",trailer,MQ)))
if (sv=CreateMarkovStateVariable_Single(nstates,nobs,Prior,FreeDim,NonZeroIndex,MQ))
......@@ -258,7 +258,7 @@ int WriteMarkovSpecification_SV(FILE *f_out, TMarkovStateVariable *sv, char *ids
if (idstring[0])
{
// 24 characters in "for state_variable ==//" plus null character
/* // 24 characters in "for state_variable ==//" plus null character ansi-c*/
trailer=(char*)malloc(24+strlen(idstring));
sprintf(trailer,"for state_variable%s ==//",idstring);
......@@ -397,7 +397,7 @@ int ReadTransitionMatrices_SV(FILE *f_in, TMarkovStateVariable* sv, char *header
}
else
{
// Read transition matrix
/* // Read transition matrix ansi-c*/
if (!header) header="";
format="//== %sTransition matrix%s ==//";
sprintf(idbuffer=(char*)malloc(strlen(header) + strlen(format) + strlen(idstring) - 3),format,header,idstring);
......@@ -412,7 +412,7 @@ int ReadTransitionMatrices_SV(FILE *f_in, TMarkovStateVariable* sv, char *header
free(idbuffer);
if (!err)
{
// Scale the columns of Q - loose requirement on sumation to one
/* // Scale the columns of Q - loose requirement on sumation to one ansi-c*/
for (j=sv->nstates-1; j >= 0; j--)
{
for (sum=0.0, i=sv->nstates-1; i >= 0; i--)
......@@ -432,7 +432,7 @@ int ReadTransitionMatrices_SV(FILE *f_in, TMarkovStateVariable* sv, char *header
ElementM(sv->Q,i,j)*=sum;
}
// Update
/* // Update ansi-c*/
if (!Update_B_from_Q_SV(sv))
{
dw_UserError("Transition matrices do not satisfy restrictions");
......@@ -520,7 +520,7 @@ int ReadBaseTransitionMatrices_SV(FILE *f_in, TMarkovStateVariable* sv, char *he
}
else
{
// Read transition matrix
/* // Read transition matrix ansi-c*/
Q=CreateMatrix(sv->nbasestates,sv->nbasestates);
if (!header) header="";
format="//== %sBase transition matrix%s ==//";
......@@ -536,7 +536,7 @@ int ReadBaseTransitionMatrices_SV(FILE *f_in, TMarkovStateVariable* sv, char *he
free(idbuffer);
if (!err)
{
// Scale the columns of Q - loose requirement on sumation to one
/* // Scale the columns of Q - loose requirement on sumation to one ansi-c*/
for (j=sv->nbasestates-1; j >= 0; j--)
{
for (sum=0.0, i=sv->nbasestates-1; i >= 0; i--)
......@@ -558,10 +558,10 @@ int ReadBaseTransitionMatrices_SV(FILE *f_in, TMarkovStateVariable* sv, char *he
ElementM(Q,i,j)*=sum;
}
// Convert base transition matrix to full transition matrix.
/* // Convert base transition matrix to full transition matrix. ansi-c*/
ConvertBaseTransitionMatrix(sv->Q,Q,sv->nlags_encoded);
// Update
/* // Update ansi-c*/
if (!Update_B_from_Q_SV(sv))
{
dw_UserError("Transition matrices do not satisfy restrictions");
......@@ -910,7 +910,7 @@ int ReadStates(FILE *f, char *filename, char *header, TStateModel *model)
ReadError(format,header,err);
else
{
// Check states and propagate
/* // Check states and propagate ansi-c*/
for (i=model->sv->nstates; i >= 0; i--)
if ((model->sv->S[i] < 0) || (model->sv->S[i] >= model->sv->nstates))
{
......@@ -1016,13 +1016,13 @@ TMarkovStateVariable* CreateMarkovStateVariable_File(FILE *f, char *filename, in
TMatrix* restrictions;
TMarkovStateVariable **sv, *rtrn=(TMarkovStateVariable*)NULL, *tmp;
// Open file if necessary
/* // Open file if necessary ansi-c*/
if (!f)
f_in=dw_OpenTextFile(filename);
else
f_in=f;
// Check for Flat Independent Markov States and Simple Restrictions
/* // Check for Flat Independent Markov States and Simple Restrictions ansi-c*/
if (dw_SetFilePosition(f_in,"//== Flat Independent Markov States and Simple Restrictions ==//"))
{
if (nobs <= 0)
......@@ -1128,7 +1128,7 @@ TMarkovStateVariable* CreateMarkovStateVariable_File(FILE *f, char *filename, in
rtrn=sv[0];
}
// Close file if necessary
/* // Close file if necessary ansi-c*/
if (!f) fclose(f_in);
return rtrn;
......
......@@ -46,7 +46,7 @@ int main(int nargs, char **args)
(char*)NULL,
(char*)NULL};
//=== Help Screen ===
/* //=== Help Screen === ansi-c*/
if (dw_FindArgument_String(nargs,args,"h") != -1)
{
printf("print_draws <options>\n");
......@@ -54,7 +54,7 @@ int main(int nargs, char **args)
return 0;
}
//=== Get seed, tuning peroid, burn-in period, number of iterations, and thinning factor
/* //=== Get seed, tuning peroid, burn-in period, number of iterations, and thinning factor ansi-c*/
seed=dw_ParseInteger_String(nargs,args,"gs",0);
tuning=dw_ParseInteger_String(nargs,args,"mh",30000);
iterations=dw_ParseInteger_String(nargs,args,"i",1000);
......@@ -62,10 +62,10 @@ int main(int nargs, char **args)
thinning=dw_ParseInteger_String(nargs,args,"t",1);
nd1=(dw_FindArgument_String(nargs,args,"nd1") >= 0) ? 1 : 0;
//=== Initialize random number generator
/* //=== Initialize random number generator ansi-c*/
dw_initialize_generator(seed);
//=== Setup model and initial parameters
/* //=== Setup model and initial parameters ansi-c*/
printf("Reading data...\n");
if (!(model=CreateTStateModelFromEstimateFinal(nargs,args,&cmd)))
{
......@@ -74,7 +74,7 @@ int main(int nargs, char **args)
}
p=(T_VAR_Parameters*)(model->theta);
//=== Open header file and print headers
/* //=== Open header file and print headers ansi-c*/
filename=CreateFilenameFromTag("%sheader_%s.dat",cmd->out_tag,cmd->out_directory);
f_out=fopen(filename,"wt");
free(filename);
......@@ -83,24 +83,24 @@ int main(int nargs, char **args)
fprintf(f_out,"\n");
fclose(f_out);
//=== Open output file
/* //=== Open output file ansi-c*/
filename=CreateFilenameFromTag("%sdraws_%s.dat",cmd->out_tag,cmd->out_directory);
f_out=fopen(filename,"wt");
free(filename);
// Burn-in period with calibration of jumping parameters
/* // Burn-in period with calibration of jumping parameters ansi-c*/
printf("Calibrating jumping parameters - %d draws\n",tuning);
begin_time=(int)time((time_t*)NULL);
AdaptiveMetropolisScale(model,tuning,1000,1,(FILE*)NULL); // tuning iterations - 1000 iterations before updating - verbose
AdaptiveMetropolisScale(model,tuning,1000,1,(FILE*)NULL); /* tuning iterations - 1000 iterations before updating - verbose ansi-c*/
end_time=(int)time((time_t*)NULL);
printf("Elapsed Time: %d seconds\n",end_time - begin_time);
// Reset parametrers
/* // Reset parametrers ansi-c*/
if (!ReadTransitionMatrices((FILE*)NULL,cmd->parameters_filename_actual,cmd->parameters_header_actual,model)
|| !Read_VAR_Parameters((FILE*)NULL,cmd->parameters_filename_actual,cmd->parameters_header_actual,model))
printf("Unable to reset parameters after tuning\n");
// Burn-in period
/* // Burn-in period ansi-c*/
printf("Burn-in period - %d draws\n",burn_in);
for (check=period, count=1; count <= burn_in; count++)
{
......@@ -116,7 +116,7 @@ int main(int nargs, char **args)
printf("Elapsed Time: %d seconds\n",end_time - begin_time);
ResetMetropolisInformation(p);
// Simulation
/* // Simulation ansi-c*/
printf("Simulating - %d draws\n",iterations);
for (check=period, output=thinning, count=1; count <= iterations; count++)
{
......@@ -142,7 +142,7 @@ int main(int nargs, char **args)
end_time=(int)time((time_t*)NULL);
printf("Elapsed Time: %d seconds\n",end_time - begin_time);
// clean up
/* // clean up ansi-c*/
fclose(f_out);
FreeStateModel(model);
Free_VARCommandLine(cmd);
......
This diff is collapsed.
......@@ -6,125 +6,125 @@
#include "swzmatrix.h"
#include "dw_matrix_array.h"
#define standard_ordering 1 // for future implementation
#define standard_ordering 1 /* for future implementation ansi-c*/
#define SPEC_RANDOM_WALK 0x00000001
#define SPEC_SIMS_ZHA 0x00000002
//=== Normalization types (must be mutually exclusive) ===//
/* //=== Normalization types (must be mutually exclusive) ===// ansi-c*/
#define VAR_NORMALIZATION_NONE 0x00000000
#define VAR_NORMALIZATION_WZ 0x00000001
typedef struct
{
//====== Model specification ======
/* //====== Model specification ====== ansi-c*/
int Specification;
int *IsIdentity_V;
//====== Free parameter specification (for future implementation) ======
/* //====== Free parameter specification (for future implementation) ====== ansi-c*/
int FreeParameterType;
//====== Sizes ======
/* //====== Sizes ====== ansi-c*/
int nvars;
int nlags;
int npre;
int nobs;
int nstates;
//====== State variable translation ======
int* n_var_states; // nvars n_var_states[j] is the number of variance states for column j
int** var_states; // nvars x n_states translation table for variance states
int* n_coef_states; // nvars n_coef_states[j] is the number of coefficients states for column j
int** coef_states; // nvars x n_states translation table for coefficient states
int n_A0_states; // number of states for the matrix A0
int* A0_states; // n_states translation table for the matrix A0
int** A0_column_states; // nvars x n_A0_states translation table from determinant of A0 states to coefficient states
//====== Parameters ======
PRECISION** Zeta; // nvars x n_var_states[j]
TVector** A0; // nvars x n_coef_states[j] x nvars
TVector** Aplus; // nvars x n_coef_states[j] x npre
//====== Free parameters ======
/* //====== State variable translation ====== ansi-c*/
int* n_var_states; /* nvars n_var_states[j] is the number of variance states for column j ansi-c*/
int** var_states; /* nvars x n_states translation table for variance states ansi-c*/
int* n_coef_states; /* nvars n_coef_states[j] is the number of coefficients states for column j ansi-c*/
int** coef_states; /* nvars x n_states translation table for coefficient states ansi-c*/
int n_A0_states; /* number of states for the matrix A0 ansi-c*/
int* A0_states; /* n_states translation table for the matrix A0 ansi-c*/
int** A0_column_states; /* nvars x n_A0_states translation table from determinant of A0 states to coefficient states ansi-c*/
/* //====== Parameters ====== ansi-c*/
PRECISION** Zeta; /* nvars x n_var_states[j] ansi-c*/
TVector** A0; /* nvars x n_coef_states[j] x nvars ansi-c*/
TVector** Aplus; /* nvars x n_coef_states[j] x npre ansi-c*/
/* //====== Free parameters ====== ansi-c*/
int* dim_b0;
TVector** b0;
int* dim_bplus;
TVector** bplus;
//====== Priors ======
TVector zeta_a_prior; //
TVector zeta_b_prior; //
TMatrix* A0_prior; // A0_prior[j] = constant parameter variance of the normal prior on the jth column of A0
TMatrix* Aplus_prior; // Aplus_prior[j] = constant parameter variance of the normal prior on the jth column of Aplus
/* //====== Priors ====== ansi-c*/
TVector zeta_a_prior; /* ansi-c*/
TVector zeta_b_prior; /* ansi-c*/
TMatrix* A0_prior; /* A0_prior[j] = constant parameter variance of the normal prior on the jth column of A0 ansi-c*/
TMatrix* Aplus_prior; /* Aplus_prior[j] = constant parameter variance of the normal prior on the jth column of Aplus ansi-c*/
//====== Identifying restrictions ======
/* //====== Identifying restrictions ====== ansi-c*/
TMatrix *U;
TMatrix *V;
TMatrix *W;
//====== Sims-Zha specification parameters and workspace ======
TVector** lambda; // nvars x n_coef_states[j] array of nvars-dimensional vectors
TVector* constant; // nvars x n_coef_states[j] -- constant[j][k] == psi[j][npre - 1 + k]
TVector* psi; // nvars x (npre - 1 + n_coef_states[j])
PRECISION lambda_prior; // prior variance of each element of lambda
/* //====== Sims-Zha specification parameters and workspace ====== ansi-c*/
TVector** lambda; /* nvars x n_coef_states[j] array of nvars-dimensional vectors ansi-c*/
TVector* constant; /* nvars x n_coef_states[j] -- constant[j][k] == psi[j][npre - 1 + k] ansi-c*/
TVector* psi; /* nvars x (npre - 1 + n_coef_states[j]) ansi-c*/
PRECISION lambda_prior; /* prior variance of each element of lambda ansi-c*/
PRECISION inverse_lambda_prior;
TMatrix* inverse_psi_prior;
//====== Normalization ======
int normalization_type; // type of normalization used
int normalized; // type of normalization actually used to normalize current draw
TVector** Target; // nvar x n_coef_states[j] array of nvars-dimensional vectors
int** flipped; // nvar x n_coef_states[j] array of integers
/* //====== Normalization ====== ansi-c*/
int normalization_type; /* type of normalization used ansi-c*/
int normalized; /* type of normalization actually used to normalize current draw ansi-c*/
TVector** Target; /* nvar x n_coef_states[j] array of nvars-dimensional vectors ansi-c*/
int** flipped; /* nvar x n_coef_states[j] array of integers ansi-c*/
int WZ_inconsistancies;
//====== Workspace ======
PRECISION log_prior_constant; // Constant of integrate for the log prior
PRECISION minus_half_nvars_times_log2pi; // Constant used in LogConditionalProbability functions
TVector inverse_zeta_b_prior; // inverse_zeta_b_prior = 1.0/zeta_b_prior
TMatrix* inverse_b0_prior; // inverse_b0_prior = U'[j]*Inverse(A0_prior[j])*U[j]
TMatrix* inverse_bplus_prior; // inverse_bplus_prior = V'[j]*Inverse(Aplus_prior[j])*V[j]
/* //====== Workspace ====== ansi-c*/
PRECISION log_prior_constant; /* Constant of integrate for the log prior ansi-c*/
PRECISION minus_half_nvars_times_log2pi; /* Constant used in LogConditionalProbability functions ansi-c*/
TVector inverse_zeta_b_prior; /* inverse_zeta_b_prior = 1.0/zeta_b_prior ansi-c*/
TMatrix* inverse_b0_prior; /* inverse_b0_prior = U'[j]*Inverse(A0_prior[j])*U[j] ansi-c*/
TMatrix* inverse_bplus_prior; /* inverse_bplus_prior = V'[j]*Inverse(Aplus_prior[j])*V[j] ansi-c*/
TVector log_abs_det_A0; // log(abs(det(A0[k])))
TVector log_abs_det_A0; /* log(abs(det(A0[k]))) ansi-c*/
PRECISION*** A0_dot_products; // A0_dot_products[t][j][k] = Y'[t] * A0[j][k]
PRECISION*** Aplus_dot_products; // Aplus_dot_products[t][j][k] = X'[t] * Aplus[j][k]
PRECISION*** A0_dot_products; /* A0_dot_products[t][j][k] = Y'[t] * A0[j][k] ansi-c*/
PRECISION*** Aplus_dot_products; /* Aplus_dot_products[t][j][k] = X'[t] * Aplus[j][k] ansi-c*/
// A0 Metropolis Info
/* // A0 Metropolis Info ansi-c*/
PRECISION** A0_Metropolis_Scale;
int Total_A0_Metropolis_Draws;
int** A0_Metropolis_Jumps;
// State dependent fields
TMatrix* YY; // YY[k] = sum(Y[t]*Y'[t], 1 <= t <= nobs and S[t] == k)
TMatrix* XY; // YX[k] = sum(X[t]*Y'[t], 1 <= t <= nobs and S[t] == k)
TMatrix* XX; // XX[k] = sum(X[t]*X'[t], 1 <= t <= nobs and S[t] == k)
int* T; // T[k] = number of t with 1 <= t <= nobs and S[t] == k
int *S; // S[t] = state variable used to compute YY, XY, XX, and T
TMatrix* yy; // yy[t] = Y[t]*Y'[t]
TMatrix* xy; // xy[t] = X[t]*Y'[t]
TMatrix* xx; // xx[t] = X[t]*X'[t]
// Flags for validity of workspace fields
int valid_log_abs_det_A0; // Invalid after A0 changes
int valid_dot_products; // Invalid after A0 or Aplus changes
int valid_state_dependent_fields; // Invalid after states change
int valid_state_dependent_fields_previous; // Initially invalid.
int valid_parameters; // Initially invalid. Valid after successful read or draw of parameters.
// Parametes are invalid if Zeta is negative or if they do not satisfy
// the normalization.
//=== Data ===
TVector* Y; // Y[t] nvar vector of time t data for 1 <= t <= T
TVector* X; // X[t] npre vector of time t predetermined variables for 1 <= t <= T
/* // State dependent fields ansi-c*/
TMatrix* YY; /* YY[k] = sum(Y[t]*Y'[t], 1 <= t <= nobs and S[t] == k) ansi-c*/
TMatrix* XY; /* YX[k] = sum(X[t]*Y'[t], 1 <= t <= nobs and S[t] == k) ansi-c*/
TMatrix* XX; /* XX[k] = sum(X[t]*X'[t], 1 <= t <= nobs and S[t] == k) ansi-c*/
int* T; /* T[k] = number of t with 1 <= t <= nobs and S[t] == k ansi-c*/
int *S; /* S[t] = state variable used to compute YY, XY, XX, and T ansi-c*/
TMatrix* yy; /* yy[t] = Y[t]*Y'[t] ansi-c*/
TMatrix* xy; /* xy[t] = X[t]*Y'[t] ansi-c*/
TMatrix* xx; /* xx[t] = X[t]*X'[t] ansi-c*/
/* // Flags for validity of workspace fields ansi-c*/
int valid_log_abs_det_A0; /* Invalid after A0 changes ansi-c*/
int valid_dot_products; /* Invalid after A0 or Aplus changes ansi-c*/
int valid_state_dependent_fields; /* Invalid after states change ansi-c*/
int valid_state_dependent_fields_previous; /* Initially invalid. ansi-c*/
int valid_parameters; /* Initially invalid. Valid after successful read or draw of parameters. ansi-c*/
/* // Parametes are invalid if Zeta is negative or if they do not satisfy ansi-c*/
/* // the normalization. ansi-c*/
/* //=== Data === ansi-c*/
TVector* Y; /* Y[t] nvar vector of time t data for 1 <= t <= T ansi-c*/
TVector* X; /* X[t] npre vector of time t predetermined variables for 1 <= t <= T ansi-c*/
} T_VAR_Parameters;
// Constructors-Destructors
/* // Constructors-Destructors ansi-c*/
void FreeTheta_VAR(T_VAR_Parameters *p);
ThetaRoutines* CreateRoutines_VAR(void);
T_VAR_Parameters* CreateTheta_VAR(int flag, int nvars, int nlags, int nexg, int nstates, int nobs, // Specification and Sizes
int **coef_states, int **var_states, // Translation Tables
TMatrix *U, TMatrix *V, TMatrix *W, // Restrictions
TMatrix Y, TMatrix X); // Data
T_VAR_Parameters* CreateTheta_VAR(int flag, int nvars, int nlags, int nexg, int nstates, int nobs, /* Specification and Sizes ansi-c*/
int **coef_states, int **var_states, /* Translation Tables ansi-c*/
TMatrix *U, TMatrix *V, TMatrix *W, /* Restrictions ansi-c*/
TMatrix Y, TMatrix X); /* Data ansi-c*/
int** CreateTranslationMatrix_Flat(int **states, TMarkovStateVariable *sv);
void SetPriors_VAR(T_VAR_Parameters *theta, TMatrix* A0_prior, TMatrix* Aplus_prior, TVector zeta_a_prior, TVector zeta_b_prior);
......@@ -145,47 +145,47 @@ TVector ExpectationSingleStep_VAR(TVector y, int s, int t, TStateModel *model);
void DrawParameters_VAR(TStateModel *model);
void InitializeParameters_VAR(T_VAR_Parameters *p);
// Priors
/* // Priors ansi-c*/
void SetLogPriorConstant_VAR(T_VAR_Parameters *p);
PRECISION LogPrior_VAR(TStateModel *model);
// Normalization
/* // Normalization ansi-c*/
int IsNormalized_VAR(T_VAR_Parameters *p);
int Normalize_VAR(T_VAR_Parameters *p);
void Setup_No_Normalization(T_VAR_Parameters *p);
void Setup_WZ_Normalization(T_VAR_Parameters *p, TVector **A0);
int WZ_Normalize(T_VAR_Parameters *p);
// Notification
/* // Notification ansi-c*/
void StatesChanged_VAR(TStateModel *model);
void ThetaChanged_VAR(TStateModel *model);
void InitializeForwardRecursion_VAR(TStateModel *model);
// Utility Routines
/* // Utility Routines ansi-c*/
int Reset_VAR_Improper_Distribution_Counter(void);
int Get_VAR_Improper_Distribution_Counter(void);
void Increment_Verbose(void);
void SetVerboseFile(FILE *f);
// Optimization
/* // Optimization ansi-c*/
int NumberFreeParametersVAR(TStateModel *model);
void FreeParametersToVAR(TStateModel *model, PRECISION *f);
void VARToFreeParameters(TStateModel *model, PRECISION *f);
int ZetaIndex(T_VAR_Parameters *p);
int ZetaLength(T_VAR_Parameters *p);
//PRECISION ComputeConstantSimsZha(TStateModel *model);
/* //PRECISION ComputeConstantSimsZha(TStateModel *model); ansi-c*/
//
/* // ansi-c*/
void PsiDeltaToAplus(TStateModel *model);
// Impulse Response
/* // Impulse Response ansi-c*/
TMatrix ComputeImpulseResponseReducedForm(TMatrix R, int h, TMatrix A0_Xi_inv, TMatrix B, int nlags);
TMatrix ComputeImpulseResponseStructural(TMatrix R, int h, TMatrix A0, TMatrix Aplus, TVector Xi, int nlags);
TMatrix ComputeImpulseResponse(TMatrix R, int h, int k, TStateModel *model);
TMatrix ComputeVarianceDecomposition(TMatrix X, TMatrix IR, int nvars);
// Simulation
/* // Simulation ansi-c*/
void DrawZeta_Aplus(TStateModel *model);
void DrawZeta_DotProducts(TStateModel *model);
void AdaptiveMetropolisScale(TStateModel *model, int iterations, int period, int verbose, FILE *f_posterior);
......@@ -219,8 +219,8 @@ void Update_lambda_psi_from_bplus(T_VAR_Parameters *p);
int GetNumberStatesFromTranslationMatrix(int j, int **states);
int **CreateTranslationMatrix(TMarkovStateVariable ***list, TMarkovStateVariable *sv);
//PRECISION InnerProductSymmetric(TVector x, TMatrix S);
//PRECISION InnerProductNonSymmetric(TVector x, TVector y, TMatrix S);
/* //PRECISION InnerProductSymmetric(TVector x, TMatrix S); ansi-c*/
/* //PRECISION InnerProductNonSymmetric(TVector x, TVector y, TMatrix S); ansi-c*/
void update_psi_quadratic_form(TMatrix S, int n, int m, int k, TVector lambda, TMatrix XX);
TMatrix MatrixInnerProductSymmetric(TMatrix X, TMatrix Y, TMatrix S);
......@@ -231,10 +231,10 @@ TVector DrawNormal_InverseVariance_SVD(TVector x, TVector b, TMatrix S);
TVector DrawNormal_InverseUpperTriangular(TVector x, TVector b, TMatrix T);
// Obsolete routines
/* // Obsolete routines ansi-c*/
#endif // __VAR_BASE_MODEL__
#endif /* __VAR_BASE_MODEL__ ansi-c*/
/********************************************************************************
......
......@@ -101,14 +101,14 @@ TStateModel* Read_VAR_Specification(FILE *f, char *filename)
int **coef_states, **var_states;
PRECISION** A0_Metropolis_Scale=(PRECISION**)NULL;
// Valid file
/* // Valid file ansi-c*/