From ef17942b998f3f42af31879c77bd8254a05cba2f Mon Sep 17 00:00:00 2001 From: michel Date: Mon, 17 Oct 2005 19:55:03 +0000 Subject: [PATCH] v4 parser: added code for estimated_params_init and estimated_params_bounds git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@499 ac1d8469-bf42-47a9-8791-bf33cf982152 --- parser.src/ComputingTasks.cc | 106 +++++++++++++++++++++++++++- parser.src/DynareBison.yy | 4 ++ parser.src/DynareParser.cc | 8 +++ parser.src/include/ComputingTasks.h | 2 + parser.src/include/DynareParser.h | 2 + 5 files changed, 121 insertions(+), 1 deletion(-) diff --git a/parser.src/ComputingTasks.cc b/parser.src/ComputingTasks.cc index 55f3078ce..aa09e4fe9 100644 --- a/parser.src/ComputingTasks.cc +++ b/parser.src/ComputingTasks.cc @@ -131,7 +131,7 @@ void ComputingTasks::setEstimatedElements(void) { if (!SymbolTable::Exist(EstimParams->name)) { - string msg = "Unknown symbol : "+EstimParams->name; + string msg = "Unknown symbol: "+EstimParams->name; error(msg.c_str()); } if (SymbolTable::isReferenced(EstimParams->name) == eNotReferenced) @@ -178,6 +178,110 @@ void ComputingTasks::setEstimatedElements(void) EstimParams->p3 << " " << EstimParams->p4 << " " << EstimParams->jscale << "];\n"; EstimParams->clear(); } +//------------------------------------------------------------------------------ +void ComputingTasks::setEstimatedInitElements(void) +{ + if (!SymbolTable::Exist(EstimParams->name)) + { + string msg = "Unknown symbol: "+EstimParams->name; + error(msg.c_str()); + } + if (SymbolTable::isReferenced(EstimParams->name) == eNotReferenced) + { + return; + } + if ((EstimParams->init_val).size() == 0) + { + EstimParams->init_val = EstimParams->mean; + } + if (EstimParams->type < 3) + { + if( SymbolTable::getType(EstimParams->name) == eExogenous) + { + *output << "tmp1 = find(estim_params_.var_exo(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ");\n"; + *output << "estim_params_.var_exo(tmp1,2) = " << EstimParams->init_val << ";\n"; + } + else if ( SymbolTable::getType(EstimParams->name) == eEndogenous) + { + *output << "tmp1 = find(estim_params_.var_endo(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ");\n"; + *output << "estim_params_.var_endo(tmp1,2) = " << EstimParams->init_val << ";\n"; + } + else if ( SymbolTable::getType(EstimParams->name) == eParameter) + { + *output << "tmp1 = find(estim_params_.param_vals(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ");\n"; + *output << "estim_params_.param_vals(tmp1,2) = " << EstimParams->init_val << ";\n"; + } + } + else + { + if( SymbolTable::getType(EstimParams->name) == eExogenous) + { + *output << "tmp1 = find((estim_params_.corrx(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ")) & (estim_params_.corrx(:,2)==SymbolTable::getID(EstimParams->name2)+1);\n"; + *output << "estim_params_.corrx(tmp1,3) = " << EstimParams->init_val << ";\n"; + } + else if ( SymbolTable::getType(EstimParams->name) == eEndogenous) + { + *output << "tmp1 = find((estim_params_.corrn(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ")) & (estim_params_.corrn(:,2)==" << SymbolTable::getID(EstimParams->name2)+1 << ";\n"; + *output << "estim_params_.corrx(tmp1,3) = " << EstimParams->init_val << ";\n"; + } + } + EstimParams->clear(); +} +//------------------------------------------------------------------------------ +void ComputingTasks::setEstimatedBoundsElements(void) +{ + if (!SymbolTable::Exist(EstimParams->name)) + { + string msg = "Unknown symbol: "+EstimParams->name; + error(msg.c_str()); + } + if (SymbolTable::isReferenced(EstimParams->name) == eNotReferenced) + { + return; + } + if ((EstimParams->init_val).size() == 0) + { + EstimParams->init_val = EstimParams->mean; + } + if (EstimParams->type < 3) + { + if( SymbolTable::getType(EstimParams->name) == eExogenous) + { + *output << "tmp1 = find(estim_params_.var_exo(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ");\n"; + *output << "estim_params_.var_exo(tmp1,3) = " << EstimParams->low_bound << ";\n"; + *output << "estim_params_.var_exo(tmp1,4) = " << EstimParams->up_bound << ";\n"; + } + else if ( SymbolTable::getType(EstimParams->name) == eEndogenous) + { + *output << "tmp1 = find(estim_params_.var_endo(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ");\n"; + *output << "estim_params_.var_endo(tmp1,3) = " << EstimParams->low_bound << ";\n"; + *output << "estim_params_.var_endo(tmp1,4) = " << EstimParams->up_bound << ";\n"; + } + else if ( SymbolTable::getType(EstimParams->name) == eParameter) + { + *output << "tmp1 = find(estim_params_.param_vals(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ");\n"; + *output << "estim_params_.param_vals(tmp1,3) = " << EstimParams->low_bound << ";\n"; + *output << "estim_params_.param_vals(tmp1,4) = " << EstimParams->up_bound << ";\n"; + } + } + else + { + if( SymbolTable::getType(EstimParams->name) == eExogenous) + { + *output << "tmp1 = find((estim_params_.corrx(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ")) & (estim_params_.corrx(:,2)==SymbolTable::getID(EstimParams->name2)+1);\n"; + *output << "estim_params_.corrx(tmp1,4) = " << EstimParams->low_bound << ";\n"; + *output << "estim_params_.corrx(tmp1,5) = " << EstimParams->up_bound << ";\n"; + } + else if ( SymbolTable::getType(EstimParams->name) == eEndogenous) + { + *output << "tmp1 = find((estim_params_.corrn(:,1)==" << SymbolTable::getID(EstimParams->name)+1 << ")) & (estim_params_.corrn(:,2)==" << SymbolTable::getID(EstimParams->name2)+1 << ";\n"; + *output << "estim_params_.corrx(tmp1,4) = " << EstimParams->low_bound << ";\n"; + *output << "estim_params_.corrx(tmp1,5) = " << EstimParams->up_bound << ";\n"; + } + } + EstimParams->clear(); +} +//----------------------------------------------------------------------- void ComputingTasks::set_trend_element (string name, string expression) { //Testing if symbol exists diff --git a/parser.src/DynareBison.yy b/parser.src/DynareBison.yy index 7fb45fc9e..fa173940d 100644 --- a/parser.src/DynareBison.yy +++ b/parser.src/DynareBison.yy @@ -643,7 +643,9 @@ ; estimated_init_list : estimated_init_list estimated_init_elem + {_parser->set_estimated_init_elements();} | estimated_init_elem + {_parser->set_estimated_init_elements();} ; estimated_init_elem : STDERR NAME COMMA value ';' @@ -668,7 +670,9 @@ ; estimated_bounds_list : estimated_bounds_list estimated_bounds_elem + {_parser->set_estimated_bounds_elements();} | estimated_bounds_elem + {_parser->set_estimated_bounds_elements();} ; estimated_bounds_elem : STDERR NAME COMMA value COMMA value ';' diff --git a/parser.src/DynareParser.cc b/parser.src/DynareParser.cc index 4264a9c9b..827c0bd40 100644 --- a/parser.src/DynareParser.cc +++ b/parser.src/DynareParser.cc @@ -463,6 +463,14 @@ void dynare::parser::set_estimated_elements(void) { computing_tasks.setEstimatedElements(); } +void dynare::parser::set_estimated_init_elements(void) +{ + computing_tasks.setEstimatedInitElements(); +} +void dynare::parser::set_estimated_bounds_elements(void) +{ + computing_tasks.setEstimatedBoundsElements(); +} void dynare::parser::set_unit_root_vars() { tmp_symbol_table.set("options_.unit_root_vars"); diff --git a/parser.src/include/ComputingTasks.h b/parser.src/include/ComputingTasks.h index 45b5059b9..8864e255c 100644 --- a/parser.src/include/ComputingTasks.h +++ b/parser.src/include/ComputingTasks.h @@ -98,6 +98,8 @@ class ComputingTasks void setOptimOptions(std::string str1, std::string str2, int task); /*! Prints estimated elements */ void setEstimatedElements(void); + void setEstimatedInitElements(void); + void setEstimatedBoundsElements(void); void setEstimationStandardError(void); void set_trend_element(std::string, std::string); diff --git a/parser.src/include/DynareParser.h b/parser.src/include/DynareParser.h index 6b4b96131..8a9592431 100644 --- a/parser.src/include/DynareParser.h +++ b/parser.src/include/DynareParser.h @@ -223,6 +223,8 @@ namespace dynare void estimation_init(void); /*! Writes instructions for estimated elements */ void set_estimated_elements(void); + void set_estimated_init_elements(void); + void set_estimated_bounds_elements(void); /*! Runs estimation process */ void run_estimation(void); /*! Prints optimization options */