Commit 644d8c8a authored by ferhat's avatar ferhat
Browse files

Load_params_and_steady_state is now a dynare command -> needed to normalize the equations.

 -> MatlabFile.cc and MatlabFile.hh are added to dynare in order to read the Mat-File

git-svn-id: https://www.dynare.org/svn/dynare/trunk@2349 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 25d7c93a
...@@ -303,7 +303,6 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block ...@@ -303,7 +303,6 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
ModelBlock->Block_List[count_Block].IM_lead_lag[i].Equ = (int*)malloc(tmp_size[incidencematrix.Model_Max_Lag_Endo - Lag + i] * sizeof(int)); ModelBlock->Block_List[count_Block].IM_lead_lag[i].Equ = (int*)malloc(tmp_size[incidencematrix.Model_Max_Lag_Endo - Lag + i] * sizeof(int));
ModelBlock->Block_List[count_Block].IM_lead_lag[i].Var_Index = (int*)malloc(tmp_size[incidencematrix.Model_Max_Lag_Endo - Lag + i] * sizeof(int)); ModelBlock->Block_List[count_Block].IM_lead_lag[i].Var_Index = (int*)malloc(tmp_size[incidencematrix.Model_Max_Lag_Endo - Lag + i] * sizeof(int));
ModelBlock->Block_List[count_Block].IM_lead_lag[i].Equ_Index = (int*)malloc(tmp_size[incidencematrix.Model_Max_Lag_Endo - Lag + i] * sizeof(int)); ModelBlock->Block_List[count_Block].IM_lead_lag[i].Equ_Index = (int*)malloc(tmp_size[incidencematrix.Model_Max_Lag_Endo - Lag + i] * sizeof(int));
//cout << "count_Block = " << count_Block << " i = " << i << " size_other_endo = " << tmp_size_other_endo[incidencematrix.Model_Max_Lag_Endo - Lag + i] << "\n";
ModelBlock->Block_List[count_Block].IM_lead_lag[i].size_other_endo = tmp_size_other_endo[incidencematrix.Model_Max_Lag_Endo - Lag + i]; ModelBlock->Block_List[count_Block].IM_lead_lag[i].size_other_endo = tmp_size_other_endo[incidencematrix.Model_Max_Lag_Endo - Lag + i];
ModelBlock->Block_List[count_Block].IM_lead_lag[i].nb_other_endo = tmp_other_endo[incidencematrix.Model_Max_Lag_Endo - Lag + i]; ModelBlock->Block_List[count_Block].IM_lead_lag[i].nb_other_endo = tmp_other_endo[incidencematrix.Model_Max_Lag_Endo - Lag + i];
ModelBlock->Block_List[count_Block].IM_lead_lag[i].u_other_endo = (int*)malloc(tmp_size_other_endo[incidencematrix.Model_Max_Lag_Endo - Lag + i] * sizeof(int)); ModelBlock->Block_List[count_Block].IM_lead_lag[i].u_other_endo = (int*)malloc(tmp_size_other_endo[incidencematrix.Model_Max_Lag_Endo - Lag + i] * sizeof(int));
...@@ -428,9 +427,10 @@ BlockTriangular::Free_Block(Model_Block* ModelBlock) const ...@@ -428,9 +427,10 @@ BlockTriangular::Free_Block(Model_Block* ModelBlock) const
free(ModelBlock->Block_List[blk].Variable); free(ModelBlock->Block_List[blk].Variable);
free(ModelBlock->Block_List[blk].Exogenous); free(ModelBlock->Block_List[blk].Exogenous);
free(ModelBlock->Block_List[blk].Own_Derivative); free(ModelBlock->Block_List[blk].Own_Derivative);
free(ModelBlock->Block_List[blk].Other_Endogenous);
for (i = 0;i < ModelBlock->Block_List[blk].Max_Lag + ModelBlock->Block_List[blk].Max_Lead + 1;i++) for (i = 0;i < ModelBlock->Block_List[blk].Max_Lag + ModelBlock->Block_List[blk].Max_Lead + 1;i++)
{ {
if (incidencematrix.Model_Max_Lag_Endo-ModelBlock->Block_List[blk].Max_Lag+i>=0 && ModelBlock->Block_List[blk].IM_lead_lag[i].size) if (incidencematrix.Model_Max_Lag_Endo-ModelBlock->Block_List[blk].Max_Lag+i>=0 /*&& ModelBlock->Block_List[blk].IM_lead_lag[i].size*/)
{ {
free(ModelBlock->Block_List[blk].IM_lead_lag[i].u); free(ModelBlock->Block_List[blk].IM_lead_lag[i].u);
free(ModelBlock->Block_List[blk].IM_lead_lag[i].us); free(ModelBlock->Block_List[blk].IM_lead_lag[i].us);
...@@ -438,8 +438,13 @@ BlockTriangular::Free_Block(Model_Block* ModelBlock) const ...@@ -438,8 +438,13 @@ BlockTriangular::Free_Block(Model_Block* ModelBlock) const
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Var); free(ModelBlock->Block_List[blk].IM_lead_lag[i].Var);
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Equ_Index); free(ModelBlock->Block_List[blk].IM_lead_lag[i].Equ_Index);
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Var_Index); free(ModelBlock->Block_List[blk].IM_lead_lag[i].Var_Index);
free(ModelBlock->Block_List[blk].IM_lead_lag[i].u_other_endo);
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Var_other_endo);
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Equ_other_endo);
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Var_Index_other_endo);
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Equ_Index_other_endo);
} }
if (incidencematrix.Model_Max_Lag_Exo-ModelBlock->Block_List[blk].Max_Lag+i>=0 && ModelBlock->Block_List[blk].IM_lead_lag[i].size_exo) if (incidencematrix.Model_Max_Lag_Exo-ModelBlock->Block_List[blk].Max_Lag+i>=0 /*&& ModelBlock->Block_List[blk].IM_lead_lag[i].size_exo*/)
{ {
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Exogenous); free(ModelBlock->Block_List[blk].IM_lead_lag[i].Exogenous);
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Exogenous_Index); free(ModelBlock->Block_List[blk].IM_lead_lag[i].Exogenous_Index);
...@@ -539,8 +544,6 @@ BlockTriangular::Reduce_Blocks_and_type_determination(int prologue, int epilogue ...@@ -539,8 +544,6 @@ BlockTriangular::Reduce_Blocks_and_type_determination(int prologue, int epilogue
tmp_output.str(""); tmp_output.str("");
lhs->writeOutput(tmp_output, oMatlabDynamicModelSparse, temporary_terms); lhs->writeOutput(tmp_output, oMatlabDynamicModelSparse, temporary_terms);
tmp_s << "y(it_, " << Index_Var_IM[first_count_equ].index+1 << ")"; tmp_s << "y(it_, " << Index_Var_IM[first_count_equ].index+1 << ")";
//cout << "tmp_s=" << tmp_s.str() << " tmp_output=" << tmp_output.str() << " " << bool(tmp_output.str()==tmp_s.str()) << " " << BlockSim(Simulation_Type)
// << " first_count_equ=" << first_count_equ << " equation=" << Index_Equ_IM[first_count_equ].index << "\n";
//Determine whether the equation could be evaluated rather than to be solved //Determine whether the equation could be evaluated rather than to be solved
if (tmp_output.str()==tmp_s.str()) if (tmp_output.str()==tmp_s.str())
{ {
...@@ -553,7 +556,6 @@ BlockTriangular::Reduce_Blocks_and_type_determination(int prologue, int epilogue ...@@ -553,7 +556,6 @@ BlockTriangular::Reduce_Blocks_and_type_determination(int prologue, int epilogue
{ {
tmp_output.str(""); tmp_output.str("");
rhs->writeOutput(tmp_output, oCDynamicModelSparseDLL, temporary_terms); rhs->writeOutput(tmp_output, oCDynamicModelSparseDLL, temporary_terms);
//cout << "sec tmp_s=" << tmp_s.str() << " tmp_output=" << tmp_output.str() << " " << bool(tmp_output.str()==tmp_s.str()) << " " << BlockSim(Simulation_Type) << "\n";
if (tmp_output.str()==tmp_s.str()) if (tmp_output.str()==tmp_s.str())
{ {
if (Simulation_Type==SOLVE_BACKWARD_SIMPLE) if (Simulation_Type==SOLVE_BACKWARD_SIMPLE)
...@@ -568,10 +570,8 @@ BlockTriangular::Reduce_Blocks_and_type_determination(int prologue, int epilogue ...@@ -568,10 +570,8 @@ BlockTriangular::Reduce_Blocks_and_type_determination(int prologue, int epilogue
|| ((prev_Type == EVALUATE_BACKWARD_R || prev_Type == EVALUATE_BACKWARD) && (Simulation_Type == EVALUATE_BACKWARD_R || Simulation_Type == EVALUATE_BACKWARD)) || ((prev_Type == EVALUATE_BACKWARD_R || prev_Type == EVALUATE_BACKWARD) && (Simulation_Type == EVALUATE_BACKWARD_R || Simulation_Type == EVALUATE_BACKWARD))
) )
{ {
//cout << "Type[0].first=" << Type[0].first << " Type[0].second= " << Type[0].second << "\n";
BlockSimulationType c_Type = (Type[Type.size()-1]).first; BlockSimulationType c_Type = (Type[Type.size()-1]).first;
int c_Size = (Type[Type.size()-1]).second; int c_Size = (Type[Type.size()-1]).second;
//cout << "i=" << i << " Type.size()=" << Type.size() << " c_Size=" << c_Size << "\n";
Type[Type.size()-1]=make_pair(c_Type, ++c_Size); Type[Type.size()-1]=make_pair(c_Type, ++c_Size);
} }
else else
...@@ -582,11 +582,8 @@ BlockTriangular::Reduce_Blocks_and_type_determination(int prologue, int epilogue ...@@ -582,11 +582,8 @@ BlockTriangular::Reduce_Blocks_and_type_determination(int prologue, int epilogue
} }
else else
{ {
/*for (count_equ = first_count_equ; count_equ < Blck_Size+first_count_equ; count_equ++)
cout << Index_Equ_IM[count_equ ].index+1 << " " << Index_Var_IM[count_equ ].index+1 << "\n";*/
Type.push_back(make_pair(Simulation_Type, Blck_Size)); Type.push_back(make_pair(Simulation_Type, Blck_Size));
} }
//cout << "Type.size()= " << Type.size() << " BlockSim(Simulation_Type) = " << BlockSim(Simulation_Type) << "\n";
prev_Type = Simulation_Type; prev_Type = Simulation_Type;
} }
return(Type); return(Type);
...@@ -720,7 +717,6 @@ BlockTriangular::Normalize_and_BlockDecompose(bool* IM, Model_Block* ModelBlock, ...@@ -720,7 +717,6 @@ BlockTriangular::Normalize_and_BlockDecompose(bool* IM, Model_Block* ModelBlock,
Nb_SimulBlocks = 0; Nb_SimulBlocks = 0;
for (t_type::const_iterator it = Type.begin(); it!=Type.end(); it++) for (t_type::const_iterator it = Type.begin(); it!=Type.end(); it++)
{ {
//cout << "Block " << i++ << " Type=" << BlockSim(it->first) << " Size=" << it->second << "\n";
if (it->first==SOLVE_FORWARD_COMPLETE || it->first==SOLVE_BACKWARD_COMPLETE || it->first==SOLVE_TWO_BOUNDARIES_COMPLETE) if (it->first==SOLVE_FORWARD_COMPLETE || it->first==SOLVE_BACKWARD_COMPLETE || it->first==SOLVE_TWO_BOUNDARIES_COMPLETE)
{ {
Nb_SimulBlocks++; Nb_SimulBlocks++;
......
...@@ -828,6 +828,37 @@ DynaTypeStatement::writeOutput(ostream &output, const string &basename) const ...@@ -828,6 +828,37 @@ DynaTypeStatement::writeOutput(ostream &output, const string &basename) const
<< "',var_list_);" << endl; << "',var_list_);" << endl;
} }
SaveParamsAndSteadyStateStatement::SaveParamsAndSteadyStateStatement(const string &filename_arg) :
filename(filename_arg)
{
}
void
SaveParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &basename) const
{
output << "save_params_and_steady_state('" << filename << "');" << endl;
}
LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const string &filename_arg) :
filename(filename_arg)
{
}
void
LoadParamsAndSteadyStateStatement::checkPass(ModFileStructure &mod_file_struct)
{
mod_file_struct.load_params_and_steady_state_present = true;
mod_file_struct.load_params_and_steady_state_filename = filename;
}
void
LoadParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &basename) const
{
output << "load_params_and_steady_state('" << filename << "');" << endl;
}
ModelComparisonStatement::ModelComparisonStatement(const filename_list_type &filename_list_arg, ModelComparisonStatement::ModelComparisonStatement(const filename_list_type &filename_list_arg,
const OptionsList &options_list_arg) : const OptionsList &options_list_arg) :
filename_list(filename_list_arg), filename_list(filename_list_arg),
......
...@@ -96,7 +96,7 @@ class ParsingDriver; ...@@ -96,7 +96,7 @@ class ParsingDriver;
%token <string_val> INT_NUMBER %token <string_val> INT_NUMBER
%token INV_GAMMA1_PDF INV_GAMMA2_PDF IRF %token INV_GAMMA1_PDF INV_GAMMA2_PDF IRF
%token KALMAN_ALGO KALMAN_TOL %token KALMAN_ALGO KALMAN_TOL
%token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_MH_FILE LOGLINEAR LU %token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LU
%token MARKOWITZ MARGINAL_DENSITY MAX %token MARKOWITZ MARGINAL_DENSITY MAX
%token METHOD MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN %token METHOD MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN
%token MODE_CHECK MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS %token MODE_CHECK MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS
...@@ -109,7 +109,7 @@ class ParsingDriver; ...@@ -109,7 +109,7 @@ class ParsingDriver;
%token PRINT PRIOR_TRUNC PRIOR_ANALYSIS POSTERIOR_ANALYSIS %token PRINT PRIOR_TRUNC PRIOR_ANALYSIS POSTERIOR_ANALYSIS
%token <string_val> QUOTED_STRING %token <string_val> QUOTED_STRING
%token QZ_CRITERIUM %token QZ_CRITERIUM
%token RELATIVE_IRF REPLIC RPLOT %token RELATIVE_IRF REPLIC RPLOT SAVE_PARAMS_AND_STEADY_STATE
%token SHOCKS SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED SMOOTHER SOLVE_ALGO %token SHOCKS SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED SMOOTHER SOLVE_ALGO
%token SPARSE SPARSE_DLL STDERR STEADY STOCH_SIMUL %token SPARSE SPARSE_DLL STDERR STEADY STOCH_SIMUL
%token TEX RAMSEY_POLICY PLANNER_DISCOUNT %token TEX RAMSEY_POLICY PLANNER_DISCOUNT
...@@ -194,6 +194,8 @@ statement : declaration ...@@ -194,6 +194,8 @@ statement : declaration
| dynare_sensitivity | dynare_sensitivity
| homotopy_setup | homotopy_setup
| forecast | forecast
| load_params_and_steady_state
| save_params_and_steady_state
; ;
declaration : parameters declaration : parameters
...@@ -1088,6 +1090,16 @@ dynasave : DYNASAVE '(' filename ')'';' ...@@ -1088,6 +1090,16 @@ dynasave : DYNASAVE '(' filename ')'';'
{ driver.run_dynasave($3); } { driver.run_dynasave($3); }
; ;
load_params_and_steady_state: LOAD_PARAMS_AND_STEADY_STATE '(' filename ')' ';'
{driver.run_load_params_and_steady_state($3);}
;
save_params_and_steady_state: SAVE_PARAMS_AND_STEADY_STATE '(' filename ')' ';'
{driver.run_save_params_and_steady_state($3);}
;
model_comparison : MODEL_COMPARISON mc_filename_list ';' model_comparison : MODEL_COMPARISON mc_filename_list ';'
{ driver.run_model_comparison(); } { driver.run_model_comparison(); }
| MODEL_COMPARISON '(' o_marginal_density ')' mc_filename_list ';' | MODEL_COMPARISON '(' o_marginal_density ')' mc_filename_list ';'
...@@ -1234,9 +1246,9 @@ dynare_sensitivity_option : o_gsa_identification ...@@ -1234,9 +1246,9 @@ dynare_sensitivity_option : o_gsa_identification
| o_mode_file | o_mode_file
| o_gsa_trans_ident | o_gsa_trans_ident
; ;
homotopy_setup: HOMOTOPY_SETUP ';' homotopy_list END
homotopy_setup: HOMOTOPY_SETUP ';' homotopy_list END
{ driver.end_homotopy();}; { driver.end_homotopy();};
homotopy_list : homotopy_item homotopy_list : homotopy_item
...@@ -1263,6 +1275,7 @@ forecast_option: o_periods ...@@ -1263,6 +1275,7 @@ forecast_option: o_periods
| o_conf_sig | o_conf_sig
; ;
number : INT_NUMBER number : INT_NUMBER
| FLOAT_NUMBER | FLOAT_NUMBER
; ;
......
...@@ -29,7 +29,7 @@ using namespace std; ...@@ -29,7 +29,7 @@ using namespace std;
DynareFlex::lex(Dynare::parser::semantic_type *yylval, \ DynareFlex::lex(Dynare::parser::semantic_type *yylval, \
Dynare::parser::location_type *yylloc, \ Dynare::parser::location_type *yylloc, \
ParsingDriver &driver) ParsingDriver &driver)
// Shortcut to access tokens defined by Bison // Shortcut to access tokens defined by Bison
typedef Dynare::parser::token token; typedef Dynare::parser::token token;
...@@ -117,6 +117,9 @@ int sigma_e = 0; ...@@ -117,6 +117,9 @@ int sigma_e = 0;
<INITIAL>dynasave {BEGIN DYNARE_STATEMENT; return token::DYNASAVE;} <INITIAL>dynasave {BEGIN DYNARE_STATEMENT; return token::DYNASAVE;}
<INITIAL>model_comparison {BEGIN DYNARE_STATEMENT; return token::MODEL_COMPARISON;} <INITIAL>model_comparison {BEGIN DYNARE_STATEMENT; return token::MODEL_COMPARISON;}
<INITIAL>load_params_and_steady_state {BEGIN DYNARE_STATEMENT; return token::LOAD_PARAMS_AND_STEADY_STATE;}
<INITIAL>save_params_and_steady_state {BEGIN DYNARE_STATEMENT; return token::SAVE_PARAMS_AND_STEADY_STATE;}
<INITIAL>steady {BEGIN DYNARE_STATEMENT; return token::STEADY;} <INITIAL>steady {BEGIN DYNARE_STATEMENT; return token::STEADY;}
<INITIAL>check {BEGIN DYNARE_STATEMENT; return token::CHECK;} <INITIAL>check {BEGIN DYNARE_STATEMENT; return token::CHECK;}
<INITIAL>simul {BEGIN DYNARE_STATEMENT; return token::SIMUL;} <INITIAL>simul {BEGIN DYNARE_STATEMENT; return token::SIMUL;}
......
...@@ -2,7 +2,7 @@ include Makefile.include ...@@ -2,7 +2,7 @@ include Makefile.include
ifeq ($(shell uname -o), Cygwin) ifeq ($(shell uname -o), Cygwin)
DYNARE_M = dynare_m.exe DYNARE_M = dynare_m.exe
else else
DYNARE_M = dynare_m DYNARE_M = dynare_m
endif endif
...@@ -25,6 +25,7 @@ OBJS = \ ...@@ -25,6 +25,7 @@ OBJS = \
ParsingDriver.o \ ParsingDriver.o \
DataTree.o \ DataTree.o \
ModFile.o \ ModFile.o \
MatlabFile.o \
Statement.o \ Statement.o \
ExprNode.o \ ExprNode.o \
ModelNormalization.o \ ModelNormalization.o \
......
...@@ -37,13 +37,32 @@ ModFile::~ModFile() ...@@ -37,13 +37,32 @@ ModFile::~ModFile()
} }
void void
ModFile::evalAllExpressions() ModFile::evalAllExpressions()
{ {
//Evaluate Parameters //Evaluate Parameters
cout << "Evaluating expressions ...";
InitParamStatement *it; InitParamStatement *it;
int j=0; vector< vector<double> >::iterator it2;
ostringstream constant;
NodeID tmp_id;
CollectStruct collect_struct;
int j=0, k;
if(mod_file_struct.load_params_and_steady_state_present)
{
cout << "Reading " << mod_file_struct.load_params_and_steady_state_filename << " ...";
matlab_file.MatFileRead(mod_file_struct.load_params_and_steady_state_filename);
string sname="stored_values";
bool tmp_b=matlab_file.Collect(sname, collect_struct);
matlab_file.Delete();
if(!tmp_b)
{
cout << "The structure " << sname << " is not found in " << mod_file_struct.load_params_and_steady_state_filename << "\n";
}
cout << "done\n";
}
cout << "Evaluating expressions ...";
for(vector<Statement *>::const_iterator it1=statements.begin();it1!=statements.end(); it1++) for(vector<Statement *>::const_iterator it1=statements.begin();it1!=statements.end(); it1++)
{ {
it=dynamic_cast<InitParamStatement *>(*it1); it=dynamic_cast<InitParamStatement *>(*it1);
...@@ -63,6 +82,23 @@ ModFile::evalAllExpressions() ...@@ -63,6 +82,23 @@ ModFile::evalAllExpressions()
} }
} }
} }
if(mod_file_struct.load_params_and_steady_state_present && j!=symbol_table.parameter_nbr)
{
//Reading a Mat-File
for(k=0;k <symbol_table.parameter_nbr; k++)
{
if(global_eval_context.find(make_pair(k, eParameter))==global_eval_context.end())
{
map<string,vector<double> >::iterator it2=collect_struct.variable_double_name.find(symbol_table.getNameByID(eParameter, k));
if(it2!=collect_struct.variable_double_name.end())
{
j++;
vector<double>::iterator it=it2->second.begin();
global_eval_context[make_pair(k, eParameter)]=*it;
}
}
}
}
if (j!=symbol_table.parameter_nbr) if (j!=symbol_table.parameter_nbr)
{ {
cout << "Warning: Uninitialized parameters: \n"; cout << "Warning: Uninitialized parameters: \n";
...@@ -71,7 +107,6 @@ ModFile::evalAllExpressions() ...@@ -71,7 +107,6 @@ ModFile::evalAllExpressions()
if(global_eval_context.find(make_pair(j, eParameter))==global_eval_context.end()) if(global_eval_context.find(make_pair(j, eParameter))==global_eval_context.end())
cout << " " << symbol_table.getNameByID(eParameter, j) << "\n"; cout << " " << symbol_table.getNameByID(eParameter, j) << "\n";
} }
} }
//Evaluate variables //Evaluate variables
for(InitOrEndValStatement::init_values_type::const_iterator it=init_values.begin(); it!=init_values.end(); it++) for(InitOrEndValStatement::init_values_type::const_iterator it=init_values.begin(); it!=init_values.end(); it++)
...@@ -90,6 +125,82 @@ ModFile::evalAllExpressions() ...@@ -90,6 +125,82 @@ ModFile::evalAllExpressions()
cout << "error in evaluation of variable\n"; cout << "error in evaluation of variable\n";
} }
} }
if(mod_file_struct.load_params_and_steady_state_present && init_values.size()<symbol_table.endo_nbr+symbol_table.exo_nbr+symbol_table.exo_det_nbr)
{
for(j=0;j <symbol_table.endo_nbr; j++)
{
if(global_eval_context.find(make_pair(j, eEndogenous))==global_eval_context.end())
{
//it2=mat_file.variable.find(symbol_table.getNameByID(eEndogenous, j));
map<string,vector<double> >::iterator it2=collect_struct.variable_double_name.find(symbol_table.getNameByID(eEndogenous, j));
if(it2!=collect_struct.variable_double_name.end())
{
vector<double>::iterator it=it2->second.begin();
global_eval_context[make_pair(j, eEndogenous)]=*it;
constant.str("");
if(*it>=0)
{
constant << *it;
tmp_id=expressions_tree.AddNumConstant(constant.str());
}
else
{
constant << -*it;
tmp_id=expressions_tree.AddUMinus(expressions_tree.AddNumConstant(constant.str()));
}
init_values.push_back(make_pair(it2->first, tmp_id));
}
}
}
for(j=0;j <symbol_table.exo_nbr; j++)
{
if(global_eval_context.find(make_pair(j, eExogenous))==global_eval_context.end())
{
map<string,vector<double> >::iterator it2=collect_struct.variable_double_name.find(symbol_table.getNameByID(eExogenous, j));
if(it2!=collect_struct.variable_double_name.end())
{
vector<double>::iterator it=it2->second.begin();
global_eval_context[make_pair(j, eExogenous)]=*it;
constant.str("");
if(*it>=0)
{
constant << *it;
tmp_id=expressions_tree.AddNumConstant(constant.str());
}
else
{
constant << -*it;
tmp_id=expressions_tree.AddUMinus(expressions_tree.AddNumConstant(constant.str()));
}
init_values.push_back(make_pair(it2->first, tmp_id));
}
}
}
for(j=0;j <symbol_table.exo_det_nbr; j++)
{
if(global_eval_context.find(make_pair(j, eExogenous))==global_eval_context.end())
{
map<string,vector<double> >::iterator it2=collect_struct.variable_double_name.find(symbol_table.getNameByID(eExogenous, j));
if(it2!=collect_struct.variable_double_name.end())
{
vector<double>::iterator it=it2->second.begin();
global_eval_context[make_pair(j, eExogenous)]=*it;
constant.str("");
if(*it>=0)
{
constant << *it;
tmp_id=expressions_tree.AddNumConstant(constant.str());
}
else
{
constant << -*it;
tmp_id=expressions_tree.AddUMinus(expressions_tree.AddNumConstant(constant.str()));
}
init_values.push_back(make_pair(it2->first, tmp_id));
}
}
}
}
if(init_values.size()<symbol_table.endo_nbr+symbol_table.exo_nbr+symbol_table.exo_det_nbr) if(init_values.size()<symbol_table.endo_nbr+symbol_table.exo_nbr+symbol_table.exo_det_nbr)
{ {
cout << "\nWarning: Uninitialized variable: \n"; cout << "\nWarning: Uninitialized variable: \n";
......
...@@ -628,7 +628,6 @@ end: ...@@ -628,7 +628,6 @@ end:
<< ", equation=" << eq+1 << endl; << ", equation=" << eq+1 << endl;
} }
} }
//jacobian_max_exo_col=(variable_table.max_exo_lag+variable_table.max_exo_lead+1)*symbol_table.exo_nbr;
for (m=0;m<=ModelBlock->Block_List[j].Max_Lead+ModelBlock->Block_List[j].Max_Lag;m++) for (m=0;m<=ModelBlock->Block_List[j].Max_Lead+ModelBlock->Block_List[j].Max_Lag;m++)
{ {
k=m-ModelBlock->Block_List[j].Max_Lag; k=m-ModelBlock->Block_List[j].Max_Lag;
...@@ -677,7 +676,6 @@ end: ...@@ -677,7 +676,6 @@ end:
<< ", equation=" << eq+1 << endl; << ", equation=" << eq+1 << endl;
} }
} }
/*jacobian_max_endo_col=(variable_table.max_endo_lag+variable_table.max_endo_lead+1)*symbol_table.endo_nbr;*/
for (m=0;m<=ModelBlock->Block_List[j].Max_Lead+ModelBlock->Block_List[j].Max_Lag;m++) for (m=0;m<=ModelBlock->Block_List[j].Max_Lead+ModelBlock->Block_List[j].Max_Lag;m++)
{ {
k=m-ModelBlock->Block_List[j].Max_Lag; k=m-ModelBlock->Block_List[j].Max_Lag;
...@@ -694,7 +692,6 @@ end: ...@@ -694,7 +692,6 @@ end:
<< ", equation=" << eq+1 << endl; << ", equation=" << eq+1 << endl;
} }
} }
//jacobian_max_exo_col=(variable_table.max_exo_lag+variable_table.max_exo_lead+1)*symbol_table.exo_nbr;
for (m=0;m<=ModelBlock->Block_List[j].Max_Lead+ModelBlock->Block_List[j].Max_Lag;m++) for (m=0;m<=ModelBlock->Block_List[j].Max_Lead+ModelBlock->Block_List[j].Max_Lag;m++)
{ {
k=m-ModelBlock->Block_List[j].Max_Lag; k=m-ModelBlock->Block_List[j].Max_Lag;
...@@ -726,7 +723,6 @@ end: ...@@ -726,7 +723,6 @@ end:
int var=ModelBlock->Block_List[j].IM_lead_lag[m].Var_Index[i]; int var=ModelBlock->Block_List[j].IM_lead_lag[m].Var_Index[i];
int eqr=ModelBlock->Block_List[j].IM_lead_lag[m].Equ[i]; int eqr=ModelBlock->Block_List[j].IM_lead_lag[m].Equ[i];
int varr=ModelBlock->Block_List[j].IM_lead_lag[m].Var[i]; int varr=ModelBlock->Block_List[j].IM_lead_lag[m].Var[i];
//Uf[ModelBlock->Block_List[j].Equation[eqr]] << "+g1(" << eqr+1 << ", " << varr+1 << ")*y(it_, " << var+1 << ")";
output << " g1(" << eqr+1 << ", " << varr+1 << ") = "; output << " g1(" << eqr+1 << ", " << varr+1 << ") = ";
writeDerivative(output, eq, var, 0, oMatlabDynamicModelSparse, temporary_terms, eEndogenous); writeDerivative(output, eq, var, 0, oMatlabDynamicModelSparse, temporary_terms, eEndogenous);
output << "; % variable=" << symbol_table.getNameByID(eEndogenous, var) output << "; % variable=" << symbol_table.getNameByID(eEndogenous, var)
...@@ -833,7 +829,6 @@ end: ...@@ -833,7 +829,6 @@ end:
<< ", equation=" << eq+1 << endl; << ", equation=" << eq+1 << endl;
} }
} }
//jacobian_max_exo_col=(variable_table.max_exo_lag+variable_table.max_exo_lead+1)*symbol_table.exo_nbr;
for (m=0;m<=ModelBlock->Block_List[j].Max_Lead+ModelBlock->Block_List[j].Max_Lag;m++) for (m=0;m<=ModelBlock->Block_List[j].Max_Lead+ModelBlock->Block_List[j].Max_Lag;m++)
{ {
k=m-ModelBlock->Block_List[j].Max_Lag; k=m-ModelBlock->Block_List[j].Max_Lag;
...@@ -854,7 +849,6 @@ end: ...@@ -854,7 +849,6 @@ end:
} }
} }
} }
//output << " else" << endl;
output << " varargout{1}=g1_x;\n"; output << " varargout{1}=g1_x;\n";
output << " varargout{2}=g1_o;\n"; output << " varargout{2}=g1_o;\n";
output << " end;\n"; output << " end;\n";
...@@ -955,7 +949,6 @@ ModelTree::writeModelStaticEquationsOrdered_M(Model_Block *ModelBlock, const str ...@@ -955,7 +949,6 @@ ModelTree::writeModelStaticEquationsOrdered_M(Model_Block *ModelBlock, const str
if (ModelBlock->Block_List[j].Temporary_terms->size()) if (ModelBlock->Block_List[j].Temporary_terms->size())
output << " " << sps << "% //Temporary variables" << endl; output << " " << sps << "% //Temporary variables" << endl;
i=0; i=0;
//temporary_terms_type tt2;
for (temporary_terms_type::const_iterator it = ModelBlock->Block_List[j].Temporary_terms->begin(); for (temporary_terms_type::const_iterator it = ModelBlock->Block_List[j].Temporary_terms->begin();
it != ModelBlock->Block_List[j].Temporary_terms->end(); it++) it != ModelBlock->Block_List[j].Temporary_terms->end(); it++)
{ {
...@@ -971,18 +964,14 @@ ModelTree::writeModelStaticEquationsOrdered_M(Model_Block *ModelBlock, const str ...@@ -971,18 +964,14 @@ ModelTree::writeModelStaticEquationsOrdered_M(Model_Block *ModelBlock, const str
// The equations // The equations
for (i = 0;i < ModelBlock->Block_List[j].Size;i++) for (i = 0;i < ModelBlock->Block_List[j].Size;i++)
{ {
//ModelBlock->Block_List[j].Variable_Sorted[i] = variable_table.getID(eEndogenous, ModelBlock->Block_List[j].Variable[i], 0);
string sModel = symbol_table.getNameByID(eEndogenous, ModelBlock->Block_List[j].Variable[i]) ; string sModel = symbol_table.getNameByID(eEndogenous, ModelBlock->Block_List[j].Variable[i]) ;
output << sps << " % equation " << ModelBlock->Block_List[j].Equation[i]+1 << " variable : " output << sps << " % equation " << ModelBlock->Block_List[j].Equation[i]+1 << " variable : "
<< sModel << " (" << ModelBlock->Block_List[j].Variable[i]+1 << ")" << endl; << sModel << " (" << ModelBlock->Block_List[j].Variable[i]+1 << ")" << endl;
/*if (!lhs_rhs_done) eq_node = equations[ModelBlock->Block_List[j].Equation[i]];
{*/ lhs = eq_node->arg1;
eq_node = equations[ModelBlock->Block_List[j].Equation[i]]; rhs = eq_node->arg2;
lhs = eq_node->arg1; tmp_output.str("");
rhs = eq_node->arg2; lhs->writeOutput(tmp_output, oMatlabStaticModelSparse, temporary_terms);
tmp_output.str("");
lhs->writeOutput(tmp_output, oMatlabStaticModelSparse, temporary_terms);
/*}*/
output << " ";