ms-dsge: change types of output for better packaging

time-shift
Houtan Bastani 2012-01-08 15:57:40 +01:00 committed by Michel Juillard
parent 8a0fca85e8
commit 0750bc707b
1 changed files with 35 additions and 42 deletions

View File

@ -2970,9 +2970,8 @@ DynamicModel::writeCOutput(ostream &output, const string &basename, bool block_d
vector<int> state_var, state_equ; vector<int> state_var, state_equ;
output << endl output << endl
<< "int lead_lag_incidence[" << "vector<vector<int > > lead_lag_incidence;" << endl
<< max_lag+max_lead+1 <<"][" << "vector<int > variable_presence;" << endl;
<< symbol_table.endo_nbr() << "];" << endl;
// Loop on endogenous variables // Loop on endogenous variables
int nstatic = 0, int nstatic = 0,
nfwrd = 0, nfwrd = 0,
@ -2980,6 +2979,7 @@ DynamicModel::writeCOutput(ostream &output, const string &basename, bool block_d
nboth = 0; nboth = 0;
for (int endoID = 0; endoID < symbol_table.endo_nbr(); endoID++) for (int endoID = 0; endoID < symbol_table.endo_nbr(); endoID++)
{ {
output << "variable_presence.clear();" << endl;
int sstatic = 1, int sstatic = 1,
sfwrd = 0, sfwrd = 0,
spred = 0, spred = 0,
@ -2991,58 +2991,52 @@ DynamicModel::writeCOutput(ostream &output, const string &basename, bool block_d
try try
{ {
int varID = getDerivID(symbol_table.getID(eEndogenous, endoID), lag); int varID = getDerivID(symbol_table.getID(eEndogenous, endoID), lag);
output << "lead_lag_incidence[" << lag + max_endo_lag << "][" << endoID << "] = " output << "variable_presence.push_back(" << getDynJacobianCol(varID) << ");" << endl;
<< getDynJacobianCol(varID) << ";" << endl;
if (lag == -1) if (lag == -1)
{ {
sstatic = 0; sstatic = 0;
spred = 1; spred = 1;
} }
else if (lag == 1) else if (lag == 1)
{ if (spred == 1)
if (spred == 1) {
{ sboth = 1;
sboth = 1; spred = 0;
spred = 0; }
} else
else {
{ sstatic = 0;
sstatic = 0; sfwrd = 1;
sfwrd = 1; }
}
}
} }
catch (UnknownDerivIDException &e) catch (UnknownDerivIDException &e)
{ {
output << "lead_lag_incidence[" << lag + max_endo_lag << "][" << endoID << "] = 0;" << endl; output << "variable_presence.push_back(0);" << endl;
} }
} }
nstatic += sstatic; nstatic += sstatic;
nfwrd += sfwrd; nfwrd += sfwrd;
npred += spred; npred += spred;
nboth += sboth; nboth += sboth;
output << "lead_lag_incidence.push_back(variable_presence);" << endl;
} }
output << "int nstatic = " << nstatic << ";" << endl output << "int nstatic = " << nstatic << ";" << endl
<< "int nfwrd = " << nfwrd << ";" << endl << "int nfwrd = " << nfwrd << ";" << endl
<< "int npred = " << npred << ";" << endl << "int npred = " << npred << ";" << endl
<< "int nboth = " << nboth << ";" << endl; << "int nboth = " << nboth << ";" << endl;
for (int endoID = 0; endoID < symbol_table.endo_nbr(); endoID++) for (int endoID = 0; endoID < symbol_table.endo_nbr(); endoID++)
{ // Loop on periods
// Loop on periods for (int lag = -max_endo_lag; lag < 0; lag++)
for (int lag = -max_endo_lag; lag < 0; lag++) // Print variableID if exists with current period, otherwise print 0
try
{
getDerivID(symbol_table.getID(eEndogenous, variable_reordered[endoID]), lag);
if (lag < 0 && find(state_var.begin(), state_var.end(), variable_reordered[endoID]+1) == state_var.end())
state_var.push_back(variable_reordered[endoID]);
}
catch (UnknownDerivIDException &e)
{ {
// Print variableID if exists with current period, otherwise print 0
try
{
getDerivID(symbol_table.getID(eEndogenous, variable_reordered[endoID]), lag);
if (lag < 0 && find(state_var.begin(), state_var.end(), variable_reordered[endoID]+1) == state_var.end())
state_var.push_back(variable_reordered[endoID]);
}
catch (UnknownDerivIDException &e)
{
}
} }
}
// Writing initialization for some other variables // Writing initialization for some other variables
output << endl output << endl
@ -3076,26 +3070,25 @@ DynamicModel::writeCOutput(ostream &output, const string &basename, bool block_d
<< "int maximum_exo_det_lead = " << max_exo_det_lead << ";" << endl << "int maximum_exo_det_lead = " << max_exo_det_lead << ";" << endl
<< "double exo_det_steady_state[" << symbol_table.exo_det_nbr() << "];" << endl; << "double exo_det_steady_state[" << symbol_table.exo_det_nbr() << "];" << endl;
if (symbol_table.param_nbr()) output << endl
output << endl << "map<int, double > params;" << endl;
<< "double params[" << symbol_table.param_nbr() << "];" << endl;
// Write number of non-zero derivatives // Write number of non-zero derivatives
// Use -1 if the derivatives have not been computed // Use -1 if the derivatives have not been computed
output << endl output << endl
<< "int NNZDerivatives[3];" << endl << "vector<double> NNZDerivatives;" << endl
<< "NNZDerivatives[0] = " << NNZDerivatives[0] << ";" << endl; << "NNZDerivatives.push_back(" << NNZDerivatives[0] << ");" << endl;
if (order > 1) if (order > 1)
{ {
output << "NNZDerivatives[1] = " << NNZDerivatives[1] << ";" << endl; output << "NNZDerivatives.push_back(" << NNZDerivatives[1] << ");" << endl;
if (order > 2) if (order > 2)
output << "NNZDerivatives[2] = " << NNZDerivatives[2] << ";" << endl; output << "NNZDerivatives.push_back(" << NNZDerivatives[2] << ");" << endl;
else else
output << "NNZDerivatives[2] = -1;" << endl; output << "NNZDerivatives.push_back(-1);" << endl;
} }
else else
output << "NNZDerivatives[1] = -1;" << endl output << "NNZDerivatives.push_back(-1);" << endl
<< "NNZDerivatives[2] = -1;" << endl; << "NNZDerivatives.push_back(-1);" << endl;
} }
map<pair<int, pair<int, int > >, expr_t> map<pair<int, pair<int, int > >, expr_t>