2008-02-03 11:28:36 +01:00
/*
2017-02-09 12:46:37 +01:00
* Copyright ( C ) 2003 - 2017 Dynare Team
2008-02-03 11:28:36 +01:00
*
* This file is part of Dynare .
*
* Dynare is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* Dynare is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with Dynare . If not , see < http : //www.gnu.org/licenses/>.
*/
2008-06-28 13:20:45 +02:00
# include <cstdlib>
2009-04-28 18:21:39 +02:00
# include <cassert>
2008-02-03 11:28:36 +01:00
# include <iostream>
# include <sstream>
using namespace std ;
# include "ComputingTasks.hh"
# include "Statement.hh"
2011-12-19 17:32:02 +01:00
# include <boost/algorithm/string/trim.hpp>
# include <boost/algorithm/string/split.hpp>
# include <boost/lexical_cast.hpp>
# include <boost/tokenizer.hpp>
2009-09-02 15:36:56 +02:00
SteadyStatement : : SteadyStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
2008-02-03 11:28:36 +01:00
{
}
2009-06-30 17:07:09 +02:00
void
2012-01-23 16:52:27 +01:00
SteadyStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2009-06-30 17:07:09 +02:00
{
2010-01-08 12:06:25 +01:00
mod_file_struct . steady_present = true ;
2009-06-30 17:07:09 +02:00
}
2008-02-03 11:28:36 +01:00
void
2015-05-28 11:42:12 +02:00
SteadyStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
options_list . writeOutput ( output ) ;
2014-12-15 11:44:27 +01:00
output < < " steady; " < < endl ;
2008-02-03 11:28:36 +01:00
}
2017-02-08 18:29:57 +01:00
void
SteadyStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" steady \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2008-02-03 11:28:36 +01:00
CheckStatement : : CheckStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
{
}
void
2015-05-28 11:42:12 +02:00
CheckStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
options_list . writeOutput ( output ) ;
2013-01-15 16:45:15 +01:00
output < < " oo_.dr.eigval = check(M_,options_,oo_); " < < endl ;
2008-02-03 11:28:36 +01:00
}
void
2012-01-23 16:52:27 +01:00
CheckStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2008-02-03 11:28:36 +01:00
{
mod_file_struct . check_present = true ;
}
2017-02-08 18:29:57 +01:00
void
CheckStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" check \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2008-08-29 14:31:25 +02:00
ModelInfoStatement : : ModelInfoStatement ( const OptionsList & options_list_arg ) :
2008-08-25 17:06:36 +02:00
options_list ( options_list_arg )
{
}
2009-12-16 18:13:23 +01:00
void
2012-01-23 16:52:27 +01:00
ModelInfoStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2008-08-25 17:06:36 +02:00
{
2008-08-28 15:20:34 +02:00
//mod_file_struct.model_info_present = true;
2008-08-25 17:06:36 +02:00
}
2009-12-16 18:13:23 +01:00
void
2015-05-28 11:42:12 +02:00
ModelInfoStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-08-25 17:06:36 +02:00
{
options_list . writeOutput ( output ) ;
2014-12-15 11:44:27 +01:00
output < < " model_info(); " < < endl ;
2008-08-25 17:06:36 +02:00
}
2017-02-08 18:29:57 +01:00
void
ModelInfoStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" model_info \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2009-09-02 18:44:15 +02:00
SimulStatement : : SimulStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
2008-02-03 11:28:36 +01:00
{
}
void
2012-01-23 16:52:27 +01:00
SimulStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2008-02-03 11:28:36 +01:00
{
2014-04-09 17:57:17 +02:00
mod_file_struct . perfect_foresight_solver_present = true ;
2008-02-03 11:28:36 +01:00
}
void
2015-05-28 11:42:12 +02:00
SimulStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
options_list . writeOutput ( output ) ;
2014-04-09 17:57:17 +02:00
output < < " perfect_foresight_setup; " < < endl
< < " perfect_foresight_solver; " < < endl ;
}
2017-02-08 18:29:57 +01:00
void
SimulStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" simul \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2014-04-09 17:57:17 +02:00
PerfectForesightSetupStatement : : PerfectForesightSetupStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
{
}
void
2015-05-28 11:42:12 +02:00
PerfectForesightSetupStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2014-04-09 17:57:17 +02:00
{
options_list . writeOutput ( output ) ;
output < < " perfect_foresight_setup; " < < endl ;
}
2017-02-08 18:29:57 +01:00
void
PerfectForesightSetupStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" perfect_foresight_setup \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2014-04-09 17:57:17 +02:00
PerfectForesightSolverStatement : : PerfectForesightSolverStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
{
}
void
PerfectForesightSolverStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
mod_file_struct . perfect_foresight_solver_present = true ;
2015-06-04 14:16:52 +02:00
// Fill in option_occbin of mod_file_struct
2015-10-13 14:37:50 +02:00
if ( options_list . num_options . find ( " occbin " ) ! = options_list . num_options . end ( ) )
2015-06-04 14:16:52 +02:00
mod_file_struct . occbin_option = true ;
2014-04-09 17:57:17 +02:00
}
void
2015-05-28 11:42:12 +02:00
PerfectForesightSolverStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2014-04-09 17:57:17 +02:00
{
options_list . writeOutput ( output ) ;
output < < " perfect_foresight_solver; " < < endl ;
2008-02-03 11:28:36 +01:00
}
2017-02-08 18:29:57 +01:00
void
PerfectForesightSolverStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" perfect_foresight_solver \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2015-10-14 11:02:35 +02:00
PriorPosteriorFunctionStatement : : PriorPosteriorFunctionStatement ( const bool prior_func_arg ,
const OptionsList & options_list_arg ) :
prior_func ( prior_func_arg ) ,
2015-10-13 17:16:10 +02:00
options_list ( options_list_arg )
{
}
void
PriorPosteriorFunctionStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
OptionsList : : string_options_t : : const_iterator it2 = options_list . string_options . find ( " function " ) ;
if ( it2 = = options_list . string_options . end ( ) | | it2 - > second . empty ( ) )
2017-06-01 19:58:32 +02:00
{
cerr < < " ERROR: both the prior_function and posterior_function commands require the 'function' argument "
< < endl ;
exit ( EXIT_FAILURE ) ;
}
2015-10-13 17:16:10 +02:00
}
void
PriorPosteriorFunctionStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
2015-10-13 17:40:15 +02:00
options_list . writeOutput ( output ) ;
2015-10-13 17:16:10 +02:00
string type = " posterior " ;
2015-10-14 11:02:35 +02:00
if ( prior_func )
2017-06-01 19:58:32 +02:00
type = " prior " ;
2015-10-13 17:16:10 +02:00
output < < " oo_ = execute_prior_posterior_function( "
2015-10-13 17:40:15 +02:00
< < " ' " < < options_list . string_options . find ( " function " ) - > second < < " ', "
2015-10-13 17:16:10 +02:00
< < " M_, options_, oo_, estim_params_, bayestopt_, dataset_, dataset_info, "
< < " ' " < < type < < " '); " < < endl ;
}
2017-02-08 18:29:57 +01:00
void
PriorPosteriorFunctionStatement : : writeJsonOutput ( ostream & output ) const
{
string type = " posterior " ;
if ( prior_func )
2017-06-14 07:01:31 +02:00
type = " prior " ;
2017-02-08 18:29:57 +01:00
output < < " { \" statementName \" : \" prior_posterior_function \" , \" type \" : \" " < < type < < " \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2016-11-03 12:56:54 +01:00
VarModelStatement : : VarModelStatement ( const SymbolList & symbol_list_arg ,
const OptionsList & options_list_arg ,
2017-05-04 15:50:33 +02:00
const string & name_arg ) :
2016-10-26 18:19:33 +02:00
symbol_list ( symbol_list_arg ) ,
options_list ( options_list_arg ) ,
2017-05-04 15:50:33 +02:00
name ( name_arg )
2016-10-26 18:19:33 +02:00
{
}
2016-11-18 16:52:13 +01:00
void
2016-11-25 17:15:13 +01:00
VarModelStatement : : getVarModelNameAndVarList ( map < string , pair < SymbolList , int > > & var_model_info )
2016-11-18 16:52:13 +01:00
{
2016-11-25 17:15:13 +01:00
var_model_info [ name ] = make_pair ( symbol_list , atoi ( options_list . num_options . find ( " var.order " ) - > second . c_str ( ) ) ) ;
2016-11-18 16:52:13 +01:00
}
2016-10-26 18:19:33 +02:00
void
2016-11-03 12:56:54 +01:00
VarModelStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2016-10-26 18:19:33 +02:00
{
2016-11-03 12:56:54 +01:00
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " var.order " ) ;
2016-10-26 18:19:33 +02:00
if ( it = = options_list . num_options . end ( ) )
{
2016-11-03 12:56:54 +01:00
cerr < < " ERROR: You must provide the order option to the var_model statement. " < < endl ;
2016-10-26 18:19:33 +02:00
exit ( EXIT_FAILURE ) ;
}
2016-11-03 12:56:54 +01:00
if ( name . empty ( ) )
2016-10-26 18:19:33 +02:00
{
2016-11-03 12:56:54 +01:00
cerr < < " ERROR: You must provide the model_name option to the var_model statement. " < < endl ;
2016-10-26 18:19:33 +02:00
exit ( EXIT_FAILURE ) ;
}
}
void
2016-11-03 12:56:54 +01:00
VarModelStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2016-10-26 18:19:33 +02:00
{
options_list . writeOutput ( output ) ;
2016-11-03 12:56:54 +01:00
symbol_list . writeOutput ( " options_.var.var_list_ " , output ) ;
output < < " M_.var. " < < name < < " = options_.var; " < < endl
2016-11-21 18:00:46 +01:00
< < " clear options_.var; " < < endl ;
}
void
VarModelStatement : : createVarModelMFunction ( ostream & output , const map < string , set < int > > & var_expectation_functions_to_write ) const
{
if ( var_expectation_functions_to_write . find ( name ) = = var_expectation_functions_to_write . end ( ) )
return ;
stringstream ss ;
set < int > horizons = var_expectation_functions_to_write . find ( name ) - > second ;
for ( set < int > : : const_iterator it = horizons . begin ( ) ; it ! = horizons . end ( ) ; it + + )
2017-05-04 16:50:19 +02:00
{
if ( it ! = horizons . begin ( ) )
ss < < " " ;
ss < < * it ;
}
output < < " writeVarExpectationFunction(' " < < name < < " ', " ;
if ( horizons . size ( ) > 1 )
output < < " [ " ;
output < < ss . rdbuf ( ) ;
if ( horizons . size ( ) > 1 )
output < < " ] " ;
output < < " ); " < < endl ;
2016-10-26 18:19:33 +02:00
}
2017-05-11 12:14:45 +02:00
VarEstimationStatement : : VarEstimationStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
2017-05-10 17:21:38 +02:00
{
}
2017-05-11 12:14:45 +02:00
void
VarEstimationStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
OptionsList : : string_options_t : : const_iterator it = options_list . string_options . find ( " var_estimation.model_name " ) ;
if ( it = = options_list . string_options . end ( ) )
{
cerr < < " ERROR: You must provide the model name to the var_estimation statement. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
2017-05-10 17:21:38 +02:00
void
VarEstimationStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
2017-05-11 12:14:45 +02:00
options_list . writeOutput ( output ) ;
output < < " oo_ = var_estimation(M_, options_, oo_); " < < endl ;
2017-05-10 17:21:38 +02:00
}
2017-05-04 18:06:50 +02:00
VarRestrictionsStatement : : VarRestrictionsStatement ( const string & var_model_name_arg ,
2017-05-18 17:50:58 +02:00
const map < string , vector < string > > & var_map_arg ,
2017-05-04 18:06:50 +02:00
const map < int , map < int , SymbolList > > & exclusion_restrictions_arg ,
const equation_restrictions_t & equation_restrictions_arg ,
const crossequation_restrictions_t & crossequation_restrictions_arg ,
const map < pair < int , int > , double > & covariance_number_restriction_arg ,
2017-05-16 10:09:48 +02:00
const map < pair < int , int > , pair < int , int > > & covariance_pair_restriction_arg ,
2017-06-01 19:58:32 +02:00
const SymbolTable & symbol_table_arg ) :
2017-05-04 18:06:50 +02:00
var_model_name ( var_model_name_arg ) ,
2017-05-18 17:50:58 +02:00
var_map ( var_map_arg ) ,
2017-05-04 18:06:50 +02:00
exclusion_restrictions ( exclusion_restrictions_arg ) ,
equation_restrictions ( equation_restrictions_arg ) ,
crossequation_restrictions ( crossequation_restrictions_arg ) ,
covariance_number_restriction ( covariance_number_restriction_arg ) ,
2017-05-16 10:09:48 +02:00
covariance_pair_restriction ( covariance_pair_restriction_arg ) ,
symbol_table ( symbol_table_arg )
2017-05-04 18:06:50 +02:00
{
}
2017-05-18 17:50:58 +02:00
int
VarRestrictionsStatement : : findIdxInVector ( const vector < string > & vecvars , const string & var ) const
{
int idx = 0 ;
bool setflag = false ;
for ( vector < string > : : const_iterator itvs = vecvars . begin ( ) ;
itvs ! = vecvars . end ( ) ; itvs + + , idx + + )
if ( * itvs = = var )
{
setflag = true ;
break ;
}
if ( ! setflag )
{
cerr < < " ERROR: you are imposing an exclusion restriction on an equation or variable "
< < var < < " that is not contained in VAR " < < var_model_name ;
exit ( EXIT_FAILURE ) ;
}
return idx ;
}
2017-05-04 18:06:50 +02:00
void
VarRestrictionsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
2017-05-18 17:50:58 +02:00
map < string , vector < string > > : : const_iterator itvs = var_map . find ( var_model_name ) ;
if ( itvs = = var_map . end ( ) )
{
cerr < < " ERROR: you are imposing restrictions on a VAR named " < < var_model_name
< < " but this VAR has not been declared via thevar_model statement. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
vector < string > vars = itvs - > second ;
2017-06-01 19:58:32 +02:00
string Mstr ( " M_.var. " + var_model_name + " .restrictions. " ) ;
2017-05-16 10:09:48 +02:00
int nrestrictions = 0 ;
2017-05-04 18:06:50 +02:00
// Exclusion Restrictions
int idx = 1 ;
for ( map < int , map < int , SymbolList > > : : const_iterator it = exclusion_restrictions . begin ( ) ;
it ! = exclusion_restrictions . end ( ) ; it + + , idx + + )
{
2017-05-11 17:36:56 +02:00
output < < Mstr < < " exclusion_restrictions{ " < < idx < < " }.lag = "
2017-05-04 18:06:50 +02:00
< < it - > first < < " ; " < < endl
2017-05-11 17:36:56 +02:00
< < Mstr < < " exclusion_restrictions{ " < < idx < < " }.restrictions = [ " ;
2017-05-04 18:06:50 +02:00
for ( map < int , SymbolList > : : const_iterator it1 = it - > second . begin ( ) ;
it1 ! = it - > second . end ( ) ; it1 + + )
{
if ( it1 ! = it - > second . begin ( ) )
output < < " " ;
2017-05-18 17:50:58 +02:00
output < < " struct('eq', " < < findIdxInVector ( vars , symbol_table . getName ( it1 - > first ) ) + 1
< < " , 'vars', [ " ;
vector < string > excvars = it1 - > second . getSymbols ( ) ;
for ( vector < string > : : const_iterator itvs1 = excvars . begin ( ) ;
itvs1 ! = excvars . end ( ) ; itvs1 + + )
output < < findIdxInVector ( vars , * itvs1 ) + 1 < < " " ;
output < < " ]) " ;
2017-05-16 10:09:48 +02:00
nrestrictions + = it1 - > second . getSize ( ) ;
2017-05-04 18:06:50 +02:00
}
output < < " ]; " < < endl ;
}
// Equation Restrictions
idx = 1 ;
for ( equation_restrictions_t : : const_iterator it = equation_restrictions . begin ( ) ;
2017-05-16 10:09:48 +02:00
it ! = equation_restrictions . end ( ) ; it + + , idx + + , nrestrictions + + )
2017-05-04 18:06:50 +02:00
{
2017-05-16 10:09:48 +02:00
output < < Mstr < < " equation_restriction{ " < < idx < < " }.eq = ' "
< < symbol_table . getName ( it - > first ) < < " '; " < < endl
2017-05-11 17:36:56 +02:00
< < Mstr < < " equation_restriction{ " < < idx < < " }.val = "
2017-05-04 18:06:50 +02:00
< < it - > second . second < < " ; " < < endl ;
var_restriction_eq_crosseq_t ls = it - > second . first . first ;
2017-05-16 10:09:48 +02:00
output < < Mstr < < " equation_restriction{ " < < idx < < " }.ls = ' "
< < symbol_table . getName ( ls . first . first ) < < " '; " < < endl
2017-05-11 17:36:56 +02:00
< < Mstr < < " equation_restriction{ " < < idx < < " }.lslag = "
2017-05-04 18:06:50 +02:00
< < ls . first . second . second < < " ; " < < endl
2017-05-11 17:36:56 +02:00
< < Mstr < < " equation_restriction{ " < < idx < < " }.lscoeff = " ;
2017-05-04 18:06:50 +02:00
ls . second - > writeOutput ( output ) ;
output < < " ; " < < endl ;
var_restriction_eq_crosseq_t rs = it - > second . first . second ;
if ( rs . first . first > = 0 )
{
2017-05-16 10:09:48 +02:00
output < < Mstr < < " equation_restriction{ " < < idx < < " }.rs = ' "
< < symbol_table . getName ( rs . first . first ) < < " '; " < < endl
2017-05-11 17:36:56 +02:00
< < Mstr < < " equation_restriction{ " < < idx < < " }.rslag = "
2017-05-04 18:06:50 +02:00
< < rs . first . second . second < < " ; " < < endl
2017-05-11 17:36:56 +02:00
< < Mstr < < " equation_restriction{ " < < idx < < " }.rscoeff = " ;
2017-05-04 18:06:50 +02:00
rs . second - > writeOutput ( output ) ;
output < < " ; " < < endl ;
}
}
// Cross Equation Restrictions
idx = 1 ;
for ( crossequation_restrictions_t : : const_iterator it = crossequation_restrictions . begin ( ) ;
2017-05-16 10:09:48 +02:00
it ! = crossequation_restrictions . end ( ) ; it + + , idx + + , nrestrictions + + )
2017-05-04 18:06:50 +02:00
{
2017-05-19 14:20:26 +02:00
output < < Mstr < < " crossequation_restriction{ " < < idx < < " }.val = "
< < it - > second < < " ; " < < endl ;
2017-05-04 18:06:50 +02:00
2017-05-19 14:20:26 +02:00
var_restriction_eq_crosseq_t ls = it - > first . first ;
2017-05-18 17:50:58 +02:00
output < < Mstr < < " crossequation_restriction{ " < < idx < < " }.lseq = "
< < findIdxInVector ( vars , symbol_table . getName ( ls . first . first ) ) + 1 < < " ; " < < endl
< < Mstr < < " crossequation_restriction{ " < < idx < < " }.lsvar = "
< < findIdxInVector ( vars , symbol_table . getName ( ls . first . second . first ) ) + 1 < < " ; " < < endl
2017-05-11 17:36:56 +02:00
< < Mstr < < " crossequation_restriction{ " < < idx < < " }.lslag = "
2017-05-04 18:06:50 +02:00
< < ls . first . second . second < < " ; " < < endl
2017-05-11 17:36:56 +02:00
< < Mstr < < " crossequation_restriction{ " < < idx < < " }.lscoeff = " ;
2017-05-04 18:06:50 +02:00
ls . second - > writeOutput ( output ) ;
output < < " ; " < < endl ;
2017-05-19 14:20:26 +02:00
var_restriction_eq_crosseq_t rs = it - > first . second ;
2017-05-04 18:06:50 +02:00
if ( rs . first . first > = 0 )
{
2017-05-18 17:50:58 +02:00
output < < Mstr < < " crossequation_restriction{ " < < idx < < " }.rseq = "
< < findIdxInVector ( vars , symbol_table . getName ( rs . first . first ) ) + 1 < < " ; " < < endl
< < Mstr < < " crossequation_restriction{ " < < idx < < " }.rsvar = "
< < findIdxInVector ( vars , symbol_table . getName ( rs . first . second . first ) ) + 1 < < " ; " < < endl
2017-05-11 17:36:56 +02:00
< < Mstr < < " crossequation_restriction{ " < < idx < < " }.rslag = "
2017-05-04 18:06:50 +02:00
< < rs . first . second . second < < " ; " < < endl
2017-05-11 17:36:56 +02:00
< < Mstr < < " crossequation_restriction{ " < < idx < < " }.rscoeff = " ;
2017-05-04 18:06:50 +02:00
rs . second - > writeOutput ( output ) ;
output < < " ; " < < endl ;
}
}
// Covariance Const Restrictions
idx = 1 ;
for ( map < pair < int , int > , double > : : const_iterator it = covariance_number_restriction . begin ( ) ;
it ! = covariance_number_restriction . end ( ) ; it + + , idx + + )
2017-05-16 10:09:48 +02:00
output < < Mstr < < " covariance_const_restriction{ " < < idx < < " }.var1 = ' "
< < symbol_table . getName ( it - > first . first ) < < " '; " < < endl
< < Mstr < < " covariance_const_restriction{ " < < idx < < " }.var2 = ' "
< < symbol_table . getName ( it - > first . second ) < < " '; " < < endl
2017-05-11 17:36:56 +02:00
< < Mstr < < " covariance_const_restriction{ " < < idx < < " }.val = "
2017-05-04 18:06:50 +02:00
< < it - > second < < " ; " < < endl ;
// Covariance Pair Restrictions
idx = 1 ;
for ( map < pair < int , int > , pair < int , int > > : : const_iterator it = covariance_pair_restriction . begin ( ) ;
it ! = covariance_pair_restriction . end ( ) ; it + + , idx + + )
2017-05-16 10:09:48 +02:00
output < < Mstr < < " covariance_pair_restriction{ " < < idx < < " }.var11 = ' "
< < symbol_table . getName ( it - > first . first ) < < " '; " < < endl
< < Mstr < < " covariance_pair_restriction{ " < < idx < < " }.var12 = ' "
< < symbol_table . getName ( it - > first . second ) < < " '; " < < endl
< < Mstr < < " covariance_pair_restriction{ " < < idx < < " }.var21 = ' "
< < symbol_table . getName ( it - > second . first ) < < " '; " < < endl
< < Mstr < < " covariance_pair_restriction{ " < < idx < < " }.var22 = ' "
< < symbol_table . getName ( it - > second . second ) < < " '; " < < endl ;
output < < Mstr < < " N = " < < nrestrictions < < " ; " < < endl ;
2017-05-04 18:06:50 +02:00
}
2008-04-07 15:14:40 +02:00
StochSimulStatement : : StochSimulStatement ( const SymbolList & symbol_list_arg ,
2009-09-02 18:44:15 +02:00
const OptionsList & options_list_arg ) :
2008-04-07 15:14:40 +02:00
symbol_list ( symbol_list_arg ) ,
2009-09-02 18:44:15 +02:00
options_list ( options_list_arg )
2008-02-03 11:28:36 +01:00
{
}
void
2012-01-23 16:52:27 +01:00
StochSimulStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2008-02-03 11:28:36 +01:00
{
2008-09-29 12:16:13 +02:00
mod_file_struct . stoch_simul_present = true ;
2008-02-03 11:28:36 +01:00
// Fill in option_order of mod_file_struct
2010-09-16 19:00:48 +02:00
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " order " ) ;
2008-02-03 11:28:36 +01:00
if ( it ! = options_list . num_options . end ( ) )
2009-12-16 18:13:23 +01:00
mod_file_struct . order_option = max ( mod_file_struct . order_option , atoi ( it - > second . c_str ( ) ) ) ;
2008-11-04 12:00:54 +01:00
2009-10-20 18:55:31 +02:00
// Fill in mod_file_struct.partial_information
it = options_list . num_options . find ( " partial_information " ) ;
if ( it ! = options_list . num_options . end ( ) & & it - > second = = " 1 " )
mod_file_struct . partial_information = true ;
2009-12-09 12:50:58 +01:00
// Option k_order_solver (implicit when order >= 3)
it = options_list . num_options . find ( " k_order_solver " ) ;
if ( ( it ! = options_list . num_options . end ( ) & & it - > second = = " 1 " )
| | mod_file_struct . order_option > = 3 )
mod_file_struct . k_order_solver = true ;
2010-05-31 18:38:49 +02:00
2015-08-03 17:51:45 +02:00
it = options_list . num_options . find ( " hp_filter " ) ;
OptionsList : : num_options_t : : const_iterator it1 = options_list . num_options . find ( " bandpass.indicator " ) ;
OptionsList : : num_options_t : : const_iterator it2 = options_list . num_options . find ( " one_sided_hp_filter " ) ;
2017-06-01 19:58:32 +02:00
if ( ( it ! = options_list . num_options . end ( ) & & it1 ! = options_list . num_options . end ( ) )
| | ( it ! = options_list . num_options . end ( ) & & it2 ! = options_list . num_options . end ( ) )
| | ( it1 ! = options_list . num_options . end ( ) & & it2 ! = options_list . num_options . end ( ) ) )
{
cerr < < " ERROR: stoch_simul: can only use one of hp, one-sided hp, and bandpass filters "
< < endl ;
exit ( EXIT_FAILURE ) ;
}
2008-02-03 11:28:36 +01:00
}
void
2015-05-28 11:42:12 +02:00
StochSimulStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
2015-02-10 03:39:18 +01:00
// Ensure that order 3 implies k_order (#844)
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " order " ) ;
OptionsList : : num_options_t : : const_iterator it1 = options_list . num_options . find ( " k_order_solver " ) ;
if ( ( it1 ! = options_list . num_options . end ( ) & & it1 - > second = = " 1 " )
| | ( it ! = options_list . num_options . end ( ) & & atoi ( it - > second . c_str ( ) ) > = 3 ) )
output < < " options_.k_order_solver = 1; " < < endl ;
2008-02-03 11:28:36 +01:00
options_list . writeOutput ( output ) ;
2008-04-07 15:14:40 +02:00
symbol_list . writeOutput ( " var_list_ " , output ) ;
2009-09-02 18:44:15 +02:00
output < < " info = stoch_simul(var_list_); " < < endl ;
2008-02-03 11:28:36 +01:00
}
2017-02-08 18:29:57 +01:00
void
StochSimulStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" stoch_simul \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2008-05-01 14:04:48 +02:00
ForecastStatement : : ForecastStatement ( const SymbolList & symbol_list_arg ,
2009-01-23 11:59:37 +01:00
const OptionsList & options_list_arg ) :
2008-05-01 14:04:48 +02:00
symbol_list ( symbol_list_arg ) ,
options_list ( options_list_arg )
{
}
void
2015-05-28 11:42:12 +02:00
ForecastStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-05-01 14:04:48 +02:00
{
options_list . writeOutput ( output ) ;
symbol_list . writeOutput ( " var_list_ " , output ) ;
2015-11-24 20:55:33 +01:00
output < < " [oo_.forecast,info] = dyn_forecast(var_list_,M_,options_,oo_,'simul'); " < < endl ;
2008-05-01 14:04:48 +02:00
}
2017-02-08 18:29:57 +01:00
void
ForecastStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" forecast \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2014-03-08 10:05:25 +01:00
RamseyModelStatement : : RamseyModelStatement ( const SymbolList & symbol_list_arg ,
2017-06-01 19:58:32 +02:00
const OptionsList & options_list_arg ) :
2014-03-08 10:05:25 +01:00
symbol_list ( symbol_list_arg ) ,
options_list ( options_list_arg )
{
}
void
RamseyModelStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
mod_file_struct . ramsey_model_present = true ;
/* Fill in option_order of mod_file_struct
Since ramsey model needs one further order of derivation ( for example , for 1 st order
approximation , it needs 2 nd derivatives ) , we add 1 to the order declared by user */
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " order " ) ;
if ( it ! = options_list . num_options . end ( ) )
{
int order = atoi ( it - > second . c_str ( ) ) ;
if ( order > 2 )
{
cerr < < " ERROR: ramsey_model: order > 2 is not implemented " < < endl ;
exit ( EXIT_FAILURE ) ;
}
mod_file_struct . order_option = max ( mod_file_struct . order_option , order + 1 ) ;
}
// Fill in mod_file_struct.partial_information
it = options_list . num_options . find ( " partial_information " ) ;
if ( it ! = options_list . num_options . end ( ) & & it - > second = = " 1 " )
mod_file_struct . partial_information = true ;
// Option k_order_solver (implicit when order >= 3)
it = options_list . num_options . find ( " k_order_solver " ) ;
if ( ( it ! = options_list . num_options . end ( ) & & it - > second = = " 1 " )
| | mod_file_struct . order_option > = 3 )
mod_file_struct . k_order_solver = true ;
}
void
2015-05-28 11:42:12 +02:00
RamseyModelStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2014-03-08 10:05:25 +01:00
{
2014-03-09 09:52:44 +01:00
// options_.ramsey_policy indicates that a Ramsey model is present in the *.mod file
// this affects the computation of the steady state that uses a special algorithm
// It should probably rather be a M_ field, but we leave it in options_ for historical reason
2014-09-28 10:05:22 +02:00
2015-02-10 03:39:18 +01:00
// Ensure that order 3 implies k_order (#844)
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " order " ) ;
OptionsList : : num_options_t : : const_iterator it1 = options_list . num_options . find ( " k_order_solver " ) ;
if ( ( it1 ! = options_list . num_options . end ( ) & & it1 - > second = = " 1 " )
| | ( it ! = options_list . num_options . end ( ) & & atoi ( it - > second . c_str ( ) ) > = 3 ) )
output < < " options_.k_order_solver = 1; " < < endl ;
2014-12-15 11:44:27 +01:00
output < < " options_.ramsey_policy = 1; " < < endl ;
2014-09-28 10:05:22 +02:00
options_list . writeOutput ( output ) ;
2014-03-08 10:05:25 +01:00
}
2017-02-08 18:29:57 +01:00
void
RamseyModelStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" ramsey_model \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
RamseyConstraintsStatement : : RamseyConstraintsStatement ( const SymbolTable & symbol_table_arg , const constraints_t & constraints_arg ) :
symbol_table ( symbol_table_arg ) ,
2015-05-31 12:18:06 +02:00
constraints ( constraints_arg )
{
}
void
RamseyConstraintsStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
2017-06-01 19:58:32 +02:00
if ( ( mod_file_struct . ramsey_model_present ! = true ) | | ( mod_file_struct . ramsey_policy_present ! = true ) )
2015-05-31 12:18:06 +02:00
cerr < < " ramsey_constraints: can only be used with ramsey_model or ramsey_policy " < < endl ;
}
void
RamseyConstraintsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
output < < " M_.ramsey_model_constraints = { " < < endl ;
for ( RamseyConstraintsStatement : : constraints_t : : const_iterator it = constraints . begin ( ) ; it ! = constraints . end ( ) ; + + it )
{
if ( it ! = constraints . begin ( ) )
2017-06-01 19:58:32 +02:00
output < < " , " ;
2015-05-31 12:18:06 +02:00
output < < " { " < < it - > endo + 1 < < " , ' " ;
2017-06-01 19:58:32 +02:00
switch ( it - > code )
{
case oLess :
output < < ' < ' ;
break ;
case oGreater :
output < < ' > ' ;
break ;
case oLessEqual :
output < < " <= " ;
break ;
case oGreaterEqual :
output < < " >= " ;
break ;
default :
cerr < < " Ramsey constraints: this shouldn't happen. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2015-05-31 12:18:06 +02:00
output < < " ', ' " ;
it - > expression - > writeOutput ( output ) ;
output < < " '} " < < endl ;
}
output < < " }; " < < endl ;
}
2017-02-08 18:29:57 +01:00
void
RamseyConstraintsStatement : : writeJsonOutput ( ostream & output ) const
{
deriv_node_temp_terms_t tef_terms ;
output < < " { \" statementName \" : \" ramsey_constraints \" "
< < " , \" ramsey_model_constraints \" : [ " < < endl ;
for ( RamseyConstraintsStatement : : constraints_t : : const_iterator it = constraints . begin ( ) ; it ! = constraints . end ( ) ; + + it )
{
if ( it ! = constraints . begin ( ) )
2017-06-14 07:01:31 +02:00
output < < " , " ;
2017-02-08 18:29:57 +01:00
output < < " { \" constraint \" : \" " < < symbol_table . getName ( it - > endo ) < < " " ;
2017-06-14 07:01:31 +02:00
switch ( it - > code )
{
case oLess :
output < < ' < ' ;
break ;
case oGreater :
output < < ' > ' ;
break ;
case oLessEqual :
output < < " <= " ;
break ;
case oGreaterEqual :
output < < " >= " ;
break ;
default :
cerr < < " Ramsey constraints: this shouldn't happen. " < < endl ;
exit ( 1 ) ;
}
2017-02-08 18:29:57 +01:00
output < < " " ;
2017-02-20 12:18:11 +01:00
it - > expression - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " \" } " < < endl ;
}
output < < " ] " < < endl ;
output < < " } " ;
}
2015-05-31 12:18:06 +02:00
// Statement *
// RamseyConstraintsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table)
// {
// vector<string> errors;
// SymbolList new_symbol_list, new_options_symbol_list;
// OptionsList new_options_list = options_list;
// SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable();
// vector<string> symbols = symbol_list.get_symbols();
// for (vector<string>::const_iterator it = symbols.begin(); it != symbols.end(); it++)
// try
// {
// new_symbol_table->getID(*it);
// new_symbol_list.addSymbol(*it);
// }
// catch (SymbolTable::UnknownSymbolIDException &e)
// {
// errors.push_back(orig_symbol_table.getName(e.id));
// }
// catch (SymbolTable::UnknownSymbolNameException &e)
// {
// errors.push_back(e.name);
// }
// OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments");
// if (it != options_list.symbol_list_options.end())
// {
// symbols = it->second.get_symbols();
// for (vector<string>::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++)
// try
// {
// new_symbol_table->getID(*it1);
// new_options_symbol_list.addSymbol(*it1);
// }
// catch (SymbolTable::UnknownSymbolIDException &e)
// {
// errors.push_back(orig_symbol_table.getName(e.id));
// }
// catch (SymbolTable::UnknownSymbolNameException &e)
// {
// errors.push_back(e.name);
// }
// new_options_list.symbol_list_options["instruments"] = new_options_symbol_list;
// }
// if (!errors.empty())
// {
// cerr << endl
// << "ERROR: The following vars were used in the ramsey_policy statement(s) but were not declared." << endl
// << " This likely means that you declared them as varexo and that they're not in the model" << endl;
// for (vector<string>::const_iterator it = errors.begin(); it != errors.end(); it++)
// cerr << *it << endl;
// exit(EXIT_FAILURE);
// }
// return new RamseyPolicyStatement(new_symbol_list, options_list);
// }
2016-12-27 13:46:01 +01:00
RamseyPolicyStatement : : RamseyPolicyStatement ( const SymbolTable & symbol_table_arg ,
const vector < string > & ramsey_policy_list_arg ,
2008-02-03 11:28:36 +01:00
const OptionsList & options_list_arg ) :
2016-12-27 13:46:01 +01:00
symbol_table ( symbol_table_arg ) ,
ramsey_policy_list ( ramsey_policy_list_arg ) ,
2008-02-03 11:28:36 +01:00
options_list ( options_list_arg )
{
}
void
2012-01-23 16:52:27 +01:00
RamseyPolicyStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2008-02-03 11:28:36 +01:00
{
2014-03-09 09:52:44 +01:00
// ramsey_model_present indicates that the model is augmented with the FOC of the planner problem
mod_file_struct . ramsey_model_present = true ;
2017-06-01 19:58:32 +02:00
// ramsey_policy_present indicates that ramsey_policy instruction for computation of first order approximation
2014-03-09 09:52:44 +01:00
// of a stochastic Ramsey problem if present in the *.mod file
2008-09-29 12:16:13 +02:00
mod_file_struct . ramsey_policy_present = true ;
2008-02-03 11:28:36 +01:00
/* Fill in option_order of mod_file_struct
Since ramsey policy needs one further order of derivation ( for example , for 1 st order
approximation , it needs 2 nd derivatives ) , we add 1 to the order declared by user */
2010-09-16 19:00:48 +02:00
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " order " ) ;
2008-02-03 11:28:36 +01:00
if ( it ! = options_list . num_options . end ( ) )
2008-11-04 11:52:06 +01:00
{
int order = atoi ( it - > second . c_str ( ) ) ;
2013-11-22 21:09:04 +01:00
if ( order > 2 )
2008-11-04 11:52:06 +01:00
{
2013-11-22 21:09:04 +01:00
cerr < < " ERROR: ramsey_policy: order > 2 is not implemented " < < endl ;
2008-11-04 11:52:06 +01:00
exit ( EXIT_FAILURE ) ;
}
mod_file_struct . order_option = max ( mod_file_struct . order_option , order + 1 ) ;
}
2008-11-04 12:00:54 +01:00
2009-10-20 18:55:31 +02:00
// Fill in mod_file_struct.partial_information
it = options_list . num_options . find ( " partial_information " ) ;
if ( it ! = options_list . num_options . end ( ) & & it - > second = = " 1 " )
mod_file_struct . partial_information = true ;
2009-12-09 12:50:58 +01:00
// Option k_order_solver (implicit when order >= 3)
it = options_list . num_options . find ( " k_order_solver " ) ;
if ( ( it ! = options_list . num_options . end ( ) & & it - > second = = " 1 " )
| | mod_file_struct . order_option > = 3 )
mod_file_struct . k_order_solver = true ;
2008-02-03 11:28:36 +01:00
}
2016-12-27 13:46:01 +01:00
void
RamseyPolicyStatement : : checkRamseyPolicyList ( )
{
for ( vector < string > : : const_iterator it = ramsey_policy_list . begin ( ) ;
it ! = ramsey_policy_list . end ( ) ; it + + )
{
if ( ! symbol_table . exists ( * it ) )
{
cerr < < " ERROR: ramsey_policy: " < < * it < < " was not declared. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
if ( symbol_table . getType ( * it ) ! = eEndogenous )
{
cerr < < " ERROR: ramsey_policy: " < < * it < < " is not endogenous. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
}
2008-02-03 11:28:36 +01:00
void
2015-05-28 11:42:12 +02:00
RamseyPolicyStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
2015-02-10 03:39:18 +01:00
// Ensure that order 3 implies k_order (#844)
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " order " ) ;
OptionsList : : num_options_t : : const_iterator it1 = options_list . num_options . find ( " k_order_solver " ) ;
if ( ( it1 ! = options_list . num_options . end ( ) & & it1 - > second = = " 1 " )
| | ( it ! = options_list . num_options . end ( ) & & atoi ( it - > second . c_str ( ) ) > = 3 ) )
output < < " options_.k_order_solver = 1; " < < endl ;
2008-02-03 11:28:36 +01:00
options_list . writeOutput ( output ) ;
2016-12-27 13:46:01 +01:00
output < < " var_list_ = char( " ;
for ( vector < string > : : const_iterator it = ramsey_policy_list . begin ( ) ;
it ! = ramsey_policy_list . end ( ) ; + + it )
{
if ( it ! = ramsey_policy_list . begin ( ) )
output < < " , " ;
output < < " ' " < < * it < < " ' " ;
}
output < < " ); " < < endl
< < " ramsey_policy(var_list_); " < < endl ;
2008-02-03 11:28:36 +01:00
}
2017-02-08 18:29:57 +01:00
void
RamseyPolicyStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" ramsey_policy \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
2017-02-27 15:40:34 +01:00
output < < " , \" ramsey_policy_list \" : [ " ;
2017-02-08 18:29:57 +01:00
for ( vector < string > : : const_iterator it = ramsey_policy_list . begin ( ) ;
it ! = ramsey_policy_list . end ( ) ; + + it )
{
if ( it ! = ramsey_policy_list . begin ( ) )
output < < " , " ;
output < < " \" " < < * it < < " \" " ;
}
output < < " ] "
< < " } " ;
}
2011-03-13 21:19:55 +01:00
DiscretionaryPolicyStatement : : DiscretionaryPolicyStatement ( const SymbolList & symbol_list_arg ,
2017-06-01 19:58:32 +02:00
const OptionsList & options_list_arg ) :
2011-03-13 21:19:55 +01:00
symbol_list ( symbol_list_arg ) ,
options_list ( options_list_arg )
{
}
void
2012-01-23 16:52:27 +01:00
DiscretionaryPolicyStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2011-03-13 21:19:55 +01:00
{
mod_file_struct . discretionary_policy_present = true ;
2012-06-19 12:07:09 +02:00
if ( options_list . symbol_list_options . find ( " instruments " ) = = options_list . symbol_list_options . end ( ) )
{
cerr < < " ERROR: discretionary_policy: the instruments option is required. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2011-03-13 21:19:55 +01:00
/* Fill in option_order of mod_file_struct
Since discretionary policy needs one further order of derivation ( for example , for 1 st order
approximation , it needs 2 nd derivatives ) , we add 1 to the order declared by user */
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " order " ) ;
if ( it ! = options_list . num_options . end ( ) )
{
int order = atoi ( it - > second . c_str ( ) ) ;
if ( order > 1 )
{
cerr < < " ERROR: discretionary_policy: order > 1 is not yet implemented " < < endl ;
exit ( EXIT_FAILURE ) ;
}
mod_file_struct . order_option = max ( mod_file_struct . order_option , order + 1 ) ;
}
// Fill in mod_file_struct.partial_information
it = options_list . num_options . find ( " partial_information " ) ;
if ( it ! = options_list . num_options . end ( ) & & it - > second = = " 1 " )
mod_file_struct . partial_information = true ;
// Option k_order_solver (implicit when order >= 3)
it = options_list . num_options . find ( " k_order_solver " ) ;
if ( ( it ! = options_list . num_options . end ( ) & & it - > second = = " 1 " )
| | mod_file_struct . order_option > = 3 )
mod_file_struct . k_order_solver = true ;
}
void
2015-05-28 11:42:12 +02:00
DiscretionaryPolicyStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2011-03-13 21:19:55 +01:00
{
2015-02-10 03:39:18 +01:00
// Ensure that order 3 implies k_order (#844)
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " order " ) ;
OptionsList : : num_options_t : : const_iterator it1 = options_list . num_options . find ( " k_order_solver " ) ;
if ( ( it1 ! = options_list . num_options . end ( ) & & it1 - > second = = " 1 " )
| | ( it ! = options_list . num_options . end ( ) & & atoi ( it - > second . c_str ( ) ) > = 3 ) )
output < < " options_.k_order_solver = 1; " < < endl ;
2011-03-13 21:19:55 +01:00
options_list . writeOutput ( output ) ;
symbol_list . writeOutput ( " var_list_ " , output ) ;
2014-12-15 11:44:27 +01:00
output < < " discretionary_policy(var_list_); " < < endl ;
2011-03-13 21:19:55 +01:00
}
2017-02-08 18:29:57 +01:00
void
DiscretionaryPolicyStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" discretionary_policy \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2008-04-07 15:14:40 +02:00
EstimationStatement : : EstimationStatement ( const SymbolList & symbol_list_arg ,
2013-11-20 12:06:26 +01:00
const OptionsList & options_list_arg ) :
2008-04-07 15:14:40 +02:00
symbol_list ( symbol_list_arg ) ,
2013-11-20 12:06:26 +01:00
options_list ( options_list_arg )
2008-02-03 11:28:36 +01:00
{
}
void
2012-01-23 16:52:27 +01:00
EstimationStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2008-02-03 11:28:36 +01:00
{
2008-09-29 12:16:13 +02:00
mod_file_struct . estimation_present = true ;
2008-02-03 11:28:36 +01:00
// Fill in option_order of mod_file_struct
2010-09-16 19:00:48 +02:00
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " order " ) ;
2008-02-03 11:28:36 +01:00
if ( it ! = options_list . num_options . end ( ) )
2012-06-06 17:06:28 +02:00
{
int order = atoi ( it - > second . c_str ( ) ) ;
2017-06-01 19:58:32 +02:00
2012-06-06 17:06:28 +02:00
if ( order > 2 )
{
cerr < < " ERROR: order > 2 is not supported in estimation " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2017-06-01 19:58:32 +02:00
2012-06-06 17:06:28 +02:00
mod_file_struct . order_option = max ( mod_file_struct . order_option , order ) ;
}
2017-06-01 19:58:32 +02:00
2009-10-20 18:55:31 +02:00
// Fill in mod_file_struct.partial_information
it = options_list . num_options . find ( " partial_information " ) ;
if ( it ! = options_list . num_options . end ( ) & & it - > second = = " 1 " )
mod_file_struct . partial_information = true ;
2010-06-11 21:19:30 +02:00
2012-06-07 15:26:49 +02:00
// Fill in mod_file_struct.estimation_analytic_derivation
it = options_list . num_options . find ( " analytic_derivation " ) ;
if ( it ! = options_list . num_options . end ( ) & & it - > second = = " 1 " )
mod_file_struct . estimation_analytic_derivation = true ;
2010-06-11 21:19:30 +02:00
it = options_list . num_options . find ( " dsge_var " ) ;
if ( it ! = options_list . num_options . end ( ) )
2017-06-01 19:58:32 +02:00
// Fill in mod_file_struct.dsge_var_calibrated
mod_file_struct . dsge_var_calibrated = it - > second ;
2010-06-11 21:19:30 +02:00
// Fill in mod_file_struct.dsge_var_estimated
2010-09-16 19:00:48 +02:00
OptionsList : : string_options_t : : const_iterator it_str = options_list . string_options . find ( " dsge_var " ) ;
2010-06-11 21:19:30 +02:00
if ( it_str ! = options_list . string_options . end ( ) )
mod_file_struct . dsge_var_estimated = true ;
// Fill in mod_file_struct.bayesian_irf_present
it = options_list . num_options . find ( " bayesian_irf " ) ;
if ( it ! = options_list . num_options . end ( ) & & it - > second = = " 1 " )
mod_file_struct . bayesian_irf_present = true ;
it = options_list . num_options . find ( " dsge_varlag " ) ;
if ( it ! = options_list . num_options . end ( ) )
2011-02-04 16:25:38 +01:00
if ( mod_file_struct . dsge_var_calibrated . empty ( )
& & ! mod_file_struct . dsge_var_estimated )
2010-06-11 21:19:30 +02:00
{
cerr < < " ERROR: The estimation statement requires a dsge_var option to be passed "
< < " if the dsge_varlag option is passed. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2011-02-04 16:25:38 +01:00
if ( ! mod_file_struct . dsge_var_calibrated . empty ( )
& & mod_file_struct . dsge_var_estimated )
2010-06-11 21:19:30 +02:00
{
cerr < < " ERROR: An estimation statement cannot take more than one dsge_var option. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2011-12-06 15:42:57 +01:00
2017-06-01 19:58:32 +02:00
if ( options_list . string_options . find ( " datafile " ) = = options_list . string_options . end ( )
& & ! mod_file_struct . estimation_data_statement_present )
2011-12-06 15:42:57 +01:00
{
2012-03-09 11:52:32 +01:00
cerr < < " ERROR: The estimation statement requires a data file to be supplied via the datafile option. " < < endl ;
2011-12-06 15:42:57 +01:00
exit ( EXIT_FAILURE ) ;
}
2013-12-09 16:23:49 +01:00
2017-06-01 19:58:32 +02:00
if ( options_list . string_options . find ( " mode_file " ) ! = options_list . string_options . end ( )
& & mod_file_struct . estim_params_use_calib )
2013-12-09 16:23:49 +01:00
{
cerr < < " ERROR: The mode_file option of the estimation statement is incompatible with the use_calibration option of the estimated_params_init block. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2008-02-03 11:28:36 +01:00
}
void
2015-05-28 11:42:12 +02:00
EstimationStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
options_list . writeOutput ( output ) ;
2012-06-06 17:06:28 +02:00
// Special treatment for order option and particle filter
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " order " ) ;
if ( it = = options_list . num_options . end ( ) )
output < < " options_.order = 1; " < < endl ;
else if ( atoi ( it - > second . c_str ( ) ) = = 2 )
output < < " options_.particle.status = 1; " < < endl ;
2013-06-03 15:56:10 +02:00
// Do not check for the steady state in diffuse filter mode (#400)
it = options_list . num_options . find ( " diffuse_filter " ) ;
if ( it ! = options_list . num_options . end ( ) & & it - > second = = " 1 " )
output < < " options_.steadystate.nocheck = 1; " < < endl ;
2008-04-07 15:14:40 +02:00
symbol_list . writeOutput ( " var_list_ " , output ) ;
2014-12-15 11:44:27 +01:00
output < < " oo_recursive_=dynare_estimation(var_list_); " < < endl ;
2008-02-03 11:28:36 +01:00
}
2017-02-08 18:29:57 +01:00
void
EstimationStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" estimation \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2008-02-03 11:28:36 +01:00
DynareSensitivityStatement : : DynareSensitivityStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
{
}
2009-10-14 18:16:43 +02:00
void
2012-01-23 16:52:27 +01:00
DynareSensitivityStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2009-10-14 18:16:43 +02:00
{
2010-09-16 19:00:48 +02:00
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " identification " ) ;
2009-10-14 18:16:43 +02:00
if ( it ! = options_list . num_options . end ( )
& & it - > second = = " 1 " )
mod_file_struct . identification_present = true ;
}
2008-02-03 11:28:36 +01:00
void
2015-05-28 11:42:12 +02:00
DynareSensitivityStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
2009-12-16 18:13:23 +01:00
options_list . writeOutput ( output , " options_gsa " ) ;
2012-06-15 11:06:07 +02:00
/* Ensure that nograph, nodisplay and graph_format are also set in top-level
options_ .
\ todo factorize this code between identification and dynare_sensitivity ,
and provide a generic mechanism for this situation ( maybe using regexps ) */
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " nodisplay " ) ;
if ( it ! = options_list . num_options . end ( ) )
2012-06-15 15:35:00 +02:00
output < < " options_.nodisplay = " < < it - > second < < " ; " < < endl ;
2012-06-15 11:06:07 +02:00
it = options_list . num_options . find ( " nograph " ) ;
if ( it ! = options_list . num_options . end ( ) )
2012-06-15 15:35:00 +02:00
output < < " options_.nograph = " < < it - > second < < " ; " < < endl ;
2012-06-15 11:06:07 +02:00
OptionsList : : string_options_t : : const_iterator it2 = options_list . string_options . find ( " graph_format " ) ;
if ( it2 ! = options_list . string_options . end ( ) )
2012-06-15 15:35:00 +02:00
output < < " options_.graph_format = ' " < < it2 - > second < < " '; " < < endl ;
2017-06-01 19:58:32 +02:00
2008-04-05 12:52:58 +02:00
output < < " dynare_sensitivity(options_gsa); " < < endl ;
2008-02-03 11:28:36 +01:00
}
2017-02-08 18:29:57 +01:00
void
DynareSensitivityStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" dynare_sensitivity \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2015-04-01 15:17:08 +02:00
RplotStatement : : RplotStatement ( const SymbolList & symbol_list_arg ) :
symbol_list ( symbol_list_arg )
2008-02-03 11:28:36 +01:00
{
}
void
2015-05-28 11:42:12 +02:00
RplotStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
2008-04-07 15:14:40 +02:00
symbol_list . writeOutput ( " var_list_ " , output ) ;
2014-12-15 11:44:27 +01:00
output < < " rplot(var_list_); " < < endl ;
2008-02-03 11:28:36 +01:00
}
2017-02-08 18:29:57 +01:00
void
RplotStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" rplot \" " ;
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2011-11-20 20:16:02 +01:00
UnitRootVarsStatement : : UnitRootVarsStatement ( void )
{
}
void
2015-05-28 11:42:12 +02:00
UnitRootVarsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2011-11-20 20:16:02 +01:00
{
output < < " options_.diffuse_filter = 1; " < < endl
2017-06-01 19:58:32 +02:00
< < " options_.steadystate.nocheck = 1; " < < endl ;
2011-11-20 20:16:02 +01:00
}
2017-02-08 18:29:57 +01:00
void
UnitRootVarsStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" unit_root_vars \" , "
< < " \" diffuse_filter \" : 1, "
< < " \" steady_state.nocheck \" : 1} " ;
}
2008-02-03 11:28:36 +01:00
PeriodsStatement : : PeriodsStatement ( int periods_arg ) : periods ( periods_arg )
{
}
void
2015-05-28 11:42:12 +02:00
PeriodsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
output < < " options_.periods = " < < periods < < " ; " < < endl ;
}
2017-02-08 18:29:57 +01:00
void
PeriodsStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" periods \" , "
< < " \" periods \" : " < < periods < < " } " ;
}
2008-02-03 11:28:36 +01:00
DsampleStatement : : DsampleStatement ( int val1_arg ) : val1 ( val1_arg ) , val2 ( - 1 )
{
}
DsampleStatement : : DsampleStatement ( int val1_arg , int val2_arg ) : val1 ( val1_arg ) , val2 ( val2_arg )
{
}
void
2015-05-28 11:42:12 +02:00
DsampleStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
if ( val2 < 0 )
2008-12-08 17:19:59 +01:00
output < < " dsample( " < < val1 < < " ); " < < endl ;
2008-02-03 11:28:36 +01:00
else
2008-12-08 17:19:59 +01:00
output < < " dsample( " < < val1 < < " , " < < val2 < < " ); " < < endl ;
2008-02-03 11:28:36 +01:00
}
2017-02-08 18:29:57 +01:00
void
DsampleStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" dsample \" , "
< < " \" value1 \" : " < < val1 < < " , "
< < " \" value2 \" : " < < val2 < < " } " ;
}
2008-02-03 11:28:36 +01:00
EstimatedParamsStatement : : EstimatedParamsStatement ( const vector < EstimationParams > & estim_params_list_arg ,
const SymbolTable & symbol_table_arg ) :
estim_params_list ( estim_params_list_arg ) ,
symbol_table ( symbol_table_arg )
{
}
2010-06-11 21:19:30 +02:00
void
2012-01-23 16:52:27 +01:00
EstimatedParamsStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2010-06-11 21:19:30 +02:00
{
for ( vector < EstimationParams > : : const_iterator it = estim_params_list . begin ( ) ;
it ! = estim_params_list . end ( ) ; it + + )
2010-06-18 15:09:47 +02:00
{
if ( it - > name = = " dsge_prior_weight " )
mod_file_struct . dsge_prior_weight_in_estimated_params = true ;
2010-09-16 15:37:09 +02:00
// Handle case of degenerate beta prior
2011-12-29 18:43:21 +01:00
if ( it - > prior = = eBeta )
2010-09-16 15:37:09 +02:00
try
2010-06-18 15:09:47 +02:00
{
2011-02-04 16:25:38 +01:00
if ( it - > mean - > eval ( eval_context_t ( ) ) = = 0.5
& & it - > std - > eval ( eval_context_t ( ) ) = = 0.5 )
2010-09-16 15:37:09 +02:00
{
cerr < < " ERROR: The prior density is not defined for the beta distribution when the mean = standard deviation = 0.5. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
catch ( ExprNode : : EvalException & e )
{
// We don't have enough information to compute the numerical value, skip the test
2010-06-18 15:09:47 +02:00
}
}
2013-02-26 12:37:35 +01:00
// Check that no parameter/endogenous is declared twice in the block
set < string > already_declared ;
set < pair < string , string > > already_declared_corr ;
for ( vector < EstimationParams > : : const_iterator it = estim_params_list . begin ( ) ;
it ! = estim_params_list . end ( ) ; it + + )
{
if ( it - > type = = 3 ) // Correlation
{
// Use lexical ordering for the pair of symbols
pair < string , string > x = it - > name < it - > name2 ? make_pair ( it - > name , it - > name2 ) : make_pair ( it - > name2 , it - > name ) ;
if ( already_declared_corr . find ( x ) = = already_declared_corr . end ( ) )
already_declared_corr . insert ( x ) ;
else
{
cerr < < " ERROR: in `estimated_params' block, the correlation between " < < it - > name < < " and " < < it - > name2 < < " is declared twice. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
else
{
if ( already_declared . find ( it - > name ) = = already_declared . end ( ) )
already_declared . insert ( it - > name ) ;
else
{
cerr < < " ERROR: in `estimated_params' block, the symbol " < < it - > name < < " is declared twice. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
}
2013-11-29 14:50:58 +01:00
// Fill in mod_file_struct.estimated_parameters (related to #469)
for ( vector < EstimationParams > : : const_iterator it = estim_params_list . begin ( ) ;
it ! = estim_params_list . end ( ) ; it + + )
2013-12-02 14:58:33 +01:00
if ( it - > type = = 2 & & it - > name ! = " dsge_prior_weight " )
2013-11-29 14:50:58 +01:00
mod_file_struct . estimated_parameters . insert ( symbol_table . getID ( it - > name ) ) ;
2010-06-11 21:19:30 +02:00
}
2008-02-03 11:28:36 +01:00
void
2015-05-28 11:42:12 +02:00
EstimatedParamsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
2009-01-22 16:05:38 +01:00
output < < " global estim_params_ " < < endl
< < " estim_params_.var_exo = []; " < < endl
< < " estim_params_.var_endo = []; " < < endl
< < " estim_params_.corrx = []; " < < endl
< < " estim_params_.corrn = []; " < < endl
2010-04-14 15:03:41 +02:00
< < " estim_params_.param_vals = []; " < < endl ;
2008-02-03 11:28:36 +01:00
2017-02-10 11:07:45 +01:00
for ( vector < EstimationParams > : : const_iterator it = estim_params_list . begin ( ) ; it ! = estim_params_list . end ( ) ; it + + )
2008-02-03 11:28:36 +01:00
{
2009-02-27 13:19:25 +01:00
int symb_id = symbol_table . getTypeSpecificID ( it - > name ) + 1 ;
2009-01-22 16:05:38 +01:00
SymbolType symb_type = symbol_table . getType ( it - > name ) ;
2009-12-16 18:13:23 +01:00
switch ( it - > type )
2008-02-03 11:28:36 +01:00
{
case 1 :
2009-01-22 16:05:38 +01:00
if ( symb_type = = eExogenous )
2008-02-03 11:28:36 +01:00
output < < " estim_params_.var_exo = [estim_params_.var_exo; " ;
2009-01-22 16:05:38 +01:00
else if ( symb_type = = eEndogenous )
2008-02-03 11:28:36 +01:00
output < < " estim_params_.var_endo = [estim_params_.var_endo; " ;
2009-01-22 16:05:38 +01:00
output < < symb_id ;
2008-02-03 11:28:36 +01:00
break ;
case 2 :
2009-01-22 16:05:38 +01:00
output < < " estim_params_.param_vals = [estim_params_.param_vals; "
< < symb_id ;
2008-02-03 11:28:36 +01:00
break ;
case 3 :
2009-01-22 16:05:38 +01:00
if ( symb_type = = eExogenous )
2008-02-03 11:28:36 +01:00
output < < " estim_params_.corrx = [estim_params_.corrx; " ;
2009-01-22 16:05:38 +01:00
else if ( symb_type = = eEndogenous )
2008-02-03 11:28:36 +01:00
output < < " estim_params_.corrn = [estim_params_.corrn; " ;
2009-02-27 13:19:25 +01:00
output < < symb_id < < " " < < symbol_table . getTypeSpecificID ( it - > name2 ) + 1 ;
2008-02-03 11:28:36 +01:00
break ;
}
2009-01-22 16:05:38 +01:00
output < < " , " ;
it - > init_val - > writeOutput ( output ) ;
output < < " , " ;
it - > low_bound - > writeOutput ( output ) ;
output < < " , " ;
it - > up_bound - > writeOutput ( output ) ;
output < < " , "
< < it - > prior < < " , " ;
it - > mean - > writeOutput ( output ) ;
output < < " , " ;
it - > std - > writeOutput ( output ) ;
output < < " , " ;
it - > p3 - > writeOutput ( output ) ;
output < < " , " ;
it - > p4 - > writeOutput ( output ) ;
output < < " , " ;
it - > jscale - > writeOutput ( output ) ;
output < < " ]; " < < endl ;
2008-02-03 11:28:36 +01:00
}
}
2017-02-08 18:29:57 +01:00
void
EstimatedParamsStatement : : writeJsonOutput ( ostream & output ) const
{
deriv_node_temp_terms_t tef_terms ;
output < < " { \" statementName \" : \" estimated_params \" , "
< < " \" params \" : [ " ;
for ( vector < EstimationParams > : : const_iterator it = estim_params_list . begin ( ) ; it ! = estim_params_list . end ( ) ; it + + )
{
if ( it ! = estim_params_list . begin ( ) )
output < < " , " ;
output < < " { " ;
switch ( it - > type )
{
case 1 :
output < < " \" var \" : \" " < < it - > name < < " \" " ;
break ;
case 2 :
output < < " \" param \" : \" " < < it - > name < < " \" " ;
break ;
case 3 :
output < < " \" var1 \" : \" " < < it - > name < < " \" , "
< < " \" var2 \" : \" " < < it - > name2 < < " \" " ;
break ;
}
output < < " , \" init_val \" : \" " ;
2017-02-20 12:18:11 +01:00
it - > init_val - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " \" , \" lower_bound \" : \" " ;
2017-02-20 12:18:11 +01:00
it - > low_bound - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " \" , \" upper_bound \" : \" " ;
2017-02-20 12:18:11 +01:00
it - > up_bound - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " \" , \" prior_distribution \" : "
< < it - > prior
< < " , \" mean \" : \" " ;
2017-02-20 12:18:11 +01:00
it - > mean - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " \" , \" std \" : \" " ;
2017-02-20 12:18:11 +01:00
it - > std - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " \" , \" p3 \" : \" " ;
2017-02-20 12:18:11 +01:00
it - > p3 - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " \" , \" p4 \" : \" " ;
2017-02-20 12:18:11 +01:00
it - > p4 - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " \" , \" jscale \" : \" " ;
2017-02-20 12:18:11 +01:00
it - > jscale - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " \" } " < < endl ;
}
output < < " ] "
< < " } " ;
}
2008-02-03 11:28:36 +01:00
EstimatedParamsInitStatement : : EstimatedParamsInitStatement ( const vector < EstimationParams > & estim_params_list_arg ,
2013-11-06 10:36:58 +01:00
const SymbolTable & symbol_table_arg ,
const bool use_calibration_arg ) :
2008-02-03 11:28:36 +01:00
estim_params_list ( estim_params_list_arg ) ,
2013-11-06 10:36:58 +01:00
symbol_table ( symbol_table_arg ) ,
use_calibration ( use_calibration_arg )
2008-02-03 11:28:36 +01:00
{
}
2013-12-09 16:23:49 +01:00
void
EstimatedParamsInitStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
if ( use_calibration )
mod_file_struct . estim_params_use_calib = true ;
}
2008-02-03 11:28:36 +01:00
void
2015-05-28 11:42:12 +02:00
EstimatedParamsInitStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
2013-11-06 10:36:58 +01:00
if ( use_calibration )
output < < " options_.use_calibration_initialization = 1; " < < endl ;
2017-02-10 11:07:45 +01:00
for ( vector < EstimationParams > : : const_iterator it = estim_params_list . begin ( ) ; it ! = estim_params_list . end ( ) ; it + + )
2008-02-03 11:28:36 +01:00
{
2009-02-27 13:19:25 +01:00
int symb_id = symbol_table . getTypeSpecificID ( it - > name ) + 1 ;
2009-01-22 16:05:38 +01:00
SymbolType symb_type = symbol_table . getType ( it - > name ) ;
2008-02-03 11:28:36 +01:00
if ( it - > type < 3 )
{
2009-01-22 16:05:38 +01:00
if ( symb_type = = eExogenous )
2008-02-03 11:28:36 +01:00
{
2009-01-22 16:05:38 +01:00
output < < " tmp1 = find(estim_params_.var_exo(:,1)== " < < symb_id < < " ); " < < endl ;
output < < " estim_params_.var_exo(tmp1,2) = " ;
it - > init_val - > writeOutput ( output ) ;
output < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
2009-01-22 16:05:38 +01:00
else if ( symb_type = = eEndogenous )
2008-02-03 11:28:36 +01:00
{
2009-01-22 16:05:38 +01:00
output < < " tmp1 = find(estim_params_.var_endo(:,1)== " < < symb_id < < " ); " < < endl ;
output < < " estim_params_.var_endo(tmp1,2) = " ;
it - > init_val - > writeOutput ( output ) ;
output < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
2009-01-22 16:05:38 +01:00
else if ( symb_type = = eParameter )
2008-02-03 11:28:36 +01:00
{
2009-01-22 16:05:38 +01:00
output < < " tmp1 = find(estim_params_.param_vals(:,1)== " < < symb_id < < " ); " < < endl ;
output < < " estim_params_.param_vals(tmp1,2) = " ;
it - > init_val - > writeOutput ( output ) ;
output < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
}
else
{
2009-01-22 16:05:38 +01:00
if ( symb_type = = eExogenous )
2008-02-03 11:28:36 +01:00
{
2013-09-24 16:01:35 +02:00
output < < " tmp1 = find((estim_params_.corrx(:,1)== " < < symb_id < < " & estim_params_.corrx(:,2)== " < < symbol_table . getTypeSpecificID ( it - > name2 ) + 1 < < " ) | "
< < " (estim_params_.corrx(:,2)== " < < symb_id < < " & estim_params_.corrx(:,1)== " < < symbol_table . getTypeSpecificID ( it - > name2 ) + 1 < < " )); " < < endl ;
2009-01-22 16:05:38 +01:00
output < < " estim_params_.corrx(tmp1,3) = " ;
it - > init_val - > writeOutput ( output ) ;
output < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
2009-01-22 16:05:38 +01:00
else if ( symb_type = = eEndogenous )
2008-02-03 11:28:36 +01:00
{
2013-09-24 16:01:35 +02:00
output < < " tmp1 = find((estim_params_.corrn(:,1)== " < < symb_id < < " & estim_params_.corrn(:,2)== " < < symbol_table . getTypeSpecificID ( it - > name2 ) + 1 < < " ) | "
< < " (estim_params_.corrn(:,2)== " < < symb_id < < " & estim_params_.corrn(:,1)== " < < symbol_table . getTypeSpecificID ( it - > name2 ) + 1 < < " )); " < < endl ;
2009-01-22 16:05:38 +01:00
output < < " estim_params_.corrn(tmp1,3) = " ;
it - > init_val - > writeOutput ( output ) ;
output < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
}
}
}
2017-02-08 18:29:57 +01:00
void
EstimatedParamsInitStatement : : writeJsonOutput ( ostream & output ) const
{
deriv_node_temp_terms_t tef_terms ;
output < < " { \" statementName \" : \" estimated_params_init \" " ;
if ( use_calibration )
output < < " , \" use_calibration_initialization \" : 1 " ;
output < < " , \" params \" : [ " ;
for ( vector < EstimationParams > : : const_iterator it = estim_params_list . begin ( ) ; it ! = estim_params_list . end ( ) ; it + + )
{
if ( it ! = estim_params_list . begin ( ) )
output < < " , " ;
output < < " { " ;
switch ( it - > type )
{
case 1 :
output < < " \" var \" : \" " < < it - > name < < " \" " ;
break ;
case 2 :
output < < " \" param \" : \" " < < it - > name < < " \" " ;
break ;
case 3 :
output < < " \" var1 \" : \" " < < it - > name < < " \" , "
< < " \" var2 \" : \" " < < it - > name2 < < " \" " ;
break ;
}
output < < " , \" init_val \" : \" " ;
2017-02-20 12:18:11 +01:00
it - > init_val - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " \" } " ;
}
output < < " ] "
< < " } " ;
}
2008-02-03 11:28:36 +01:00
EstimatedParamsBoundsStatement : : EstimatedParamsBoundsStatement ( const vector < EstimationParams > & estim_params_list_arg ,
const SymbolTable & symbol_table_arg ) :
estim_params_list ( estim_params_list_arg ) ,
symbol_table ( symbol_table_arg )
{
}
void
2015-05-28 11:42:12 +02:00
EstimatedParamsBoundsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
2017-02-10 11:07:45 +01:00
for ( vector < EstimationParams > : : const_iterator it = estim_params_list . begin ( ) ; it ! = estim_params_list . end ( ) ; it + + )
2008-02-03 11:28:36 +01:00
{
2009-02-27 13:19:25 +01:00
int symb_id = symbol_table . getTypeSpecificID ( it - > name ) + 1 ;
2009-01-22 16:05:38 +01:00
SymbolType symb_type = symbol_table . getType ( it - > name ) ;
2008-02-03 11:28:36 +01:00
if ( it - > type < 3 )
{
2009-01-22 16:05:38 +01:00
if ( symb_type = = eExogenous )
2008-02-03 11:28:36 +01:00
{
2009-01-22 16:05:38 +01:00
output < < " tmp1 = find(estim_params_.var_exo(:,1)== " < < symb_id < < " ); " < < endl ;
output < < " estim_params_.var_exo(tmp1,3) = " ;
it - > low_bound - > writeOutput ( output ) ;
output < < " ; " < < endl ;
output < < " estim_params_.var_exo(tmp1,4) = " ;
it - > up_bound - > writeOutput ( output ) ;
output < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
2009-01-22 16:05:38 +01:00
else if ( symb_type = = eEndogenous )
2008-02-03 11:28:36 +01:00
{
2009-01-22 16:05:38 +01:00
output < < " tmp1 = find(estim_params_.var_endo(:,1)== " < < symb_id < < " ); " < < endl ;
output < < " estim_params_.var_endo(tmp1,3) = " ;
it - > low_bound - > writeOutput ( output ) ;
output < < " ; " < < endl ;
output < < " estim_params_.var_endo(tmp1,4) = " ;
it - > up_bound - > writeOutput ( output ) ;
output < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
2009-01-22 16:05:38 +01:00
else if ( symb_type = = eParameter )
2008-02-03 11:28:36 +01:00
{
2009-01-22 16:05:38 +01:00
output < < " tmp1 = find(estim_params_.param_vals(:,1)== " < < symb_id < < " ); " < < endl ;
output < < " estim_params_.param_vals(tmp1,3) = " ;
it - > low_bound - > writeOutput ( output ) ;
output < < " ; " < < endl ;
output < < " estim_params_.param_vals(tmp1,4) = " ;
it - > up_bound - > writeOutput ( output ) ;
output < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
}
else
{
2009-01-22 16:05:38 +01:00
if ( symb_type = = eExogenous )
2008-02-03 11:28:36 +01:00
{
2013-09-25 14:44:49 +02:00
output < < " tmp1 = find((estim_params_.corrx(:,1)== " < < symb_id < < " & estim_params_.corrx(:,2)== " < < symbol_table . getTypeSpecificID ( it - > name2 ) + 1 < < " ) | "
< < " (estim_params_.corrx(:,2)== " < < symb_id < < " & estim_params_.corrx(:,1)== " < < symbol_table . getTypeSpecificID ( it - > name2 ) + 1 < < " )); " < < endl ;
2009-01-22 16:05:38 +01:00
output < < " estim_params_.corrx(tmp1,4) = " ;
it - > low_bound - > writeOutput ( output ) ;
output < < " ; " < < endl ;
output < < " estim_params_.corrx(tmp1,5) = " ;
it - > up_bound - > writeOutput ( output ) ;
output < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
2009-01-22 16:05:38 +01:00
else if ( symb_type = = eEndogenous )
2008-02-03 11:28:36 +01:00
{
2013-09-25 14:44:49 +02:00
output < < " tmp1 = find((estim_params_.corrn(:,1)== " < < symb_id < < " & estim_params_.corrn(:,2)== " < < symbol_table . getTypeSpecificID ( it - > name2 ) + 1 < < " ) | "
< < " (estim_params_.corrn(:,2)== " < < symb_id < < " & estim_params_.corrn(:,1)== " < < symbol_table . getTypeSpecificID ( it - > name2 ) + 1 < < " )); " < < endl ;
2009-01-22 16:05:38 +01:00
output < < " estim_params_.corrn(tmp1,4) = " ;
it - > low_bound - > writeOutput ( output ) ;
output < < " ; " < < endl ;
output < < " estim_params_.corrn(tmp1,5) = " ;
it - > up_bound - > writeOutput ( output ) ;
output < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
}
}
}
2017-02-08 18:29:57 +01:00
void
EstimatedParamsBoundsStatement : : writeJsonOutput ( ostream & output ) const
{
deriv_node_temp_terms_t tef_terms ;
output < < " { \" statementName \" : \" estimated_params_bounds \" , "
< < " \" params \" : [ " ;
for ( vector < EstimationParams > : : const_iterator it = estim_params_list . begin ( ) ; it ! = estim_params_list . end ( ) ; it + + )
{
if ( it ! = estim_params_list . begin ( ) )
output < < " , " ;
output < < " { " ;
switch ( it - > type )
{
case 1 :
output < < " \" var \" : \" " < < it - > name < < " \" " ;
case 2 :
output < < " \" param \" : \" " < < it - > name < < " \" " ;
break ;
case 3 :
output < < " \" var1 \" : \" " < < it - > name < < " \" , "
< < " \" var2 \" : \" " < < it - > name2 < < " \" " ;
break ;
}
output < < " , \" lower_bound \" : " ;
2017-02-20 12:18:11 +01:00
it - > low_bound - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " , \" upper_bound \" : " ;
2017-02-20 12:18:11 +01:00
it - > up_bound - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " } " ;
}
output < < " ] "
< < " } " ;
}
2010-09-16 19:00:48 +02:00
ObservationTrendsStatement : : ObservationTrendsStatement ( const trend_elements_t & trend_elements_arg ,
2008-02-03 11:28:36 +01:00
const SymbolTable & symbol_table_arg ) :
trend_elements ( trend_elements_arg ) ,
symbol_table ( symbol_table_arg )
{
}
void
2015-05-28 11:42:12 +02:00
ObservationTrendsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
2015-03-01 14:22:45 +01:00
output < < " options_.trend_coeff = {}; " < < endl ;
2017-02-09 16:22:00 +01:00
for ( trend_elements_t : : const_iterator it = trend_elements . begin ( ) ; it ! = trend_elements . end ( ) ; it + + )
2008-02-03 11:28:36 +01:00
{
2008-10-17 12:20:19 +02:00
SymbolType type = symbol_table . getType ( it - > first ) ;
2008-02-03 11:28:36 +01:00
if ( type = = eEndogenous )
{
2014-12-15 11:44:27 +01:00
output < < " tmp1 = strmatch(' " < < it - > first < < " ',options_.varobs,'exact'); " < < endl ;
2008-02-03 11:28:36 +01:00
output < < " options_.trend_coeffs{tmp1} = ' " ;
it - > second - > writeOutput ( output ) ;
output < < " '; " < < endl ;
}
else
2017-02-09 16:21:18 +01:00
cerr < < " Warning : Non-variable symbol used in observation_trends: " < < it - > first < < endl ;
2008-02-03 11:28:36 +01:00
}
}
2017-02-08 18:29:57 +01:00
void
ObservationTrendsStatement : : writeJsonOutput ( ostream & output ) const
{
deriv_node_temp_terms_t tef_terms ;
output < < " { \" statementName \" : \" observation_trends \" , "
< < " \" trends \" : { " ;
bool printed = false ;
for ( trend_elements_t : : const_iterator it = trend_elements . begin ( ) ;
it ! = trend_elements . end ( ) ; it + + )
{
if ( symbol_table . getType ( it - > first ) = = eEndogenous )
{
if ( printed )
output < < " , " ;
output < < " \" " < < it - > first < < " \" : \" " ;
2017-02-20 12:18:11 +01:00
it - > second - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " \" " < < endl ;
printed = true ;
}
else
cerr < < " Warning : Non-variable symbol used in observation_trends: " < < it - > first < < endl ;
}
output < < " } "
< < " } " ;
}
2016-05-20 15:35:09 +02:00
OsrParamsStatement : : OsrParamsStatement ( const SymbolList & symbol_list_arg , const SymbolTable & symbol_table_arg ) :
symbol_list ( symbol_list_arg ) ,
symbol_table ( symbol_table_arg )
2008-02-03 11:28:36 +01:00
{
}
2011-03-03 16:30:53 +01:00
void
2012-01-23 16:52:27 +01:00
OsrParamsStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2011-03-03 16:30:53 +01:00
{
2016-05-20 15:46:28 +02:00
if ( mod_file_struct . osr_params_present )
cerr < < " WARNING: You have more than one osr_params statement in the .mod file. " < < endl ;
2011-03-03 16:30:53 +01:00
mod_file_struct . osr_params_present = true ;
}
2008-02-03 11:28:36 +01:00
void
2015-05-28 11:42:12 +02:00
OsrParamsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
2016-05-20 15:35:09 +02:00
symbol_list . writeOutput ( " M_.osr.param_names " , output ) ;
output < < " M_.osr.param_names = cellstr(M_.osr.param_names); " < < endl
< < " M_.osr.param_indices = zeros(length(M_.osr.param_names), 1); " < < endl ;
int i = 0 ;
vector < string > symbols = symbol_list . get_symbols ( ) ;
for ( vector < string > : : const_iterator it = symbols . begin ( ) ; it ! = symbols . end ( ) ; it + + )
output < < " M_.osr.param_indices( " < < + + i < < " ) = " < < symbol_table . getTypeSpecificID ( * it ) + 1 < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
2017-02-08 18:29:57 +01:00
void
OsrParamsStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" osr_params \" " ;
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2008-04-07 15:14:40 +02:00
OsrStatement : : OsrStatement ( const SymbolList & symbol_list_arg ,
2008-02-03 11:28:36 +01:00
const OptionsList & options_list_arg ) :
2008-04-07 15:14:40 +02:00
symbol_list ( symbol_list_arg ) ,
2008-02-03 11:28:36 +01:00
options_list ( options_list_arg )
{
}
2016-05-20 15:35:09 +02:00
OsrParamsBoundsStatement : : OsrParamsBoundsStatement ( const vector < OsrParams > & osr_params_list_arg ) :
osr_params_list ( osr_params_list_arg )
{
}
void
OsrParamsBoundsStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2016-05-10 18:01:00 +02:00
{
2016-05-20 15:35:09 +02:00
if ( ! mod_file_struct . osr_params_present )
{
cerr < < " ERROR: you must have an osr_params statement before the osr_params_bounds block. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2016-05-10 18:01:00 +02:00
}
void
OsrParamsBoundsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
2016-05-20 15:35:09 +02:00
output < < " M_.osr.param_bounds = [-inf(length(M_.osr.param_names), 1), inf(length(M_.osr.param_names), 1)]; " < < endl ;
2016-05-10 18:01:00 +02:00
for ( vector < OsrParams > : : const_iterator it = osr_params_list . begin ( ) ;
2016-05-20 15:35:09 +02:00
it ! = osr_params_list . end ( ) ; it + + )
2016-05-10 18:01:00 +02:00
{
2016-05-20 15:35:09 +02:00
output < < " M_.osr.param_bounds(strcmp(M_.osr.param_names, ' " < < it - > name < < " '), :) = [ " ;
2016-05-10 18:01:00 +02:00
it - > low_bound - > writeOutput ( output ) ;
output < < " , " ;
it - > up_bound - > writeOutput ( output ) ;
output < < " ]; " < < endl ;
}
}
2017-02-08 18:29:57 +01:00
void
OsrParamsBoundsStatement : : writeJsonOutput ( ostream & output ) const
{
deriv_node_temp_terms_t tef_terms ;
output < < " { \" statementName \" : \" osr_params_bounds \" "
< < " , \" bounds \" : [ " ;
for ( vector < OsrParams > : : const_iterator it = osr_params_list . begin ( ) ;
it ! = osr_params_list . end ( ) ; it + + )
{
if ( it ! = osr_params_list . begin ( ) )
output < < " , " ;
output < < " { \" parameter \" : \" " < < it - > name < < " \" , "
< < " \" bounds \" : [ \" " ;
2017-02-20 12:18:11 +01:00
it - > low_bound - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " \" , \" " ;
2017-02-20 12:18:11 +01:00
it - > up_bound - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " \" ] "
< < " } " ;
}
output < < " ] "
< < " } " ;
}
2008-02-03 11:28:36 +01:00
void
2012-01-23 16:52:27 +01:00
OsrStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2008-02-03 11:28:36 +01:00
{
2008-09-29 12:16:13 +02:00
mod_file_struct . osr_present = true ;
2008-02-03 11:28:36 +01:00
// Fill in option_order of mod_file_struct
2010-09-16 19:00:48 +02:00
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " order " ) ;
2008-02-03 11:28:36 +01:00
if ( it ! = options_list . num_options . end ( ) )
2009-12-16 18:13:23 +01:00
mod_file_struct . order_option = max ( mod_file_struct . order_option , atoi ( it - > second . c_str ( ) ) ) ;
2008-11-04 12:00:54 +01:00
2009-10-20 18:55:31 +02:00
// Fill in mod_file_struct.partial_information
it = options_list . num_options . find ( " partial_information " ) ;
if ( it ! = options_list . num_options . end ( ) & & it - > second = = " 1 " )
mod_file_struct . partial_information = true ;
2009-12-09 12:50:58 +01:00
// Option k_order_solver (implicit when order >= 3)
it = options_list . num_options . find ( " k_order_solver " ) ;
if ( ( it ! = options_list . num_options . end ( ) & & it - > second = = " 1 " )
| | mod_file_struct . order_option > = 3 )
mod_file_struct . k_order_solver = true ;
2008-02-03 11:28:36 +01:00
}
void
2015-05-28 11:42:12 +02:00
OsrStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
2015-02-10 03:39:18 +01:00
// Ensure that order 3 implies k_order (#844)
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " order " ) ;
OptionsList : : num_options_t : : const_iterator it1 = options_list . num_options . find ( " k_order_solver " ) ;
if ( ( it1 ! = options_list . num_options . end ( ) & & it1 - > second = = " 1 " )
| | ( it ! = options_list . num_options . end ( ) & & atoi ( it - > second . c_str ( ) ) > = 3 ) )
output < < " options_.k_order_solver = 1; " < < endl ;
2008-02-03 11:28:36 +01:00
options_list . writeOutput ( output ) ;
2008-04-07 15:14:40 +02:00
symbol_list . writeOutput ( " var_list_ " , output ) ;
2016-05-14 11:33:33 +02:00
output < < " oo_.osr = osr(var_list_,M_.osr.param_names,M_.osr.variable_indices,M_.osr.variable_weights); " < < endl ;
2008-02-03 11:28:36 +01:00
}
2017-02-08 18:29:57 +01:00
void
OsrStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" osr \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2010-09-16 19:00:48 +02:00
OptimWeightsStatement : : OptimWeightsStatement ( const var_weights_t & var_weights_arg ,
const covar_weights_t & covar_weights_arg ,
2008-02-03 11:28:36 +01:00
const SymbolTable & symbol_table_arg ) :
var_weights ( var_weights_arg ) ,
covar_weights ( covar_weights_arg ) ,
symbol_table ( symbol_table_arg )
{
}
2011-03-03 16:30:53 +01:00
void
2012-01-23 16:52:27 +01:00
OptimWeightsStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2011-03-03 16:30:53 +01:00
{
mod_file_struct . optim_weights_present = true ;
}
2008-02-03 11:28:36 +01:00
void
2015-05-28 11:42:12 +02:00
OptimWeightsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
2008-06-16 18:33:28 +02:00
output < < " % " < < endl
< < " % OPTIM_WEIGHTS " < < endl
< < " % " < < endl
2016-05-20 15:52:44 +02:00
< < " M_.osr.variable_weights = sparse(M_.endo_nbr,M_.endo_nbr); " < < endl
< < " M_.osr.variable_indices = []; " < < endl < < endl ;
2008-02-03 11:28:36 +01:00
2010-09-16 19:00:48 +02:00
for ( var_weights_t : : const_iterator it = var_weights . begin ( ) ;
2009-12-16 18:13:23 +01:00
it ! = var_weights . end ( ) ; it + + )
2008-02-03 11:28:36 +01:00
{
const string & name = it - > first ;
2010-09-16 19:18:45 +02:00
const expr_t value = it - > second ;
2009-02-27 13:19:25 +01:00
int id = symbol_table . getTypeSpecificID ( name ) + 1 ;
2016-05-20 15:52:44 +02:00
output < < " M_.osr.variable_weights( " < < id < < " , " < < id < < " ) = " ;
2008-02-03 11:28:36 +01:00
value - > writeOutput ( output ) ;
output < < " ; " < < endl ;
2016-05-20 15:52:44 +02:00
output < < " M_.osr.variable_indices = [M_.osr.variable_indices; " < < id < < " ]; " < < endl ;
2008-02-03 11:28:36 +01:00
}
2010-09-16 19:00:48 +02:00
for ( covar_weights_t : : const_iterator it = covar_weights . begin ( ) ;
2009-12-16 18:13:23 +01:00
it ! = covar_weights . end ( ) ; it + + )
2008-02-03 11:28:36 +01:00
{
const string & name1 = it - > first . first ;
const string & name2 = it - > first . second ;
2010-09-16 19:18:45 +02:00
const expr_t value = it - > second ;
2009-02-27 13:19:25 +01:00
int id1 = symbol_table . getTypeSpecificID ( name1 ) + 1 ;
int id2 = symbol_table . getTypeSpecificID ( name2 ) + 1 ;
2016-05-20 15:52:44 +02:00
output < < " M_.osr.variable_weights( " < < id1 < < " , " < < id2 < < " ) = " ;
2008-02-03 11:28:36 +01:00
value - > writeOutput ( output ) ;
output < < " ; " < < endl ;
2016-05-20 15:52:44 +02:00
output < < " M_.osr.variable_indices = [M_.osr.variable_indices; " < < id1 < < " ; " < < id2 < < " ]; " < < endl ;
2008-02-03 11:28:36 +01:00
}
}
2017-02-08 18:29:57 +01:00
void
OptimWeightsStatement : : writeJsonOutput ( ostream & output ) const
{
deriv_node_temp_terms_t tef_terms ;
output < < " { \" statementName \" : \" optim_weights \" , "
< < " \" weights \" : [ " ;
for ( var_weights_t : : const_iterator it = var_weights . begin ( ) ;
it ! = var_weights . end ( ) ; it + + )
{
if ( it ! = var_weights . begin ( ) )
output < < " , " ;
output < < " { \" name \" : \" " < < it - > first < < " \" "
< < " , \" value \" : \" " ;
2017-02-20 12:18:11 +01:00
it - > second - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " \" } " ;
}
for ( covar_weights_t : : const_iterator it = covar_weights . begin ( ) ;
it ! = covar_weights . end ( ) ; it + + )
{
if ( it ! = covar_weights . begin ( ) | | ! var_weights . empty ( ) )
output < < " , " ;
output < < " { \" name1 \" : \" " < < it - > first . first < < " \" "
< < " , \" name2 \" : \" " < < it - > first . second < < " \" "
< < " , \" value \" : \" " ;
2017-02-20 12:18:11 +01:00
it - > second - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " \" } " ;
}
output < < " ] "
< < " } " ;
}
2008-04-07 15:14:40 +02:00
DynaSaveStatement : : DynaSaveStatement ( const SymbolList & symbol_list_arg ,
2008-10-13 18:06:07 +02:00
const string & filename_arg ) :
2008-04-07 15:14:40 +02:00
symbol_list ( symbol_list_arg ) ,
2008-10-13 18:06:07 +02:00
filename ( filename_arg )
2008-02-03 11:28:36 +01:00
{
}
void
2015-05-28 11:42:12 +02:00
DynaSaveStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
2008-04-07 15:14:40 +02:00
symbol_list . writeOutput ( " var_list_ " , output ) ;
2008-10-13 18:06:07 +02:00
output < < " dynasave(' " < < filename
< < " ',var_list_); " < < endl ;
2008-02-03 11:28:36 +01:00
}
2017-02-08 18:29:57 +01:00
void
DynaSaveStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" dynasave \" , "
< < " \" filename \" : \" " < < filename < < " \" " ;
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2008-04-07 15:14:40 +02:00
DynaTypeStatement : : DynaTypeStatement ( const SymbolList & symbol_list_arg ,
2008-10-13 18:06:07 +02:00
const string & filename_arg ) :
2008-04-07 15:14:40 +02:00
symbol_list ( symbol_list_arg ) ,
2008-10-13 18:06:07 +02:00
filename ( filename_arg )
2008-02-03 11:28:36 +01:00
{
}
void
2015-05-28 11:42:12 +02:00
DynaTypeStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
2008-04-07 15:14:40 +02:00
symbol_list . writeOutput ( " var_list_ " , output ) ;
2008-10-13 18:06:07 +02:00
output < < " dynatype(' " < < filename
< < " ',var_list_); " < < endl ;
2008-02-03 11:28:36 +01:00
}
2017-02-08 18:29:57 +01:00
void
DynaTypeStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" dynatype \" , "
< < " \" filename \" : \" " < < filename < < " \" " ;
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2010-09-16 19:00:48 +02:00
ModelComparisonStatement : : ModelComparisonStatement ( const filename_list_t & filename_list_arg ,
2008-02-03 11:28:36 +01:00
const OptionsList & options_list_arg ) :
filename_list ( filename_list_arg ) ,
options_list ( options_list_arg )
{
}
void
2015-05-28 11:42:12 +02:00
ModelComparisonStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
options_list . writeOutput ( output ) ;
2008-09-26 18:24:13 +02:00
output < < " ModelNames_ = {}; " < < endl ;
output < < " ModelPriors_ = []; " < < endl ;
2008-02-03 11:28:36 +01:00
2010-09-16 19:00:48 +02:00
for ( filename_list_t : : const_iterator it = filename_list . begin ( ) ;
2009-12-16 18:13:23 +01:00
it ! = filename_list . end ( ) ; it + + )
2008-02-03 11:28:36 +01:00
{
2008-09-26 18:24:13 +02:00
output < < " ModelNames_ = { ModelNames_{:} ' " < < ( * it ) . first < < " '}; " < < endl ;
output < < " ModelPriors_ = [ ModelPriors_ ; " < < ( * it ) . second < < " ]; " < < endl ;
2008-02-03 11:28:36 +01:00
}
2015-08-06 08:44:47 +02:00
output < < " oo_ = model_comparison(ModelNames_,ModelPriors_,oo_,options_,M_.fname); " < < endl ;
2008-02-03 11:28:36 +01:00
}
2017-02-08 18:29:57 +01:00
void
ModelComparisonStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" model_comparison \" " ;
if ( ! filename_list . empty ( ) )
output < < " , \" filename_list \" : { " ;
for ( filename_list_t : : const_iterator it = filename_list . begin ( ) ;
it ! = filename_list . end ( ) ; it + + )
{
if ( it ! = filename_list . begin ( ) )
output < < " , " ;
output < < " \" name \" : \" " < < it - > first < < " \" "
< < " \" prior \" : \" " < < it - > second < < " \" " ;
}
if ( ! filename_list . empty ( ) )
output < < " } " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2009-04-14 16:39:53 +02:00
PlannerObjectiveStatement : : PlannerObjectiveStatement ( StaticModel * model_tree_arg ) :
2017-02-27 15:40:34 +01:00
model_tree ( model_tree_arg ) ,
computing_pass_called ( false )
2008-02-03 11:28:36 +01:00
{
}
PlannerObjectiveStatement : : ~ PlannerObjectiveStatement ( )
{
delete model_tree ;
}
void
2012-01-23 16:52:27 +01:00
PlannerObjectiveStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2008-02-03 11:28:36 +01:00
{
2009-04-28 18:21:39 +02:00
assert ( model_tree - > equation_number ( ) = = 1 ) ;
2016-08-12 11:50:57 +02:00
if ( model_tree - > exoPresentInEqs ( ) )
{
cerr < < " ERROR: You cannot include exogenous variables in the planner objective. Please "
< < " define an auxiliary endogenous variable like eps_aux=epsilon and use it instead "
< < " of the varexo. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2011-03-03 16:03:21 +01:00
mod_file_struct . planner_objective_present = true ;
2008-02-03 11:28:36 +01:00
}
2011-03-21 18:40:57 +01:00
StaticModel *
PlannerObjectiveStatement : : getPlannerObjective ( ) const
{
return model_tree ;
}
2008-02-03 11:28:36 +01:00
void
PlannerObjectiveStatement : : computingPass ( )
{
2016-05-12 12:02:34 +02:00
model_tree - > computingPass ( eval_context_t ( ) , false , true , true , none , false , false ) ;
2017-02-27 15:40:34 +01:00
computing_pass_called = true ;
2008-02-03 11:28:36 +01:00
}
void
2015-05-28 11:42:12 +02:00
PlannerObjectiveStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
2015-07-27 15:59:13 +02:00
model_tree - > writeStaticFile ( basename + " _objective " , false , false , false , false ) ;
2008-02-03 11:28:36 +01:00
}
2017-02-08 18:29:57 +01:00
void
PlannerObjectiveStatement : : writeJsonOutput ( ostream & output ) const
{
2017-02-27 15:40:34 +01:00
output < < " { \" statementName \" : \" planner_objective \" "
< < " , " ;
if ( computing_pass_called )
2017-03-02 18:34:18 +01:00
model_tree - > writeJsonComputingPassOutput ( output , false ) ;
2017-02-27 15:40:34 +01:00
else
model_tree - > writeJsonOutput ( output ) ;
output < < " } " ;
2017-02-08 18:29:57 +01:00
}
2008-02-03 11:28:36 +01:00
BVARDensityStatement : : BVARDensityStatement ( int maxnlags_arg , const OptionsList & options_list_arg ) :
maxnlags ( maxnlags_arg ) ,
options_list ( options_list_arg )
{
}
2008-10-17 14:52:08 +02:00
void
2012-01-23 16:52:27 +01:00
BVARDensityStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2008-10-17 14:52:08 +02:00
{
2009-11-26 18:25:04 +01:00
mod_file_struct . bvar_present = true ;
2008-10-17 14:52:08 +02:00
}
2008-02-03 11:28:36 +01:00
void
2015-05-28 11:42:12 +02:00
BVARDensityStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
options_list . writeOutput ( output ) ;
output < < " bvar_density( " < < maxnlags < < " ); " < < endl ;
}
2017-02-08 18:29:57 +01:00
void
BVARDensityStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" bvar_density \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2008-02-03 11:28:36 +01:00
BVARForecastStatement : : BVARForecastStatement ( int nlags_arg , const OptionsList & options_list_arg ) :
nlags ( nlags_arg ) ,
options_list ( options_list_arg )
{
}
2008-10-17 14:52:08 +02:00
void
2012-01-23 16:52:27 +01:00
BVARForecastStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2008-10-17 14:52:08 +02:00
{
2009-11-26 18:25:04 +01:00
mod_file_struct . bvar_present = true ;
2008-10-17 14:52:08 +02:00
}
2008-02-03 11:28:36 +01:00
void
2015-05-28 11:42:12 +02:00
BVARForecastStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
options_list . writeOutput ( output ) ;
output < < " bvar_forecast( " < < nlags < < " ); " < < endl ;
}
2009-04-20 15:58:15 +02:00
2017-02-08 18:29:57 +01:00
void
BVARForecastStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" bvar_forecast \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2009-07-26 19:07:07 +02:00
SBVARStatement : : SBVARStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
{
}
void
2012-01-23 16:52:27 +01:00
SBVARStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2009-07-26 19:07:07 +02:00
{
2009-11-26 18:25:04 +01:00
mod_file_struct . bvar_present = true ;
2009-07-26 19:07:07 +02:00
}
void
2015-05-28 11:42:12 +02:00
SBVARStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2009-07-26 19:07:07 +02:00
{
options_list . writeOutput ( output ) ;
2011-05-31 10:39:41 +02:00
output < < " sbvar(M_,options_); " < < endl ;
2009-07-26 19:07:07 +02:00
}
2017-02-08 18:29:57 +01:00
void
SBVARStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" sbvar \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2011-05-11 19:02:39 +02:00
MSSBVAREstimationStatement : : MSSBVAREstimationStatement ( const OptionsList & options_list_arg ) :
2009-07-26 19:07:07 +02:00
options_list ( options_list_arg )
{
}
void
2012-01-23 16:52:27 +01:00
MSSBVAREstimationStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2009-07-26 19:07:07 +02:00
{
2009-11-26 18:25:04 +01:00
mod_file_struct . bvar_present = true ;
2012-09-25 15:49:59 +02:00
if ( options_list . num_options . find ( " ms.create_init " ) = = options_list . num_options . end ( ) )
2017-06-01 19:58:32 +02:00
if ( options_list . string_options . find ( " datafile " ) = = options_list . string_options . end ( )
| | options_list . num_options . find ( " ms.initial_year " ) = = options_list . num_options . end ( ) )
2012-09-25 15:49:59 +02:00
{
cerr < < " ERROR: If you do not pass no_create_init to ms_estimation, "
2012-10-24 14:05:11 +02:00
< < " you must pass the datafile and initial_year options. " < < endl ;
2012-09-25 15:49:59 +02:00
exit ( EXIT_FAILURE ) ;
}
2009-07-26 19:07:07 +02:00
}
void
2015-05-28 11:42:12 +02:00
MSSBVAREstimationStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2009-07-26 19:07:07 +02:00
{
2012-09-25 15:49:59 +02:00
output < < " options_ = initialize_ms_sbvar_options(M_, options_); " < < endl
< < " options_.datafile = ''; " < < endl ;
2009-07-26 19:07:07 +02:00
options_list . writeOutput ( output ) ;
2011-05-20 14:29:23 +02:00
output < < " [options_, oo_] = ms_estimation(M_, options_, oo_); " < < endl ;
2011-05-11 19:02:39 +02:00
}
2017-02-08 18:29:57 +01:00
void
MSSBVAREstimationStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" ms_sbvar_estimation \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2011-05-11 19:02:39 +02:00
MSSBVARSimulationStatement : : MSSBVARSimulationStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
{
}
void
2012-01-23 16:52:27 +01:00
MSSBVARSimulationStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2011-05-11 19:02:39 +02:00
{
mod_file_struct . bvar_present = true ;
}
void
2015-05-28 11:42:12 +02:00
MSSBVARSimulationStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2011-05-11 19:02:39 +02:00
{
2011-08-10 11:25:38 +02:00
output < < " options_ = initialize_ms_sbvar_options(M_, options_); " < < endl ;
2011-05-11 19:02:39 +02:00
options_list . writeOutput ( output ) ;
2011-09-14 20:27:51 +02:00
// Redeclare drop option if necessary
OptionsList : : num_options_t : : const_iterator mh_replic_it = options_list . num_options . find ( " ms.mh_replic " ) ;
2011-09-15 21:05:44 +02:00
OptionsList : : num_options_t : : const_iterator thinning_factor_it = options_list . num_options . find ( " ms.thinning_factor " ) ;
2011-09-14 20:27:51 +02:00
OptionsList : : num_options_t : : const_iterator drop_it = options_list . num_options . find ( " ms.drop " ) ;
2011-09-15 21:05:44 +02:00
if ( mh_replic_it ! = options_list . num_options . end ( ) | | thinning_factor_it ! = options_list . num_options . end ( ) )
2011-09-14 20:27:51 +02:00
if ( drop_it = = options_list . num_options . end ( ) )
2011-09-15 21:05:44 +02:00
output < < " options_.ms.drop = 0.1*options_.ms.mh_replic*options_.ms.thinning_factor; " < < endl ;
2011-09-14 20:27:51 +02:00
2011-05-20 14:29:23 +02:00
output < < " [options_, oo_] = ms_simulation(M_, options_, oo_); " < < endl ;
2011-05-11 19:02:39 +02:00
}
2017-02-08 18:29:57 +01:00
void
MSSBVARSimulationStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" ms_sbvar_simulation \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2011-05-11 19:02:39 +02:00
MSSBVARComputeMDDStatement : : MSSBVARComputeMDDStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
{
}
void
2012-01-23 16:52:27 +01:00
MSSBVARComputeMDDStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2011-05-11 19:02:39 +02:00
{
mod_file_struct . bvar_present = true ;
}
void
2015-05-28 11:42:12 +02:00
MSSBVARComputeMDDStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2011-05-11 19:02:39 +02:00
{
2011-08-10 11:25:38 +02:00
output < < " options_ = initialize_ms_sbvar_options(M_, options_); " < < endl ;
2011-05-11 19:02:39 +02:00
options_list . writeOutput ( output ) ;
2011-05-20 14:29:23 +02:00
output < < " [options_, oo_] = ms_compute_mdd(M_, options_, oo_); " < < endl ;
2011-05-11 19:02:39 +02:00
}
2017-02-08 18:29:57 +01:00
void
MSSBVARComputeMDDStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" ms_sbvar_compute_mdd \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2011-05-11 19:02:39 +02:00
MSSBVARComputeProbabilitiesStatement : : MSSBVARComputeProbabilitiesStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
{
}
void
2012-01-23 16:52:27 +01:00
MSSBVARComputeProbabilitiesStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2011-05-11 19:02:39 +02:00
{
mod_file_struct . bvar_present = true ;
2011-10-24 13:58:59 +02:00
if ( options_list . num_options . find ( " ms.real_time_smoothed_probabilities " ) ! = options_list . num_options . end ( ) )
if ( options_list . num_options . find ( " ms.filtered_probabilities " ) ! = options_list . num_options . end ( ) )
{
cerr < < " ERROR: You may only pass one of real_time_smoothed "
< < " and filtered_probabilities to ms_compute_probabilities. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2011-05-11 19:02:39 +02:00
}
void
2015-05-28 11:42:12 +02:00
MSSBVARComputeProbabilitiesStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2011-05-11 19:02:39 +02:00
{
2011-08-10 11:25:38 +02:00
output < < " options_ = initialize_ms_sbvar_options(M_, options_); " < < endl ;
2011-05-11 19:02:39 +02:00
options_list . writeOutput ( output ) ;
2011-05-20 14:29:23 +02:00
output < < " [options_, oo_] = ms_compute_probabilities(M_, options_, oo_); " < < endl ;
2011-05-11 19:02:39 +02:00
}
2017-02-08 18:29:57 +01:00
void
MSSBVARComputeProbabilitiesStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" ms_sbvar_compute_probabilities \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2011-05-30 15:47:34 +02:00
MSSBVARIrfStatement : : MSSBVARIrfStatement ( const SymbolList & symbol_list_arg ,
2017-06-01 19:58:32 +02:00
const OptionsList & options_list_arg ) :
2011-05-30 15:47:34 +02:00
symbol_list ( symbol_list_arg ) ,
2011-05-11 19:02:39 +02:00
options_list ( options_list_arg )
{
}
void
2012-01-23 16:52:27 +01:00
MSSBVARIrfStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2011-05-11 19:02:39 +02:00
{
mod_file_struct . bvar_present = true ;
2011-10-10 18:33:16 +02:00
bool regime_present = false ;
bool regimes_present = false ;
bool filtered_probabilities_present = false ;
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " ms.regimes " ) ;
if ( it ! = options_list . num_options . end ( ) )
regimes_present = true ;
it = options_list . num_options . find ( " ms.regime " ) ;
if ( it ! = options_list . num_options . end ( ) )
regime_present = true ;
it = options_list . num_options . find ( " ms.filtered_probabilities " ) ;
if ( it ! = options_list . num_options . end ( ) )
filtered_probabilities_present = true ;
2017-06-01 19:58:32 +02:00
if ( ( filtered_probabilities_present & & regime_present )
| | ( filtered_probabilities_present & & regimes_present )
| | ( regimes_present & & regime_present ) )
{
cerr < < " ERROR: You may only pass one of regime, regimes and "
< < " filtered_probabilities to ms_irf " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2011-05-11 19:02:39 +02:00
}
void
2015-05-28 11:42:12 +02:00
MSSBVARIrfStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2011-05-11 19:02:39 +02:00
{
2011-08-10 11:25:38 +02:00
output < < " options_ = initialize_ms_sbvar_options(M_, options_); " < < endl ;
2011-05-30 15:47:34 +02:00
symbol_list . writeOutput ( " var_list_ " , output ) ;
2011-05-11 19:02:39 +02:00
options_list . writeOutput ( output ) ;
2011-05-30 15:47:34 +02:00
output < < " [options_, oo_] = ms_irf(var_list_,M_, options_, oo_); " < < endl ;
2011-05-11 19:02:39 +02:00
}
2017-02-08 18:29:57 +01:00
void
MSSBVARIrfStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" ms_sbvar_irf \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2011-05-11 19:02:39 +02:00
MSSBVARForecastStatement : : MSSBVARForecastStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
{
}
void
2012-01-23 16:52:27 +01:00
MSSBVARForecastStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2011-05-11 19:02:39 +02:00
{
mod_file_struct . bvar_present = true ;
2011-10-11 18:08:58 +02:00
if ( options_list . num_options . find ( " ms.regimes " ) ! = options_list . num_options . end ( ) )
if ( options_list . num_options . find ( " ms.regime " ) ! = options_list . num_options . end ( ) )
{
cerr < < " ERROR: You may only pass one of regime and regimes to ms_forecast " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2011-05-11 19:02:39 +02:00
}
void
2015-05-28 11:42:12 +02:00
MSSBVARForecastStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2011-05-11 19:02:39 +02:00
{
2011-08-10 11:25:38 +02:00
output < < " options_ = initialize_ms_sbvar_options(M_, options_); " < < endl ;
2011-05-11 19:02:39 +02:00
options_list . writeOutput ( output ) ;
2011-05-20 14:29:23 +02:00
output < < " [options_, oo_] = ms_forecast(M_, options_, oo_); " < < endl ;
2011-05-11 19:02:39 +02:00
}
2017-02-08 18:29:57 +01:00
void
MSSBVARForecastStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" ms_sbvar_forecast \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2011-05-11 19:02:39 +02:00
MSSBVARVarianceDecompositionStatement : : MSSBVARVarianceDecompositionStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
{
}
void
2012-01-23 16:52:27 +01:00
MSSBVARVarianceDecompositionStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2011-05-11 19:02:39 +02:00
{
mod_file_struct . bvar_present = true ;
2011-10-19 17:25:46 +02:00
bool regime_present = false ;
bool regimes_present = false ;
bool filtered_probabilities_present = false ;
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " ms.regimes " ) ;
if ( it ! = options_list . num_options . end ( ) )
regimes_present = true ;
it = options_list . num_options . find ( " ms.regime " ) ;
if ( it ! = options_list . num_options . end ( ) )
regime_present = true ;
it = options_list . num_options . find ( " ms.filtered_probabilities " ) ;
if ( it ! = options_list . num_options . end ( ) )
filtered_probabilities_present = true ;
2017-06-01 19:58:32 +02:00
if ( ( filtered_probabilities_present & & regime_present )
| | ( filtered_probabilities_present & & regimes_present )
| | ( regimes_present & & regime_present ) )
{
cerr < < " ERROR: You may only pass one of regime, regimes and "
< < " filtered_probabilities to ms_variance_decomposition " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2011-05-11 19:02:39 +02:00
}
void
2015-05-28 11:42:12 +02:00
MSSBVARVarianceDecompositionStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2011-05-11 19:02:39 +02:00
{
2011-08-10 11:25:38 +02:00
output < < " options_ = initialize_ms_sbvar_options(M_, options_); " < < endl ;
2011-05-11 19:02:39 +02:00
options_list . writeOutput ( output ) ;
2011-05-20 14:29:23 +02:00
output < < " [options_, oo_] = ms_variance_decomposition(M_, options_, oo_); " < < endl ;
2009-07-26 19:07:07 +02:00
}
2017-02-08 18:29:57 +01:00
void
MSSBVARVarianceDecompositionStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" ms_sbvar_variance_decomposition \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2011-04-20 12:13:30 +02:00
IdentificationStatement : : IdentificationStatement ( const OptionsList & options_list_arg )
2009-04-20 15:58:15 +02:00
{
2011-04-20 12:13:30 +02:00
options_list = options_list_arg ;
if ( options_list . num_options . find ( " max_dim_cova_group " ) ! = options_list . num_options . end ( ) )
if ( atoi ( options_list . num_options [ " max_dim_cova_group " ] . c_str ( ) ) = = 0 )
{
cerr < < " ERROR: The max_dim_cova_group option to identification only accepts integers > 0. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2009-04-20 15:58:15 +02:00
}
void
2012-01-23 16:52:27 +01:00
IdentificationStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2009-04-20 15:58:15 +02:00
{
mod_file_struct . identification_present = true ;
}
void
2015-05-28 11:42:12 +02:00
IdentificationStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2009-04-20 15:58:15 +02:00
{
2009-10-14 18:16:43 +02:00
options_list . writeOutput ( output , " options_ident " ) ;
2012-06-15 11:06:07 +02:00
/* Ensure that nograph, nodisplay and graph_format are also set in top-level
options_ .
\ todo factorize this code between identification and dynare_sensitivity ,
and provide a generic mechanism for this situation ( maybe using regexps ) */
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " nodisplay " ) ;
if ( it ! = options_list . num_options . end ( ) )
2012-06-15 15:35:00 +02:00
output < < " options_.nodisplay = " < < it - > second < < " ; " < < endl ;
2012-06-15 11:06:07 +02:00
it = options_list . num_options . find ( " nograph " ) ;
if ( it ! = options_list . num_options . end ( ) )
2012-06-15 15:35:00 +02:00
output < < " options_.nograph = " < < it - > second < < " ; " < < endl ;
2012-06-15 11:06:07 +02:00
OptionsList : : string_options_t : : const_iterator it2 = options_list . string_options . find ( " graph_format " ) ;
if ( it2 ! = options_list . string_options . end ( ) )
2012-06-15 15:35:00 +02:00
output < < " options_.graph_format = ' " < < it2 - > second < < " '; " < < endl ;
2012-06-15 11:06:07 +02:00
2009-10-14 18:16:43 +02:00
output < < " dynare_identification(options_ident); " < < endl ;
2009-04-20 15:58:15 +02:00
}
2009-04-30 15:14:33 +02:00
2017-02-08 18:29:57 +01:00
void
IdentificationStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" identification \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2017-04-04 15:28:27 +02:00
WriteLatexDynamicModelStatement : : WriteLatexDynamicModelStatement ( const DynamicModel & dynamic_model_arg , bool write_equation_tags_arg ) :
dynamic_model ( dynamic_model_arg ) ,
write_equation_tags ( write_equation_tags_arg )
2009-04-30 15:14:33 +02:00
{
}
void
2015-05-28 11:42:12 +02:00
WriteLatexDynamicModelStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2009-04-30 15:14:33 +02:00
{
2017-04-04 15:28:27 +02:00
dynamic_model . writeLatexFile ( basename , write_equation_tags ) ;
2009-04-30 15:14:33 +02:00
}
2017-02-08 18:29:57 +01:00
void
WriteLatexDynamicModelStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" write_latex_dynamic_model \" } " ;
}
2009-04-30 15:14:33 +02:00
WriteLatexStaticModelStatement : : WriteLatexStaticModelStatement ( const StaticModel & static_model_arg ) :
static_model ( static_model_arg )
{
}
void
2015-05-28 11:42:12 +02:00
WriteLatexStaticModelStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2009-04-30 15:14:33 +02:00
{
static_model . writeLatexFile ( basename ) ;
}
2009-07-23 10:31:48 +02:00
2017-02-08 18:29:57 +01:00
void
WriteLatexStaticModelStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" write_latex_static_model \" } " ;
}
2015-02-16 08:31:30 +01:00
WriteLatexOriginalModelStatement : : WriteLatexOriginalModelStatement ( const DynamicModel & original_model_arg ) :
original_model ( original_model_arg )
{
}
void
2015-05-28 11:42:12 +02:00
WriteLatexOriginalModelStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2015-02-16 08:31:30 +01:00
{
original_model . writeLatexOriginalFile ( basename ) ;
}
2017-02-08 18:29:57 +01:00
void
WriteLatexOriginalModelStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" write_latex_original_model \" } " ;
}
2009-07-23 10:31:48 +02:00
ShockDecompositionStatement : : ShockDecompositionStatement ( const SymbolList & symbol_list_arg ,
2009-12-16 18:13:23 +01:00
const OptionsList & options_list_arg ) :
2009-07-23 10:31:48 +02:00
symbol_list ( symbol_list_arg ) ,
options_list ( options_list_arg )
{
}
void
2015-05-28 11:42:12 +02:00
ShockDecompositionStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2009-07-23 10:31:48 +02:00
{
options_list . writeOutput ( output ) ;
symbol_list . writeOutput ( " var_list_ " , output ) ;
2016-12-15 10:36:16 +01:00
output < < " oo_ = shock_decomposition(M_,oo_,options_,var_list_,bayestopt_,estim_params_); " < < endl ;
2009-07-23 10:31:48 +02:00
}
2017-02-08 18:29:57 +01:00
void
ShockDecompositionStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" shock_decomposition \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
2009-07-23 10:31:48 +02:00
}
2017-03-21 14:58:15 +01:00
RealtimeShockDecompositionStatement : : RealtimeShockDecompositionStatement ( const SymbolList & symbol_list_arg ,
const OptionsList & options_list_arg ) :
symbol_list ( symbol_list_arg ) ,
options_list ( options_list_arg )
{
}
void
RealtimeShockDecompositionStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
options_list . writeOutput ( output ) ;
symbol_list . writeOutput ( " var_list_ " , output ) ;
output < < " oo_ = realtime_shock_decomposition(M_,oo_,options_,var_list_,bayestopt_,estim_params_); " < < endl ;
}
2017-03-22 11:30:35 +01:00
PlotShockDecompositionStatement : : PlotShockDecompositionStatement ( const SymbolList & symbol_list_arg ,
const OptionsList & options_list_arg ) :
symbol_list ( symbol_list_arg ) ,
options_list ( options_list_arg )
{
}
void
PlotShockDecompositionStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
output < < " options_ = set_default_plot_shock_decomposition_options(options_); " < < endl ;
options_list . writeOutput ( output ) ;
symbol_list . writeOutput ( " var_list_ " , output ) ;
output < < " plot_shock_decomposition(M_, oo_, options_, var_list_); " < < endl ;
}
2017-03-21 14:58:15 +01:00
2017-03-31 12:50:17 +02:00
InitialConditionDecompositionStatement : : InitialConditionDecompositionStatement ( const SymbolList & symbol_list_arg ,
const OptionsList & options_list_arg ) :
symbol_list ( symbol_list_arg ) ,
options_list ( options_list_arg )
{
}
void
InitialConditionDecompositionStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
output < < " options_ = set_default_initial_condition_decomposition_options(options_); " < < endl ;
options_list . writeOutput ( output ) ;
symbol_list . writeOutput ( " var_list_ " , output ) ;
output < < " initial_condition_decomposition(M_, oo_, options_, var_list_, bayestopt_, estim_params_); " < < endl ;
}
2017-03-21 14:58:15 +01:00
2009-10-16 19:23:57 +02:00
ConditionalForecastStatement : : ConditionalForecastStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
{
}
void
2015-05-28 11:42:12 +02:00
ConditionalForecastStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2009-10-16 19:23:57 +02:00
{
options_list . writeOutput ( output , " options_cond_fcst_ " ) ;
2014-01-03 12:09:39 +01:00
output < < " imcforecast(constrained_paths_, constrained_vars_, options_cond_fcst_); " < < endl ;
2009-10-16 19:23:57 +02:00
}
2009-07-23 10:31:48 +02:00
2017-02-08 18:29:57 +01:00
void
ConditionalForecastStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" conditional_forecast \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2009-10-16 19:23:57 +02:00
PlotConditionalForecastStatement : : PlotConditionalForecastStatement ( int periods_arg , const SymbolList & symbol_list_arg ) :
periods ( periods_arg ) ,
symbol_list ( symbol_list_arg )
{
}
void
2015-05-28 11:42:12 +02:00
PlotConditionalForecastStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2009-10-16 19:23:57 +02:00
{
symbol_list . writeOutput ( " var_list_ " , output ) ;
2009-10-22 16:42:12 +02:00
if ( periods = = - 1 )
2012-04-28 15:11:49 +02:00
output < < " plot_icforecast(var_list_,[],options_); " < < endl ;
2009-10-22 16:42:12 +02:00
else
2012-04-28 15:11:49 +02:00
output < < " plot_icforecast(var_list_, " < < periods < < " ,options_); " < < endl ;
2009-10-16 19:23:57 +02:00
}
2009-12-04 22:32:19 +01:00
2017-02-08 18:29:57 +01:00
void
PlotConditionalForecastStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" plot_conditional_forecast \" , "
< < " \" periods \" : " < < periods ;
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2011-10-10 11:45:55 +02:00
SvarIdentificationStatement : : SvarIdentificationStatement ( const svar_identification_restrictions_t & restrictions_arg ,
2009-12-04 22:32:19 +01:00
const bool & upper_cholesky_present_arg ,
const bool & lower_cholesky_present_arg ,
2011-07-29 18:11:50 +02:00
const bool & constants_exclusion_present_arg ,
2009-12-04 22:32:19 +01:00
const SymbolTable & symbol_table_arg ) :
2011-10-10 11:45:55 +02:00
restrictions ( restrictions_arg ) ,
2009-12-04 22:32:19 +01:00
upper_cholesky_present ( upper_cholesky_present_arg ) ,
lower_cholesky_present ( lower_cholesky_present_arg ) ,
2011-07-29 18:11:50 +02:00
constants_exclusion_present ( constants_exclusion_present_arg ) ,
2009-12-04 22:32:19 +01:00
symbol_table ( symbol_table_arg )
{
}
int
SvarIdentificationStatement : : getMaxLag ( ) const
{
int max_lag = 0 ;
2011-10-10 11:45:55 +02:00
for ( svar_identification_restrictions_t : : const_iterator it = restrictions . begin ( ) ; it ! = restrictions . end ( ) ; it + + )
if ( it - > lag > max_lag )
max_lag = it - > lag ;
2009-12-04 22:32:19 +01:00
return max_lag ;
}
void
2012-01-23 16:52:27 +01:00
SvarIdentificationStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2009-12-04 22:32:19 +01:00
{
2015-08-24 11:21:06 +02:00
// no equations OK with Svar Identification
mod_file_struct . bvar_present = true ;
2009-12-04 22:32:19 +01:00
if ( ! mod_file_struct . svar_identification_present )
mod_file_struct . svar_identification_present = true ;
else
{
cerr < < " ERROR: You may only have one svar_identification block in your .mod file. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2011-08-03 11:00:11 +02:00
if ( upper_cholesky_present & & lower_cholesky_present )
{
cerr < < " ERROR: Within the svar_identification statement, you may only have one of "
< < " upper_cholesky and lower_cholesky. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2009-12-04 22:32:19 +01:00
}
void
2015-05-28 11:42:12 +02:00
SvarIdentificationStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2009-12-04 22:32:19 +01:00
{
2012-01-03 18:09:14 +01:00
assert ( ! ( upper_cholesky_present & & lower_cholesky_present ) ) ;
2009-12-04 22:32:19 +01:00
output < < " % " < < endl
< < " % SVAR IDENTIFICATION " < < endl
< < " % " < < endl ;
if ( upper_cholesky_present )
output < < " options_.ms.upper_cholesky=1; " < < endl ;
if ( lower_cholesky_present )
output < < " options_.ms.lower_cholesky=1; " < < endl ;
2011-07-29 18:11:50 +02:00
if ( constants_exclusion_present )
output < < " options_.ms.constants_exclusion=1; " < < endl ;
2009-12-04 22:32:19 +01:00
if ( ! upper_cholesky_present & & ! lower_cholesky_present )
{
int n = symbol_table . endo_nbr ( ) ;
2010-03-10 08:32:51 +01:00
int m = 1 ; // this is the constant, not the shocks
2010-03-15 12:03:37 +01:00
int r = getMaxLag ( ) ;
2009-12-04 22:32:19 +01:00
int k = r * n + m ;
2009-12-16 18:13:23 +01:00
if ( k < 1 )
2011-02-04 16:25:38 +01:00
{
cerr < < " ERROR: lag = " < < r
< < " , number of endogenous variables = " < < n
< < " , number of exogenous variables = " < < m
< < " . If this is not a logical error in the specification "
< < " of the .mod file, please report it to the Dynare Team. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2009-12-16 18:13:23 +01:00
if ( n < 1 )
2009-12-04 22:32:19 +01:00
{
cerr < < " ERROR: Number of endogenous variables = " < < n < < " < 1. If this is not a logical "
< < " error in the specification of the .mod file, please report it to the Dynare Team. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2011-08-02 10:49:50 +02:00
output < < " options_.ms.Qi = cell( " < < n < < " ,1); " < < endl ;
output < < " options_.ms.Ri = cell( " < < n < < " ,1); " < < endl ;
2009-12-04 22:32:19 +01:00
2011-10-10 11:45:55 +02:00
for ( svar_identification_restrictions_t : : const_iterator it = restrictions . begin ( ) ; it ! = restrictions . end ( ) ; it + + )
2009-12-04 22:32:19 +01:00
{
2012-01-03 18:09:14 +01:00
assert ( it - > lag > = 0 ) ;
2017-06-01 19:58:32 +02:00
if ( it - > lag = = 0 )
2012-01-03 18:09:14 +01:00
output < < " options_.ms.Qi{ " < < it - > equation < < " }( " < < it - > restriction_nbr < < " , " < < it - > variable + 1 < < " ) = " ;
2017-06-01 19:58:32 +02:00
else
{
int col = ( it - > lag - 1 ) * n + it - > variable + 1 ;
if ( col > k )
2012-01-04 12:11:35 +01:00
{
cerr < < " ERROR: lag = " < < it - > lag < < " , num endog vars = " < < n < < " current endog var index = " < < it - > variable < < " . Index "
< < " out of bounds. If the above does not represent a logical error, please report this to the Dyanre Team. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2017-06-01 19:58:32 +02:00
output < < " options_.ms.Ri{ " < < it - > equation < < " }( " < < it - > restriction_nbr < < " , " < < col < < " ) = " ;
}
2012-01-03 18:09:14 +01:00
it - > value - > writeOutput ( output ) ;
output < < " ; " < < endl ;
2009-12-04 22:32:19 +01:00
}
2015-08-24 11:21:06 +02:00
output < < " options_.ms.nlags = " < < r < < " ; " < < endl ;
2009-12-04 22:32:19 +01:00
}
}
2009-12-08 17:46:13 +01:00
2017-02-08 18:29:57 +01:00
void
SvarIdentificationStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" svar_identification \" " ;
if ( upper_cholesky_present )
output < < " , \" upper_cholesky \" : 1 " ;
if ( lower_cholesky_present )
output < < " , \" lower_cholesky \" : 1 " ;
if ( constants_exclusion_present )
output < < " , \" constants_exclusion \" : 1 " ;
if ( ! upper_cholesky_present & & ! lower_cholesky_present )
{
output < < " , \" nlags \" : " < < getMaxLag ( )
< < " , \" restrictions \" : [ " ;
for ( svar_identification_restrictions_t : : const_iterator it = restrictions . begin ( ) ; it ! = restrictions . end ( ) ; it + + )
{
if ( it ! = restrictions . begin ( ) )
output < < " , " ;
output < < " { "
< < " \" equation_number \" : " < < it - > equation < < " , "
< < " \" restriction_number \" : " < < it - > restriction_nbr < < " , "
2017-02-27 12:23:39 +01:00
< < " \" variable \" : \" " < < symbol_table . getName ( it - > variable ) < < " \" , "
2017-02-08 18:29:57 +01:00
< < " \" expression \" : \" " ;
it - > value - > writeOutput ( output ) ;
output < < " \" } " ;
}
output < < " ] " ;
}
output < < " } " ;
}
2009-12-08 17:46:13 +01:00
MarkovSwitchingStatement : : MarkovSwitchingStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
{
2011-12-19 17:32:02 +01:00
OptionsList : : num_options_t : : const_iterator it_num = options_list . num_options . find ( " ms.restrictions " ) ;
if ( it_num ! = options_list . num_options . end ( ) )
{
using namespace boost ;
2017-06-01 19:58:32 +02:00
OptionsList : : num_options_t : : const_iterator it_num_regimes
= options_list . num_options . find ( " ms.number_of_regimes " ) ;
2012-01-03 18:09:14 +01:00
assert ( it_num_regimes ! = options_list . num_options . end ( ) ) ;
2011-12-19 17:32:02 +01:00
int num_regimes = lexical_cast < int > ( it_num_regimes - > second ) ;
vector < string > tokenizedRestrictions ;
split ( tokenizedRestrictions , it_num - > second , is_any_of ( " [ " ) , token_compress_on ) ;
for ( vector < string > : : iterator it = tokenizedRestrictions . begin ( ) ;
2017-06-01 19:58:32 +02:00
it ! = tokenizedRestrictions . end ( ) ; it + + )
2011-12-19 17:32:02 +01:00
if ( it - > size ( ) > 0 )
{
vector < string > restriction ;
split ( restriction , * it , is_any_of ( " ], " ) ) ;
for ( vector < string > : : iterator it1 = restriction . begin ( ) ;
2017-06-01 19:58:32 +02:00
it1 ! = restriction . end ( ) ; )
2011-12-19 17:32:02 +01:00
if ( it1 - > empty ( ) )
restriction . erase ( it1 ) ;
else
it1 + + ;
if ( restriction . size ( ) ! = 3 )
{
cerr < < " ERROR: restrictions in the subsample statement must be specified in the form "
< < " [current_period_regime, next_period_regime, transition_probability] " < < endl ;
exit ( EXIT_FAILURE ) ;
}
try
{
int from_regime = lexical_cast < int > ( restriction [ 0 ] ) ;
int to_regime = lexical_cast < int > ( restriction [ 1 ] ) ;
if ( from_regime > num_regimes | | to_regime > num_regimes )
{
cerr < < " ERROR: the regimes specified in the restrictions option must be "
< < " <= the number of regimes specified in the number_of_regimes option " < < endl ;
exit ( EXIT_FAILURE ) ;
}
if ( restriction_map . find ( make_pair ( from_regime , to_regime ) ) ! =
restriction_map . end ( ) )
{
cerr < < " ERROR: two restrictions were given for: " < < from_regime < < " , "
< < to_regime < < endl ;
exit ( EXIT_FAILURE ) ;
}
double transition_probability = lexical_cast < double > ( restriction [ 2 ] ) ;
if ( transition_probability > 1.0 )
{
cerr < < " ERROR: the transition probability, " < < transition_probability
< < " must be less than 1 " < < endl ;
exit ( EXIT_FAILURE ) ;
}
restriction_map [ make_pair ( from_regime , to_regime ) ] = transition_probability ;
}
catch ( const bad_lexical_cast & )
{
cerr < < " ERROR: The first two arguments for a restriction must be integers "
< < " specifying the regime and the last must be a double specifying the "
< < " transition probability. You wrote [ " < < * it < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
}
}
void
2012-01-23 16:52:27 +01:00
MarkovSwitchingStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2011-12-19 17:32:02 +01:00
{
2012-01-03 16:51:52 +01:00
OptionsList : : num_options_t : : const_iterator itChain = options_list . num_options . find ( " ms.chain " ) ;
assert ( itChain ! = options_list . num_options . end ( ) ) ;
int chainNumber = atoi ( itChain - > second . c_str ( ) ) ;
if ( + + mod_file_struct . last_markov_switching_chain ! = chainNumber )
{
cerr < < " ERROR: The markov_switching chain option takes consecutive integers "
< < " beginning at 1. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2011-12-19 17:32:02 +01:00
OptionsList : : num_options_t : : const_iterator it_num = options_list . num_options . find ( " ms.restrictions " ) ;
if ( it_num ! = options_list . num_options . end ( ) )
{
using namespace boost ;
2017-06-01 19:58:32 +02:00
OptionsList : : num_options_t : : const_iterator it_num_regimes
= options_list . num_options . find ( " ms.number_of_regimes " ) ;
2012-01-03 18:27:12 +01:00
assert ( it_num_regimes ! = options_list . num_options . end ( ) ) ;
2011-12-19 17:32:02 +01:00
int num_regimes = lexical_cast < int > ( it_num_regimes - > second ) ;
2017-06-01 19:58:32 +02:00
vector < double > col_trans_prob_sum ( num_regimes , 0 ) ;
vector < double > row_trans_prob_sum ( num_regimes , 0 ) ;
vector < bool > all_restrictions_in_row ( num_regimes , true ) ;
vector < bool > all_restrictions_in_col ( num_regimes , true ) ;
for ( int row = 0 ; row < num_regimes ; row + + )
for ( int col = 0 ; col < num_regimes ; col + + )
2011-12-19 17:32:02 +01:00
if ( restriction_map . find ( make_pair ( row + 1 , col + 1 ) ) ! = restriction_map . end ( ) )
{
row_trans_prob_sum [ row ] + = restriction_map [ make_pair ( row + 1 , col + 1 ) ] ;
col_trans_prob_sum [ col ] + = restriction_map [ make_pair ( row + 1 , col + 1 ) ] ;
}
else
{
all_restrictions_in_row [ row ] = false ;
all_restrictions_in_col [ col ] = false ;
}
2017-06-01 19:58:32 +02:00
for ( int i = 0 ; i < num_regimes ; i + + )
2011-12-19 17:32:02 +01:00
{
if ( all_restrictions_in_row [ i ] )
2017-06-01 19:58:32 +02:00
{
if ( row_trans_prob_sum [ i ] ! = 1.0 )
{
cerr < < " ERROR: When all transitions probabilities are specified for a certain "
< < " regime, they must sum to 1 " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
else
if ( row_trans_prob_sum [ i ] > = 1.0 )
2011-12-19 17:32:02 +01:00
{
2017-06-01 19:58:32 +02:00
cerr < < " ERROR: When transition probabilites are not specified for every regime, "
< < " their sum must be < 1 " < < endl ;
2011-12-19 17:32:02 +01:00
exit ( EXIT_FAILURE ) ;
}
2017-06-01 19:58:32 +02:00
if ( all_restrictions_in_col [ i ] )
2011-12-19 17:32:02 +01:00
{
2017-06-01 19:58:32 +02:00
if ( col_trans_prob_sum [ i ] ! = 1.0 )
{
cerr < < " ERROR: When all transitions probabilities are specified for a certain "
< < " regime, they must sum to 1 " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2011-12-19 17:32:02 +01:00
}
2017-06-01 19:58:32 +02:00
else
if ( col_trans_prob_sum [ i ] > = 1.0 )
2011-12-19 17:32:02 +01:00
{
2017-06-01 19:58:32 +02:00
cerr < < " ERROR: When transition probabilites are not specified for every regime, "
< < " their sum must be < 1 " < < endl ;
2011-12-19 17:32:02 +01:00
exit ( EXIT_FAILURE ) ;
}
}
}
2013-08-06 21:20:36 +02:00
if ( options_list . symbol_list_options . find ( " ms.parameters " ) ! = options_list . symbol_list_options . end ( ) )
mod_file_struct . ms_dsge_present = true ;
2009-12-08 17:46:13 +01:00
}
void
2015-05-28 11:42:12 +02:00
MarkovSwitchingStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2009-12-08 17:46:13 +01:00
{
2011-12-19 15:57:28 +01:00
bool isDurationAVec = true ;
string infStr ( " Inf " ) ;
OptionsList : : num_options_t : : const_iterator itChain , itNOR , itDuration ;
2011-12-19 17:32:02 +01:00
map < pair < int , int > , double > : : const_iterator itR ;
2009-12-08 17:46:13 +01:00
itChain = options_list . num_options . find ( " ms.chain " ) ;
2012-01-03 18:09:14 +01:00
assert ( itChain ! = options_list . num_options . end ( ) ) ;
2009-12-08 17:46:13 +01:00
itDuration = options_list . num_options . find ( " ms.duration " ) ;
2012-01-03 18:09:14 +01:00
assert ( itDuration ! = options_list . num_options . end ( ) ) ;
if ( atof ( itDuration - > second . c_str ( ) ) | | infStr . compare ( itDuration - > second ) = = 0 )
2011-12-19 15:57:28 +01:00
isDurationAVec = false ;
output < < " options_.ms.duration = " < < itDuration - > second < < " ; " < < endl ;
2009-12-08 17:46:13 +01:00
2011-12-16 11:18:24 +01:00
itNOR = options_list . num_options . find ( " ms.number_of_regimes " ) ;
2012-01-03 18:09:14 +01:00
assert ( itNOR ! = options_list . num_options . end ( ) ) ;
for ( int i = 0 ; i < atoi ( itNOR - > second . c_str ( ) ) ; i + + )
2009-12-08 17:46:13 +01:00
{
2012-01-03 18:09:14 +01:00
output < < " options_.ms.ms_chain( " < < itChain - > second < < " ).regime( "
< < i + 1 < < " ).duration = options_.ms.duration " ;
if ( isDurationAVec )
output < < " ( " < < i + 1 < < " ) " ;
output < < " ; " < < endl ;
2009-12-08 17:46:13 +01:00
}
2011-12-19 17:32:02 +01:00
int restrictions_index = 0 ;
2017-06-01 19:58:32 +02:00
for ( itR = restriction_map . begin ( ) ; itR ! = restriction_map . end ( ) ; itR + + )
2011-12-19 17:32:02 +01:00
output < < " options_.ms.ms_chain( " < < itChain - > second < < " ).restrictions( "
< < + + restrictions_index < < " ) = {[ " < < itR - > first . first < < " , "
< < itR - > first . second < < " , " < < itR - > second < < " ]}; " < < endl ;
2009-12-08 17:46:13 +01:00
}
2009-12-09 01:38:53 +01:00
2013-08-06 21:29:11 +02:00
void
MarkovSwitchingStatement : : writeCOutput ( ostream & output , const string & basename )
{
output < < endl ;
2017-06-01 19:58:32 +02:00
OptionsList : : num_options_t : : const_iterator it
= options_list . num_options . find ( " ms.chain " ) ;
2013-08-06 21:29:11 +02:00
assert ( it ! = options_list . num_options . end ( ) ) ;
output < < " chain = " < < it - > second < < " ; " < < endl ;
it = options_list . num_options . find ( " ms.number_of_regimes " ) ;
assert ( it ! = options_list . num_options . end ( ) ) ;
output < < " number_of_regimes = " < < it - > second < < " ; " < < endl ;
it = options_list . num_options . find ( " ms.number_of_lags " ) ;
if ( it ! = options_list . num_options . end ( ) )
output < < " number_of_lags = " < < it - > second < < " ; " < < endl
< < " number_of_lags_was_passed = true; " < < endl ;
else
output < < " number_of_lags_was_passed = false; " < < endl ;
it = options_list . num_options . find ( " ms.duration " ) ;
assert ( it ! = options_list . num_options . end ( ) ) ;
output < < " duration.clear(); " < < endl ;
using namespace boost ;
vector < string > tokenizedDomain ;
split ( tokenizedDomain , it - > second , is_any_of ( " [ ] " ) , token_compress_on ) ;
for ( vector < string > : : iterator itvs = tokenizedDomain . begin ( ) ;
2017-06-01 19:58:32 +02:00
itvs ! = tokenizedDomain . end ( ) ; itvs + + )
2013-08-06 21:29:11 +02:00
if ( ! itvs - > empty ( ) )
output < < " duration.push_back( " < < * itvs < < " ); " < < endl ;
2017-06-01 19:58:32 +02:00
OptionsList : : symbol_list_options_t : : const_iterator itsl
= options_list . symbol_list_options . find ( " ms.parameters " ) ;
2013-08-06 21:29:11 +02:00
assert ( itsl ! = options_list . symbol_list_options . end ( ) ) ;
vector < string > parameters = itsl - > second . get_symbols ( ) ;
output < < " parameters.clear(); " < < endl ;
for ( vector < string > : : iterator itp = parameters . begin ( ) ;
2017-06-01 19:58:32 +02:00
itp ! = parameters . end ( ) ; itp + + )
2013-08-06 21:29:11 +02:00
output < < " parameters.push_back(param_names[ \" " < < * itp < < " \" ]); " < < endl ;
output < < " restriction_map.clear(); " < < endl ;
for ( map < pair < int , int > , double > : : iterator itrm = restriction_map . begin ( ) ;
itrm ! = restriction_map . end ( ) ; itrm + + )
output < < " restriction_map[make_pair( " < < itrm - > first . first < < " , "
< < itrm - > first . second < < " )] = " < < itrm - > second < < " ; " < < endl ;
output < < " msdsgeinfo->addMarkovSwitching(new MarkovSwitching( " < < endl
< < " chain, number_of_regimes, number_of_lags, number_of_lags_was_passed, parameters, duration, restriction_map)); " < < endl ;
}
2017-02-08 18:29:57 +01:00
void
MarkovSwitchingStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" markov_switching \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! restriction_map . empty ( ) )
output < < " , { " ;
for ( map < pair < int , int > , double > : : const_iterator it = restriction_map . begin ( ) ;
it ! = restriction_map . end ( ) ; it + + )
{
if ( it ! = restriction_map . begin ( ) )
output < < " , " ;
output < < " { \" current_period_regime \" : " < < it - > first . first
< < " , \" next_period_regime \" : " < < it - > first . second
< < " , \" transition_probability \" : " < < it - > second
< < " } " ;
}
if ( ! restriction_map . empty ( ) )
output < < " } " ;
output < < " } " ;
}
2009-12-09 01:38:53 +01:00
SvarStatement : : SvarStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
{
}
2012-01-03 18:09:14 +01:00
void
2012-01-23 16:52:27 +01:00
SvarStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2012-01-03 18:09:14 +01:00
{
OptionsList : : num_options_t : : const_iterator it0 , it1 , it2 ;
it0 = options_list . string_options . find ( " ms.coefficients " ) ;
it1 = options_list . string_options . find ( " ms.variances " ) ;
it2 = options_list . string_options . find ( " ms.constants " ) ;
assert ( ( it0 ! = options_list . string_options . end ( )
& & it1 = = options_list . string_options . end ( )
2017-06-01 19:58:32 +02:00
& & it2 = = options_list . string_options . end ( ) )
| | ( it0 = = options_list . string_options . end ( )
& & it1 ! = options_list . string_options . end ( )
& & it2 = = options_list . string_options . end ( ) )
| | ( it0 = = options_list . string_options . end ( )
& & it1 = = options_list . string_options . end ( )
& & it2 ! = options_list . string_options . end ( ) ) ) ;
2012-01-03 18:09:14 +01:00
}
2009-12-09 01:38:53 +01:00
void
2015-05-28 11:42:12 +02:00
SvarStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2009-12-09 01:38:53 +01:00
{
2010-09-16 19:00:48 +02:00
OptionsList : : num_options_t : : const_iterator it0 , it1 , it2 ;
OptionsList : : vec_int_options_t : : const_iterator itv ;
2009-12-09 01:38:53 +01:00
it0 = options_list . num_options . find ( " ms.chain " ) ;
2012-01-03 18:09:14 +01:00
assert ( it0 ! = options_list . num_options . end ( ) ) ;
output < < " options_.ms.ms_chain( " < < it0 - > second < < " ) " ;
2009-12-09 01:38:53 +01:00
it0 = options_list . string_options . find ( " ms.coefficients " ) ;
it1 = options_list . string_options . find ( " ms.variances " ) ;
it2 = options_list . string_options . find ( " ms.constants " ) ;
2012-01-03 18:09:14 +01:00
if ( it0 ! = options_list . string_options . end ( ) )
2009-12-09 01:38:53 +01:00
output < < " . " < < it0 - > second ;
2012-01-03 18:09:14 +01:00
else if ( it1 ! = options_list . string_options . end ( ) )
2009-12-09 01:38:53 +01:00
output < < " . " < < it1 - > second ;
else
2012-01-03 18:09:14 +01:00
output < < " . " < < it2 - > second ;
2009-12-09 01:38:53 +01:00
2009-12-10 23:49:50 +01:00
itv = options_list . vector_int_options . find ( " ms.equations " ) ;
output < < " .equations = " ;
if ( itv ! = options_list . vector_int_options . end ( ) )
{
2012-01-03 18:09:14 +01:00
assert ( itv - > second . size ( ) > = 1 ) ;
2009-12-10 23:49:50 +01:00
if ( itv - > second . size ( ) > 1 )
{
output < < " [ " ;
2009-12-16 18:13:23 +01:00
for ( vector < int > : : const_iterator viit = itv - > second . begin ( ) ;
viit ! = itv - > second . end ( ) ; viit + + )
2009-12-10 23:49:50 +01:00
output < < * viit < < " ; " ;
output < < " ]; " < < endl ;
}
else
2012-01-03 18:09:14 +01:00
output < < itv - > second . front ( ) < < " ; " < < endl ;
2009-12-10 23:49:50 +01:00
}
2009-12-09 01:38:53 +01:00
else
2009-12-10 23:49:50 +01:00
output < < " 'ALL'; " < < endl ;
2009-12-09 01:38:53 +01:00
}
2011-11-29 17:14:26 +01:00
2017-02-08 18:29:57 +01:00
void
SvarStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" svar \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2015-08-24 11:21:06 +02:00
SvarGlobalIdentificationCheckStatement : : SvarGlobalIdentificationCheckStatement ( void )
{
}
void
SvarGlobalIdentificationCheckStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
output < < " svar_global_identification_check(options_); " < < std : : endl ;
}
2017-02-08 18:29:57 +01:00
void
SvarGlobalIdentificationCheckStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" svar_global_identification \" } " ;
}
2011-11-29 17:14:26 +01:00
SetTimeStatement : : SetTimeStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
{
}
void
2015-05-28 11:42:12 +02:00
SetTimeStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2011-11-29 17:14:26 +01:00
{
options_list . writeOutput ( output ) ;
}
2011-12-06 15:42:57 +01:00
2017-02-08 18:29:57 +01:00
void
SetTimeStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" set_time \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2011-12-06 15:42:57 +01:00
EstimationDataStatement : : EstimationDataStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
{
}
void
2012-01-23 16:52:27 +01:00
EstimationDataStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2011-12-06 15:42:57 +01:00
{
mod_file_struct . estimation_data_statement_present = true ;
OptionsList : : num_options_t : : const_iterator it = options_list . num_options . find ( " nobs " ) ;
if ( it ! = options_list . num_options . end ( ) )
if ( atoi ( it - > second . c_str ( ) ) < = 0 )
{
cerr < < " ERROR: The nobs option of the data statement only accepts positive integers. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2017-06-01 19:58:32 +02:00
if ( ( options_list . string_options . find ( " file " ) = = options_list . string_options . end ( ) )
& & ( options_list . string_options . find ( " series " ) = = options_list . string_options . end ( ) ) )
2011-12-06 15:42:57 +01:00
{
2014-06-17 16:03:30 +02:00
cerr < < " ERROR: The file or series option must be passed to the data statement. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2017-06-01 19:58:32 +02:00
if ( ( options_list . string_options . find ( " file " ) ! = options_list . string_options . end ( ) )
& & ( options_list . string_options . find ( " series " ) ! = options_list . string_options . end ( ) ) )
2014-06-17 16:03:30 +02:00
{
cerr < < " ERROR: The file and series options cannot be used simultaneously in the data statement. " < < endl ;
2011-12-06 15:42:57 +01:00
exit ( EXIT_FAILURE ) ;
}
}
void
2015-05-28 11:42:12 +02:00
EstimationDataStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2011-12-06 15:42:57 +01:00
{
options_list . writeOutput ( output , " options_.dataset " ) ;
}
2011-12-11 15:35:26 +01:00
2017-02-08 18:29:57 +01:00
void
EstimationDataStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" estimation_data \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2012-03-28 16:19:10 +02:00
SubsamplesStatement : : SubsamplesStatement ( const string & name1_arg ,
const string & name2_arg ,
2012-04-02 17:54:05 +02:00
const subsample_declaration_map_t subsample_declaration_map_arg ,
const SymbolTable & symbol_table_arg ) :
2012-03-28 16:19:10 +02:00
name1 ( name1_arg ) ,
name2 ( name2_arg ) ,
2012-04-02 17:54:05 +02:00
subsample_declaration_map ( subsample_declaration_map_arg ) ,
symbol_table ( symbol_table_arg )
2012-03-28 16:19:10 +02:00
{
}
void
SubsamplesStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
}
void
2015-05-28 11:42:12 +02:00
SubsamplesStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2012-03-28 16:19:10 +02:00
{
2012-03-29 15:21:32 +02:00
output < < " subsamples_indx = get_new_or_existing_ei_index('subsamples_index', ' "
< < name1 < < " ',' " < < name2 < < " '); " < < endl
2012-03-28 16:19:10 +02:00
< < " estimation_info.subsamples_index(subsamples_indx) = {' " < < name1 ;
if ( ! name2 . empty ( ) )
2012-03-30 14:04:06 +02:00
output < < " : " < < name2 ;
2012-03-28 16:19:10 +02:00
output < < " '}; " < < endl
2012-04-02 19:02:43 +02:00
< < " estimation_info.subsamples(subsamples_indx).range = {}; " < < endl
< < " estimation_info.subsamples(subsamples_indx).range_index = {}; " < < endl ;
2012-03-28 16:19:10 +02:00
int map_indx = 1 ;
for ( subsample_declaration_map_t : : const_iterator it = subsample_declaration_map . begin ( ) ;
it ! = subsample_declaration_map . end ( ) ; it + + , map_indx + + )
output < < " estimation_info.subsamples(subsamples_indx).range_index( " < < map_indx < < " ) = {' "
< < it - > first < < " '}; " < < endl
2013-10-11 16:28:14 +02:00
< < " estimation_info.subsamples(subsamples_indx).range( " < < map_indx < < " ).date1 = "
2014-03-25 15:42:33 +01:00
< < it - > second . first < < " ; " < < endl
2013-10-11 16:28:14 +02:00
< < " estimation_info.subsamples(subsamples_indx).range( " < < map_indx < < " ).date2 = "
2014-03-25 15:42:33 +01:00
< < it - > second . second < < " ; " < < endl ;
2012-04-02 17:54:05 +02:00
// Initialize associated subsample substructures in estimation_info
const SymbolType symb_type = symbol_table . getType ( name1 ) ;
string lhs_field ;
if ( symb_type = = eParameter )
lhs_field = " parameter " ;
else if ( symb_type = = eExogenous | | symb_type = = eExogenousDet )
lhs_field = " structural_innovation " ;
else
lhs_field = " measurement_error " ;
output < < " eifind = get_new_or_existing_ei_index(' " < < lhs_field ;
if ( ! name2 . empty ( ) )
output < < " _corr " ;
output < < " _prior_index', ' "
< < name1 < < " ', ' " ;
if ( ! name2 . empty ( ) )
output < < name2 ;
output < < " '); " < < endl ;
lhs_field = " estimation_info. " + lhs_field ;
if ( ! name2 . empty ( ) )
lhs_field + = " _corr " ;
output < < lhs_field < < " _prior_index(eifind) = {' " < < name1 ;
if ( ! name2 . empty ( ) )
output < < " : " < < name2 ;
output < < " '}; " < < endl ;
output < < lhs_field < < " (eifind).subsample_prior = estimation_info.empty_prior; " < < endl
< < lhs_field < < " (eifind).subsample_prior(1: " < < subsample_declaration_map . size ( )
< < " ) = estimation_info.empty_prior; " < < endl
< < lhs_field < < " (eifind).range_index = estimation_info.subsamples(subsamples_indx).range_index; "
< < endl ;
2012-03-28 16:19:10 +02:00
}
2017-02-08 18:29:57 +01:00
void
SubsamplesStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" subsamples \" "
< < " , \" name1 \" : \" " < < name1 < < " \" " ;
if ( ! name2 . empty ( ) )
output < < " , \" name2 \" : \" " < < name2 < < " \" " ;
output < < " , \" declarations \" : { " ;
for ( subsample_declaration_map_t : : const_iterator it = subsample_declaration_map . begin ( ) ;
it ! = subsample_declaration_map . end ( ) ; it + + )
{
if ( it ! = subsample_declaration_map . begin ( ) )
output < < " , " ;
output < < " { "
< < " \" range_index \" : \" " < < it - > first < < " \" "
< < " , \" date1 \" : \" " < < it - > second . first < < " \" "
< < " , \" date2 \" : \" " < < it - > second . second < < " \" "
< < " } " ;
}
output < < " } "
< < " } " ;
}
2012-03-28 16:19:10 +02:00
SubsamplesEqualStatement : : SubsamplesEqualStatement ( const string & to_name1_arg ,
const string & to_name2_arg ,
const string & from_name1_arg ,
2012-04-02 18:06:19 +02:00
const string & from_name2_arg ,
const SymbolTable & symbol_table_arg ) :
2012-03-28 16:19:10 +02:00
to_name1 ( to_name1_arg ) ,
to_name2 ( to_name2_arg ) ,
from_name1 ( from_name1_arg ) ,
2012-04-02 18:06:19 +02:00
from_name2 ( from_name2_arg ) ,
symbol_table ( symbol_table_arg )
2012-03-28 16:19:10 +02:00
{
}
void
2015-05-28 11:42:12 +02:00
SubsamplesEqualStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2012-03-28 16:19:10 +02:00
{
2012-03-29 15:21:32 +02:00
output < < " subsamples_to_indx = get_new_or_existing_ei_index('subsamples_index', ' "
< < to_name1 < < " ',' " < < to_name2 < < " '); " < < endl
2012-03-28 16:19:10 +02:00
< < " estimation_info.subsamples_index(subsamples_to_indx) = {' " < < to_name1 ;
if ( ! to_name2 . empty ( ) )
2012-03-30 14:04:06 +02:00
output < < " : " < < to_name2 ;
2012-03-28 16:19:10 +02:00
output < < " '}; " < < endl
< < " subsamples_from_indx = get_existing_subsamples_indx(' " < < from_name1 < < " ',' " < < from_name2 < < " '); "
< < endl
< < " estimation_info.subsamples(subsamples_to_indx) = estimation_info.subsamples(subsamples_from_indx); "
< < endl ;
2012-04-02 18:06:19 +02:00
// Initialize associated subsample substructures in estimation_info
const SymbolType symb_type = symbol_table . getType ( to_name1 ) ;
string lhs_field ;
if ( symb_type = = eParameter )
lhs_field = " parameter " ;
else if ( symb_type = = eExogenous | | symb_type = = eExogenousDet )
lhs_field = " structural_innovation " ;
else
lhs_field = " measurement_error " ;
output < < " eifind = get_new_or_existing_ei_index(' " < < lhs_field ;
if ( ! to_name2 . empty ( ) )
output < < " _corr " ;
output < < " _prior_index', ' "
< < to_name1 < < " ', ' " ;
if ( ! to_name2 . empty ( ) )
output < < to_name2 ;
output < < " '); " < < endl ;
lhs_field = " estimation_info. " + lhs_field ;
if ( ! to_name2 . empty ( ) )
lhs_field + = " _corr " ;
output < < lhs_field < < " _prior_index(eifind) = {' " < < to_name1 ;
if ( ! to_name2 . empty ( ) )
output < < " : " < < to_name2 ;
output < < " '}; " < < endl ;
output < < lhs_field < < " (eifind).subsample_prior = estimation_info.empty_prior; " < < endl
< < lhs_field < < " (eifind).subsample_prior(1:size(estimation_info.subsamples(subsamples_to_indx).range_index,2)) = estimation_info.empty_prior; "
< < endl
< < lhs_field < < " (eifind).range_index = estimation_info.subsamples(subsamples_to_indx).range_index; "
< < endl ;
2012-03-28 16:19:10 +02:00
}
2017-02-08 18:29:57 +01:00
void
SubsamplesEqualStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" subsamples_equal \" "
< < " , \" to_name1 \" : \" " < < to_name1 < < " \" " ;
if ( ! to_name2 . empty ( ) )
output < < " , \" to_name2 \" : \" " < < to_name2 < < " \" " ;
output < < " , \" from_name1 \" : \" " < < from_name1 < < " \" " ;
if ( ! from_name2 . empty ( ) )
output < < " , \" from_name2 \" : \" " < < from_name2 < < " \" " ;
output < < " } " ;
}
2015-03-03 15:08:33 +01:00
JointPriorStatement : : JointPriorStatement ( const vector < string > joint_parameters_arg ,
const PriorDistributions & prior_shape_arg ,
const OptionsList & options_list_arg ) :
joint_parameters ( joint_parameters_arg ) ,
prior_shape ( prior_shape_arg ) ,
options_list ( options_list_arg )
{
}
void
JointPriorStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
if ( joint_parameters . size ( ) < 2 )
{
cerr < < " ERROR: you must pass at least two parameters to the joint prior statement " < < endl ;
exit ( EXIT_FAILURE ) ;
}
if ( prior_shape = = eNoShape )
{
cerr < < " ERROR: You must pass the shape option to the prior statement. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2017-06-01 19:58:32 +02:00
if ( options_list . num_options . find ( " mean " ) = = options_list . num_options . end ( )
& & options_list . num_options . find ( " mode " ) = = options_list . num_options . end ( ) )
2015-03-03 15:08:33 +01:00
{
cerr < < " ERROR: You must pass at least one of mean and mode to the prior statement. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
OptionsList : : num_options_t : : const_iterator it_num = options_list . num_options . find ( " domain " ) ;
if ( it_num ! = options_list . num_options . end ( ) )
{
using namespace boost ;
vector < string > tokenizedDomain ;
split ( tokenizedDomain , it_num - > second , is_any_of ( " [ ] " ) , token_compress_on ) ;
if ( tokenizedDomain . size ( ) ! = 4 )
{
cerr < < " ERROR: You must pass exactly two values to the domain option. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
}
void
2015-05-28 11:42:12 +02:00
JointPriorStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2015-03-03 15:08:33 +01:00
{
2017-06-01 19:58:32 +02:00
for ( vector < string > : : const_iterator it = joint_parameters . begin ( ) ; it ! = joint_parameters . end ( ) ; it + + )
2015-03-03 15:08:33 +01:00
output < < " eifind = get_new_or_existing_ei_index('joint_parameter_prior_index', ' "
< < * it < < " ', ''); " < < endl
< < " estimation_info.joint_parameter_prior_index(eifind) = {' " < < * it < < " '}; " < < endl ;
output < < " key = {[ " ;
2017-06-01 19:58:32 +02:00
for ( vector < string > : : const_iterator it = joint_parameters . begin ( ) ; it ! = joint_parameters . end ( ) ; it + + )
2015-03-03 15:08:33 +01:00
output < < " get_new_or_existing_ei_index('joint_parameter_prior_index', ' " < < * it < < " ', '') ... "
< < endl < < " " ;
output < < " ]}; " < < endl ;
string lhs_field ( " estimation_info.joint_parameter_tmp " ) ;
writeOutputHelper ( output , " domain " , lhs_field ) ;
writeOutputHelper ( output , " interval " , lhs_field ) ;
writeOutputHelper ( output , " mean " , lhs_field ) ;
writeOutputHelper ( output , " median " , lhs_field ) ;
writeOutputHelper ( output , " mode " , lhs_field ) ;
assert ( prior_shape ! = eNoShape ) ;
output < < lhs_field < < " .shape = " < < prior_shape < < " ; " < < endl ;
writeOutputHelper ( output , " shift " , lhs_field ) ;
writeOutputHelper ( output , " stdev " , lhs_field ) ;
writeOutputHelper ( output , " truncate " , lhs_field ) ;
writeOutputHelper ( output , " variance " , lhs_field ) ;
2015-03-09 17:58:06 +01:00
output < < " estimation_info.joint_parameter_tmp = [key, ... " < < endl
2015-03-03 15:08:33 +01:00
< < " " < < lhs_field < < " .domain , ... " < < endl
< < " " < < lhs_field < < " .interval , ... " < < endl
< < " " < < lhs_field < < " .mean , ... " < < endl
< < " " < < lhs_field < < " .median , ... " < < endl
< < " " < < lhs_field < < " .mode , ... " < < endl
< < " " < < lhs_field < < " .shape , ... " < < endl
< < " " < < lhs_field < < " .shift , ... " < < endl
< < " " < < lhs_field < < " .stdev , ... " < < endl
< < " " < < lhs_field < < " .truncate , ... " < < endl
2015-03-09 17:58:06 +01:00
< < " " < < lhs_field < < " .variance]; " < < endl
< < " estimation_info.joint_parameter = [estimation_info.joint_parameter; estimation_info.joint_parameter_tmp]; " < < endl
< < " estimation_info=rmfield(estimation_info, 'joint_parameter_tmp'); " < < endl ;
2015-03-03 15:08:33 +01:00
}
void
JointPriorStatement : : writeOutputHelper ( ostream & output , const string & field , const string & lhs_field ) const
{
OptionsList : : num_options_t : : const_iterator itn = options_list . num_options . find ( field ) ;
output < < lhs_field < < " . " < < field < < " = { " ;
2017-06-01 19:58:32 +02:00
if ( field = = " variance " )
2015-03-09 17:58:06 +01:00
output < < " { " ;
2015-03-03 15:08:33 +01:00
if ( itn ! = options_list . num_options . end ( ) )
output < < itn - > second ;
else
output < < " {} " ;
2017-06-01 19:58:32 +02:00
if ( field = = " variance " )
2015-03-09 17:58:06 +01:00
output < < " } " ;
2015-03-03 15:08:33 +01:00
output < < " }; " < < endl ;
}
2017-02-08 18:29:57 +01:00
void
JointPriorStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" joint_prior \" "
< < " , \" key \" : [ " ;
2017-06-14 07:01:31 +02:00
for ( vector < string > : : const_iterator it = joint_parameters . begin ( ) ; it ! = joint_parameters . end ( ) ; it + + )
2017-02-08 18:29:57 +01:00
{
if ( it ! = joint_parameters . begin ( ) )
output < < " , " ;
output < < " \" " < < * it < < " \" " ;
}
output < < " ] " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " , \" shape \" : " ;
2017-06-14 07:01:31 +02:00
switch ( prior_shape )
2017-02-08 18:29:57 +01:00
{
case eBeta :
2017-06-14 07:01:31 +02:00
output < < " \" beta \" " ;
2017-02-08 18:29:57 +01:00
break ;
case eGamma :
2017-06-14 07:01:31 +02:00
output < < " \" gamma \" " ;
2017-02-08 18:29:57 +01:00
break ;
case eNormal :
2017-06-14 07:01:31 +02:00
output < < " \" normal \" " ;
2017-02-08 18:29:57 +01:00
break ;
case eInvGamma :
2017-06-14 07:01:31 +02:00
output < < " \" inv_gamma \" " ;
2017-02-08 18:29:57 +01:00
break ;
case eUniform :
2017-06-14 07:01:31 +02:00
output < < " \" uniform \" " ;
2017-02-08 18:29:57 +01:00
break ;
case eInvGamma2 :
2017-06-14 07:01:31 +02:00
output < < " \" inv_gamma2 \" " ;
2017-02-08 18:29:57 +01:00
break ;
case eDirichlet :
2017-06-14 07:01:31 +02:00
output < < " \" dirichlet \" " ;
2017-02-08 18:29:57 +01:00
break ;
case eWeibull :
2017-06-14 07:01:31 +02:00
output < < " \" weibull \" " ;
2017-02-08 18:29:57 +01:00
break ;
case eNoShape :
cerr < < " Impossible case. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
output < < " } " ;
}
2015-03-03 15:08:33 +01:00
2011-12-11 15:35:26 +01:00
BasicPriorStatement : : ~ BasicPriorStatement ( )
{
}
BasicPriorStatement : : BasicPriorStatement ( const string & name_arg ,
2012-03-28 16:19:10 +02:00
const string & subsample_name_arg ,
2011-12-29 18:43:21 +01:00
const PriorDistributions & prior_shape_arg ,
2011-12-11 15:35:26 +01:00
const expr_t & variance_arg ,
const OptionsList & options_list_arg ) :
name ( name_arg ) ,
2012-03-28 16:19:10 +02:00
subsample_name ( subsample_name_arg ) ,
2011-12-29 18:43:21 +01:00
prior_shape ( prior_shape_arg ) ,
2011-12-11 15:35:26 +01:00
variance ( variance_arg ) ,
2012-03-29 15:21:32 +02:00
options_list ( options_list_arg )
2011-12-11 15:35:26 +01:00
{
}
void
2012-01-23 16:52:27 +01:00
BasicPriorStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2011-12-11 15:35:26 +01:00
{
2011-12-30 17:09:07 +01:00
if ( prior_shape = = eNoShape )
2011-12-11 15:35:26 +01:00
{
cerr < < " ERROR: You must pass the shape option to the prior statement. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2012-01-02 22:44:50 +01:00
2017-06-01 19:58:32 +02:00
if ( options_list . num_options . find ( " mean " ) = = options_list . num_options . end ( )
& & options_list . num_options . find ( " mode " ) = = options_list . num_options . end ( ) )
2012-03-28 19:07:08 +02:00
{
cerr < < " ERROR: You must pass at least one of mean and mode to the prior statement. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
OptionsList : : num_options_t : : const_iterator it_stdev = options_list . num_options . find ( " stdev " ) ;
2017-06-01 19:58:32 +02:00
if ( ( it_stdev = = options_list . num_options . end ( ) & & variance = = NULL )
| | ( it_stdev ! = options_list . num_options . end ( ) & & variance ! = NULL ) )
2012-03-28 19:07:08 +02:00
{
2013-08-06 22:02:55 +02:00
cerr < < " ERROR: You must pass exactly one of stdev and variance to the prior statement. " < < endl ;
2012-03-28 19:07:08 +02:00
exit ( EXIT_FAILURE ) ;
}
2012-01-02 22:44:50 +01:00
OptionsList : : num_options_t : : const_iterator it_num = options_list . num_options . find ( " domain " ) ;
if ( it_num ! = options_list . num_options . end ( ) )
{
using namespace boost ;
vector < string > tokenizedDomain ;
split ( tokenizedDomain , it_num - > second , is_any_of ( " [ ] " ) , token_compress_on ) ;
if ( tokenizedDomain . size ( ) ! = 4 )
{
cerr < < " ERROR: You must pass exactly two values to the domain option. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
2011-12-11 15:35:26 +01:00
}
2013-08-06 21:29:11 +02:00
bool
BasicPriorStatement : : is_structural_innovation ( const SymbolType symb_type ) const
{
if ( symb_type = = eExogenous | | symb_type = = eExogenousDet )
return true ;
return false ;
}
2011-12-11 15:35:26 +01:00
void
BasicPriorStatement : : get_base_name ( const SymbolType symb_type , string & lhs_field ) const
{
if ( symb_type = = eExogenous | | symb_type = = eExogenousDet )
lhs_field = " structural_innovation " ;
else
lhs_field = " measurement_error " ;
}
void
2012-03-26 16:46:44 +02:00
BasicPriorStatement : : writeCommonOutput ( ostream & output , const string & lhs_field ) const
2011-12-11 15:35:26 +01:00
{
2012-04-03 12:01:57 +02:00
output < < lhs_field < < " = estimation_info.empty_prior; " < < endl ;
2012-03-30 14:54:08 +02:00
writeCommonOutputHelper ( output , " domain " , lhs_field ) ;
writeCommonOutputHelper ( output , " interval " , lhs_field ) ;
writeCommonOutputHelper ( output , " mean " , lhs_field ) ;
writeCommonOutputHelper ( output , " median " , lhs_field ) ;
writeCommonOutputHelper ( output , " mode " , lhs_field ) ;
2012-03-29 15:21:32 +02:00
assert ( prior_shape ! = eNoShape ) ;
output < < lhs_field < < " .shape = " < < prior_shape < < " ; " < < endl ;
2012-03-26 16:46:44 +02:00
writeCommonOutputHelper ( output , " shift " , lhs_field ) ;
2012-03-30 14:54:08 +02:00
writeCommonOutputHelper ( output , " stdev " , lhs_field ) ;
2012-03-26 16:46:44 +02:00
writeCommonOutputHelper ( output , " truncate " , lhs_field ) ;
2012-03-30 14:54:08 +02:00
if ( variance )
2012-04-03 12:01:57 +02:00
{
output < < lhs_field < < " .variance = " ;
variance - > writeOutput ( output ) ;
output < < " ; " < < endl ;
}
2012-03-26 16:46:44 +02:00
}
void
BasicPriorStatement : : writeCommonOutputHelper ( ostream & output , const string & field , const string & lhs_field ) const
2011-12-11 15:35:26 +01:00
{
2011-12-14 13:58:21 +01:00
OptionsList : : num_options_t : : const_iterator itn = options_list . num_options . find ( field ) ;
if ( itn ! = options_list . num_options . end ( ) )
2012-04-03 12:01:57 +02:00
output < < lhs_field < < " . " < < field < < " = " < < itn - > second < < " ; " < < endl ;
2011-12-11 15:35:26 +01:00
}
2011-12-29 18:43:21 +01:00
void
2012-04-03 12:59:56 +02:00
BasicPriorStatement : : writePriorOutput ( ostream & output , string & lhs_field , const string & name2 ) const
2011-12-29 18:43:21 +01:00
{
2012-03-29 15:21:32 +02:00
if ( subsample_name . empty ( ) )
lhs_field + = " .prior(1) " ;
else
2012-03-26 16:46:44 +02:00
{
2012-04-03 12:59:56 +02:00
output < < " subsamples_indx = get_existing_subsamples_indx(' " < < name < < " ',' " < < name2 < < " '); " < < endl
2012-03-29 15:21:32 +02:00
< < " eisind = get_subsamples_range_indx(subsamples_indx, ' " < < subsample_name < < " '); " < < endl ;
lhs_field + = " .subsample_prior(eisind) " ;
2012-03-26 16:46:44 +02:00
}
2012-03-29 15:21:32 +02:00
writeCommonOutput ( output , lhs_field ) ;
2012-03-27 12:55:57 +02:00
}
2017-02-08 18:29:57 +01:00
void
BasicPriorStatement : : writeJsonPriorOutput ( ostream & output ) const
{
output < < " , \" name \" : \" " < < name < < " \" "
< < " , \" subsample \" : \" " < < subsample_name < < " \" "
< < " , " ;
writeJsonShape ( output ) ;
if ( variance ! = NULL )
{
deriv_node_temp_terms_t tef_terms ;
output < < " , \" variance \" : \" " ;
2017-02-20 12:18:11 +01:00
variance - > writeJsonOutput ( output , temporary_terms_t ( ) , tef_terms ) ;
2017-02-08 18:29:57 +01:00
output < < " \" " ;
}
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
}
2013-08-06 21:29:11 +02:00
void
BasicPriorStatement : : writeCVarianceOption ( ostream & output ) const
{
output < < " variance = " ;
if ( variance )
variance - > writeOutput ( output ) ;
else
output < < " numeric_limits<double>::quiet_NaN() " ;
output < < " ; " < < endl ;
}
void
BasicPriorStatement : : writeCDomain ( ostream & output ) const
{
output < < " domain.clear(); " < < endl ;
OptionsList : : num_options_t : : const_iterator it_num = options_list . num_options . find ( " domain " ) ;
if ( it_num ! = options_list . num_options . end ( ) )
{
using namespace boost ;
vector < string > tokenizedDomain ;
split ( tokenizedDomain , it_num - > second , is_any_of ( " [ ] " ) , token_compress_on ) ;
for ( vector < string > : : iterator it = tokenizedDomain . begin ( ) ;
2017-06-01 19:58:32 +02:00
it ! = tokenizedDomain . end ( ) ; it + + )
2013-08-06 21:29:11 +02:00
if ( ! it - > empty ( ) )
output < < " domain.push_back( " < < * it < < " ); " < < endl ;
}
}
void
BasicPriorStatement : : writeCOutputHelper ( ostream & output , const string & field ) const
{
OptionsList : : num_options_t : : const_iterator itn = options_list . num_options . find ( field ) ;
if ( itn ! = options_list . num_options . end ( ) )
output < < field < < " = " < < itn - > second < < " ; " < < endl ;
else
output < < field < < " = " < < " numeric_limits<double>::quiet_NaN(); " < < endl ;
}
void
BasicPriorStatement : : writeCShape ( ostream & output ) const
{
output < < " shape = " ;
switch ( prior_shape )
{
case eBeta :
2017-06-01 19:58:32 +02:00
output < < " \" beta \" ; " < < endl ;
2013-08-06 21:29:11 +02:00
break ;
case eGamma :
2017-06-01 19:58:32 +02:00
output < < " \" gamma \" ; " < < endl ;
2013-08-06 21:29:11 +02:00
break ;
case eNormal :
2017-06-01 19:58:32 +02:00
output < < " \" normal \" ; " < < endl ;
2013-08-06 21:29:11 +02:00
break ;
case eInvGamma :
2017-06-01 19:58:32 +02:00
output < < " \" inv_gamma \" ; " < < endl ;
2013-08-06 21:29:11 +02:00
break ;
case eUniform :
2017-06-01 19:58:32 +02:00
output < < " \" uniform \" ; " < < endl ;
2013-08-06 21:29:11 +02:00
break ;
case eInvGamma2 :
2017-06-01 19:58:32 +02:00
output < < " \" inv_gamma2 \" ; " < < endl ;
2013-08-06 21:29:11 +02:00
break ;
2014-03-25 12:48:34 +01:00
case eDirichlet :
2017-06-01 19:58:32 +02:00
output < < " \" dirichlet \" ; " < < endl ;
2014-03-25 12:48:34 +01:00
break ;
2014-12-12 18:02:07 +01:00
case eWeibull :
2017-06-01 19:58:32 +02:00
output < < " \" weibull \" ; " < < endl ;
2014-12-12 18:02:07 +01:00
break ;
2013-08-06 21:29:11 +02:00
case eNoShape :
assert ( prior_shape ! = eNoShape ) ;
}
}
2017-02-08 18:29:57 +01:00
void
BasicPriorStatement : : writeJsonShape ( ostream & output ) const
{
output < < " \" shape \" : " ;
switch ( prior_shape )
{
case eBeta :
2017-06-14 07:01:31 +02:00
output < < " \" beta \" " ;
2017-02-08 18:29:57 +01:00
break ;
case eGamma :
2017-06-14 07:01:31 +02:00
output < < " \" gamma \" " ;
2017-02-08 18:29:57 +01:00
break ;
case eNormal :
2017-06-14 07:01:31 +02:00
output < < " \" normal \" " ;
2017-02-08 18:29:57 +01:00
break ;
case eInvGamma :
2017-06-14 07:01:31 +02:00
output < < " \" inv_gamma \" " ;
2017-02-08 18:29:57 +01:00
break ;
case eUniform :
2017-06-14 07:01:31 +02:00
output < < " \" uniform \" " ;
2017-02-08 18:29:57 +01:00
break ;
case eInvGamma2 :
2017-06-14 07:01:31 +02:00
output < < " \" inv_gamma2 \" " ;
2017-02-08 18:29:57 +01:00
break ;
case eDirichlet :
2017-06-14 07:01:31 +02:00
output < < " \" dirichlet \" " ;
2017-02-08 18:29:57 +01:00
break ;
case eWeibull :
2017-06-14 07:01:31 +02:00
output < < " \" weibull \" " ;
2017-02-08 18:29:57 +01:00
break ;
case eNoShape :
assert ( prior_shape ! = eNoShape ) ;
}
}
2011-12-11 15:35:26 +01:00
PriorStatement : : PriorStatement ( const string & name_arg ,
2012-03-28 16:19:10 +02:00
const string & subsample_name_arg ,
2011-12-29 18:43:21 +01:00
const PriorDistributions & prior_shape_arg ,
2011-12-11 15:35:26 +01:00
const expr_t & variance_arg ,
const OptionsList & options_list_arg ) :
2012-03-28 16:19:10 +02:00
BasicPriorStatement ( name_arg , subsample_name_arg , prior_shape_arg , variance_arg , options_list_arg )
2011-12-11 15:35:26 +01:00
{
}
void
2015-05-28 11:42:12 +02:00
PriorStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2011-12-11 15:35:26 +01:00
{
2012-04-02 17:03:43 +02:00
string lhs_field = " estimation_info.parameter(eifind) " ;
2012-03-29 15:21:32 +02:00
output < < " eifind = get_new_or_existing_ei_index('parameter_prior_index', ' "
< < name < < " ', ''); " < < endl
< < " estimation_info.parameter_prior_index(eifind) = {' " < < name < < " '}; " < < endl ;
2012-04-03 12:59:56 +02:00
writePriorOutput ( output , lhs_field , " " ) ;
2011-12-11 15:35:26 +01:00
}
2017-02-08 18:29:57 +01:00
void
PriorStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" prior \" " ;
writeJsonPriorOutput ( output ) ;
output < < " } " ;
}
2013-08-06 21:29:11 +02:00
void
PriorStatement : : writeCOutput ( ostream & output , const string & basename )
{
output < < endl
< < " index = param_names[ \" " < < name < < " \" ]; " < < endl ;
writeCShape ( output ) ;
writeCOutputHelper ( output , " mean " ) ;
writeCOutputHelper ( output , " mode " ) ;
writeCOutputHelper ( output , " stdev " ) ;
writeCVarianceOption ( output ) ;
writeCDomain ( output ) ;
output < < " msdsgeinfo->addPrior(new ModFilePrior( " < < endl
< < " index, shape, mean, mode, stdev, variance, domain)); " < < endl ;
}
2011-12-11 15:35:26 +01:00
StdPriorStatement : : StdPriorStatement ( const string & name_arg ,
2012-03-28 16:19:10 +02:00
const string & subsample_name_arg ,
2011-12-29 18:43:21 +01:00
const PriorDistributions & prior_shape_arg ,
2011-12-11 15:35:26 +01:00
const expr_t & variance_arg ,
const OptionsList & options_list_arg ,
2017-06-01 19:58:32 +02:00
const SymbolTable & symbol_table_arg ) :
2012-03-28 16:19:10 +02:00
BasicPriorStatement ( name_arg , subsample_name_arg , prior_shape_arg , variance_arg , options_list_arg ) ,
2011-12-11 15:35:26 +01:00
symbol_table ( symbol_table_arg )
{
}
void
2015-05-28 11:42:12 +02:00
StdPriorStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2011-12-11 15:35:26 +01:00
{
string lhs_field ;
get_base_name ( symbol_table . getType ( name ) , lhs_field ) ;
2012-03-29 15:21:32 +02:00
output < < " eifind = get_new_or_existing_ei_index(' " < < lhs_field < < " _prior_index', ' "
< < name < < " ', ''); " < < endl
< < " estimation_info. " < < lhs_field < < " _prior_index(eifind) = {' " < < name < < " '}; " < < endl ;
2011-12-11 15:35:26 +01:00
2012-03-29 15:21:32 +02:00
lhs_field = " estimation_info. " + lhs_field + " (eifind) " ;
2012-04-03 12:59:56 +02:00
writePriorOutput ( output , lhs_field , " " ) ;
2011-12-11 15:35:26 +01:00
}
2017-02-08 18:29:57 +01:00
void
StdPriorStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" std_prior \" " ;
writeJsonPriorOutput ( output ) ;
output < < " } " ;
}
2013-08-06 21:29:11 +02:00
void
StdPriorStatement : : writeCOutput ( ostream & output , const string & basename )
{
output < < endl
< < " index = " ;
if ( is_structural_innovation ( symbol_table . getType ( name ) ) )
output < < " exo_names " ;
else
output < < " endo_names " ;
output < < " [ \" " < < name < < " \" ]; " < < endl ;
writeCShape ( output ) ;
writeCOutputHelper ( output , " mean " ) ;
writeCOutputHelper ( output , " mode " ) ;
writeCOutputHelper ( output , " stdev " ) ;
writeCVarianceOption ( output ) ;
writeCDomain ( output ) ;
if ( is_structural_innovation ( symbol_table . getType ( name ) ) )
output < < " msdsgeinfo->addStructuralInnovationPrior(new ModFileStructuralInnovationPrior( " ;
else
output < < " msdsgeinfo->addMeasurementErrorPrior(new ModFileMeasurementErrorPrior( " ;
output < < endl < < " index, shape, mean, mode, stdev, variance, domain)); " < < endl ;
}
2011-12-11 15:35:26 +01:00
CorrPriorStatement : : CorrPriorStatement ( const string & name_arg1 , const string & name_arg2 ,
2012-03-28 16:19:10 +02:00
const string & subsample_name_arg ,
2011-12-29 18:43:21 +01:00
const PriorDistributions & prior_shape_arg ,
2011-12-11 15:35:26 +01:00
const expr_t & variance_arg ,
const OptionsList & options_list_arg ,
2017-06-01 19:58:32 +02:00
const SymbolTable & symbol_table_arg ) :
2012-03-28 16:19:10 +02:00
BasicPriorStatement ( name_arg1 , subsample_name_arg , prior_shape_arg , variance_arg , options_list_arg ) ,
2011-12-11 15:35:26 +01:00
name1 ( name_arg2 ) ,
symbol_table ( symbol_table_arg )
{
}
void
2012-01-23 16:52:27 +01:00
CorrPriorStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2011-12-11 15:35:26 +01:00
{
2012-01-23 16:52:27 +01:00
BasicPriorStatement : : checkPass ( mod_file_struct , warnings ) ;
2011-12-11 15:35:26 +01:00
if ( symbol_table . getType ( name ) ! = symbol_table . getType ( name1 ) )
{
cerr < < " ERROR: In the corr(A,B).prior statement, A and B must be of the same type. "
< < " In your case, " < < name < < " and " < < name1 < < " are of different "
< < " types. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
void
2015-05-28 11:42:12 +02:00
CorrPriorStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2011-12-11 15:35:26 +01:00
{
string lhs_field ;
get_base_name ( symbol_table . getType ( name ) , lhs_field ) ;
2012-03-29 16:45:46 +02:00
output < < " eifind = get_new_or_existing_ei_index(' " < < lhs_field < < " _corr_prior_index', ' "
2012-03-29 15:21:32 +02:00
< < name < < " ', ' " < < name1 < < " '); " < < endl
2012-03-29 16:45:46 +02:00
< < " estimation_info. " < < lhs_field < < " _corr_prior_index(eifind) = {' "
2012-03-30 14:04:06 +02:00
< < name < < " : " < < name1 < < " '}; " < < endl ;
2011-12-11 15:35:26 +01:00
2012-03-29 15:21:32 +02:00
lhs_field = " estimation_info. " + lhs_field + " _corr(eifind) " ;
2012-04-03 12:59:56 +02:00
writePriorOutput ( output , lhs_field , name1 ) ;
2012-03-30 14:04:06 +02:00
}
2012-03-29 15:21:32 +02:00
2017-02-08 18:29:57 +01:00
void
CorrPriorStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" corr_prior \" "
< < " , \" name2 \" : \" " < < name1 < < " \" " ;
writeJsonPriorOutput ( output ) ;
output < < " } " ;
}
2013-08-06 21:29:11 +02:00
void
CorrPriorStatement : : writeCOutput ( ostream & output , const string & basename )
{
output < < endl
< < " index = " ;
if ( is_structural_innovation ( symbol_table . getType ( name ) ) )
output < < " exo_names " ;
else
output < < " endo_names " ;
output < < " [ \" " < < name < < " \" ]; " < < endl ;
output < < " index1 = " ;
if ( is_structural_innovation ( symbol_table . getType ( name1 ) ) )
output < < " exo_names " ;
else
output < < " endo_names " ;
output < < " [ \" " < < name1 < < " \" ]; " < < endl ;
writeCShape ( output ) ;
writeCOutputHelper ( output , " mean " ) ;
writeCOutputHelper ( output , " mode " ) ;
writeCOutputHelper ( output , " stdev " ) ;
writeCVarianceOption ( output ) ;
writeCDomain ( output ) ;
if ( is_structural_innovation ( symbol_table . getType ( name ) ) )
output < < " msdsgeinfo->addStructuralInnovationCorrPrior(new ModFileStructuralInnovationCorrPrior( " ;
else
output < < " msdsgeinfo->addMeasurementErrorCorrPrior(new ModFileMeasurementErrorCorrPrior( " ;
output < < endl < < " index, index1, shape, mean, mode, stdev, variance, domain)); " < < endl ;
}
2015-04-14 11:33:02 +02:00
PriorEqualStatement : : PriorEqualStatement ( const string & to_declaration_type_arg ,
const string & to_name1_arg ,
const string & to_name2_arg ,
const string & to_subsample_name_arg ,
const string & from_declaration_type_arg ,
const string & from_name1_arg ,
const string & from_name2_arg ,
const string & from_subsample_name_arg ,
const SymbolTable & symbol_table_arg ) :
to_declaration_type ( to_declaration_type_arg ) ,
to_name1 ( to_name1_arg ) ,
to_name2 ( to_name2_arg ) ,
to_subsample_name ( to_subsample_name_arg ) ,
from_declaration_type ( from_declaration_type_arg ) ,
from_name1 ( from_name1_arg ) ,
from_name2 ( from_name2_arg ) ,
from_subsample_name ( from_subsample_name_arg ) ,
symbol_table ( symbol_table_arg )
{
}
2012-03-30 14:55:25 +02:00
void
PriorEqualStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
2017-06-01 19:58:32 +02:00
if ( ( to_declaration_type ! = " par " & & to_declaration_type ! = " std " & & to_declaration_type ! = " corr " )
| | ( from_declaration_type ! = " par " & & from_declaration_type ! = " std " & & from_declaration_type ! = " corr " ) )
2012-03-30 14:55:25 +02:00
{
cerr < < " Internal Dynare Error " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
void
PriorEqualStatement : : get_base_name ( const SymbolType symb_type , string & lhs_field ) const
{
if ( symb_type = = eExogenous | | symb_type = = eExogenousDet )
lhs_field = " structural_innovation " ;
else
lhs_field = " measurement_error " ;
}
void
2015-05-28 11:42:12 +02:00
PriorEqualStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2012-03-30 14:55:25 +02:00
{
string lhs_field , rhs_field ;
if ( to_declaration_type = = " par " )
lhs_field = " parameter " ;
else
get_base_name ( symbol_table . getType ( to_name1 ) , lhs_field ) ;
if ( from_declaration_type = = " par " )
rhs_field = " parameter " ;
else
get_base_name ( symbol_table . getType ( from_name1 ) , rhs_field ) ;
if ( to_declaration_type = = " corr " )
lhs_field + = " _corr " ;
if ( from_declaration_type = = " corr " )
rhs_field + = " _corr " ;
output < < " ei_to_ind = get_new_or_existing_ei_index(' " < < lhs_field < < " _prior_index', ' "
< < to_name1 < < " ', ' " < < to_name2 < < " '); " < < endl
< < " ei_from_ind = get_new_or_existing_ei_index(' " < < rhs_field < < " _prior_index', ' "
< < from_name1 < < " ', ' " < < from_name2 < < " '); " < < endl
< < " estimation_info. " < < lhs_field < < " _prior_index(ei_to_ind) = {' " < < to_name1 ;
if ( to_declaration_type = = " corr " )
output < < " : " < < to_name2 ;
output < < " '}; " < < endl ;
if ( to_declaration_type = = " par " )
2012-04-02 17:03:43 +02:00
lhs_field = " parameter " ;
2012-03-30 14:55:25 +02:00
if ( from_declaration_type = = " par " )
2012-04-02 17:03:43 +02:00
rhs_field = " parameter " ;
2012-03-30 14:55:25 +02:00
lhs_field = " estimation_info. " + lhs_field + " (ei_to_ind) " ;
rhs_field = " estimation_info. " + rhs_field + " (ei_from_ind) " ;
if ( to_subsample_name . empty ( ) )
lhs_field + = " .prior " ;
else
{
output < < " subsamples_to_indx = get_existing_subsamples_indx(' " < < to_name1 < < " ',' " < < to_name2 < < " '); " < < endl
< < " ei_to_ss_ind = get_subsamples_range_indx(subsamples_to_indx, ' " < < to_subsample_name < < " '); " < < endl ;
lhs_field + = " .subsample_prior(ei_to_ss_ind) " ;
}
if ( from_subsample_name . empty ( ) )
rhs_field + = " .prior " ;
else
{
output < < " subsamples_from_indx = get_existing_subsamples_indx(' " < < from_name1 < < " ',' " < < from_name2 < < " '); " < < endl
< < " ei_from_ss_ind = get_subsamples_range_indx(subsamples_from_indx, ' " < < from_subsample_name < < " '); " < < endl ;
rhs_field + = " .subsample_prior(ei_from_ss_ind) " ;
}
output < < lhs_field < < " = " < < rhs_field < < " ; " < < endl ;
2011-12-11 15:35:26 +01:00
}
2011-12-14 17:19:14 +01:00
2017-02-08 18:29:57 +01:00
void
PriorEqualStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" prior_equal \" "
< < " , \" to_name1 \" : \" " < < to_name1 < < " \" " ;
if ( to_declaration_type = = " corr " )
output < < " , \" to_name2 \" : \" " < < to_name2 < < " \" " ;
output < < " , \" to_subsample \" : \" " < < to_subsample_name < < " \" "
< < " , \" from_name1 \" : \" " < < from_name1 < < " \" " ;
if ( to_declaration_type = = " corr " )
output < < " , \" from_name2 \" : \" " < < from_name2 < < " \" " ;
output < < " , \" from_subsample \" : \" " < < from_subsample_name < < " \" "
< < " } " ;
}
2011-12-14 17:19:14 +01:00
BasicOptionsStatement : : ~ BasicOptionsStatement ( )
{
}
BasicOptionsStatement : : BasicOptionsStatement ( const string & name_arg ,
2012-03-28 16:19:10 +02:00
const string & subsample_name_arg ,
const OptionsList & options_list_arg ) :
2011-12-14 17:19:14 +01:00
name ( name_arg ) ,
2012-03-28 16:19:10 +02:00
subsample_name ( subsample_name_arg ) ,
2012-03-29 16:45:46 +02:00
options_list ( options_list_arg )
2011-12-14 17:19:14 +01:00
{
}
void
2012-01-23 16:52:27 +01:00
BasicOptionsStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2011-12-14 17:19:14 +01:00
{
}
2013-08-06 21:44:04 +02:00
bool
BasicOptionsStatement : : is_structural_innovation ( const SymbolType symb_type ) const
{
if ( symb_type = = eExogenous | | symb_type = = eExogenousDet )
return true ;
return false ;
}
2011-12-14 17:19:14 +01:00
void
BasicOptionsStatement : : get_base_name ( const SymbolType symb_type , string & lhs_field ) const
{
if ( symb_type = = eExogenous | | symb_type = = eExogenousDet )
lhs_field = " structural_innovation " ;
else
lhs_field = " measurement_error " ;
}
void
2012-03-26 16:46:44 +02:00
BasicOptionsStatement : : writeCommonOutput ( ostream & output , const string & lhs_field ) const
{
2012-04-03 12:01:57 +02:00
output < < lhs_field < < " = estimation_info.empty_options; " < < endl ;
2012-03-26 16:46:44 +02:00
writeCommonOutputHelper ( output , " bounds " , lhs_field ) ;
2012-03-30 15:08:48 +02:00
writeCommonOutputHelper ( output , " init " , lhs_field ) ;
2012-03-26 16:46:44 +02:00
writeCommonOutputHelper ( output , " jscale " , lhs_field ) ;
}
void
BasicOptionsStatement : : writeCommonOutputHelper ( ostream & output , const string & field , const string & lhs_field ) const
2011-12-14 17:19:14 +01:00
{
OptionsList : : num_options_t : : const_iterator itn = options_list . num_options . find ( field ) ;
if ( itn ! = options_list . num_options . end ( ) )
2012-04-03 12:01:57 +02:00
output < < lhs_field < < " . " < < field < < " = " < < itn - > second < < " ; " < < endl ;
2012-03-28 16:19:10 +02:00
}
2013-08-06 21:44:04 +02:00
void
BasicOptionsStatement : : writeCOutputHelper ( ostream & output , const string & field ) const
{
OptionsList : : num_options_t : : const_iterator itn = options_list . num_options . find ( field ) ;
if ( itn ! = options_list . num_options . end ( ) )
output < < field < < " = " < < itn - > second < < " ; " < < endl ;
else
output < < field < < " = " < < " numeric_limits<double>::quiet_NaN(); " < < endl ;
}
2012-03-28 16:19:10 +02:00
void
2012-03-29 16:45:46 +02:00
BasicOptionsStatement : : writeOptionsOutput ( ostream & output , string & lhs_field , const string & name2 ) const
2012-03-28 16:19:10 +02:00
{
if ( subsample_name . empty ( ) )
2012-03-29 16:45:46 +02:00
lhs_field + = " .options(1) " ;
else
{
output < < " subsamples_indx = get_existing_subsamples_indx(' " < < name < < " ',' " < < name2 < < " '); " < < endl
< < " eisind = get_subsamples_range_indx(subsamples_indx, ' " < < subsample_name < < " '); " < < endl ;
lhs_field + = " .subsample_options(eisind) " ;
}
writeCommonOutput ( output , lhs_field ) ;
2012-03-27 12:55:57 +02:00
}
2017-02-08 18:29:57 +01:00
void
BasicOptionsStatement : : writeJsonOptionsOutput ( ostream & output ) const
{
output < < " , \" name \" : \" " < < name < < " \" " ;
if ( ! subsample_name . empty ( ) )
output < < " , \" subsample_name \" : \" " < < subsample_name < < " \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
}
2011-12-14 17:19:14 +01:00
OptionsStatement : : OptionsStatement ( const string & name_arg ,
2012-03-28 16:19:10 +02:00
const string & subsample_name_arg ,
2011-12-14 17:19:14 +01:00
const OptionsList & options_list_arg ) :
2012-03-28 16:19:10 +02:00
BasicOptionsStatement ( name_arg , subsample_name_arg , options_list_arg )
2011-12-14 17:19:14 +01:00
{
}
void
2015-05-28 11:42:12 +02:00
OptionsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2011-12-14 17:19:14 +01:00
{
2012-04-02 17:03:43 +02:00
string lhs_field = " estimation_info.parameter(eifind) " ;
2012-03-29 16:45:46 +02:00
output < < " eifind = get_new_or_existing_ei_index('parameter_options_index', ' "
< < name < < " ', ''); " < < endl
< < " estimation_info.parameter_options_index(eifind) = {' " < < name < < " '}; " < < endl ;
writeOptionsOutput ( output , lhs_field , " " ) ;
2011-12-14 17:19:14 +01:00
}
2017-02-08 18:29:57 +01:00
void
OptionsStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" options \" " ;
writeJsonOptionsOutput ( output ) ;
output < < " } " ;
}
2013-08-06 21:44:04 +02:00
void
OptionsStatement : : writeCOutput ( ostream & output , const string & basename )
{
output < < endl
< < " index = param_names[ \" " < < name < < " \" ]; " < < endl ;
writeCOutputHelper ( output , " init " ) ;
output < < " msdsgeinfo->addOption(new ModFileOption(index, init)); " < < endl ;
}
2011-12-14 17:19:14 +01:00
StdOptionsStatement : : StdOptionsStatement ( const string & name_arg ,
2012-03-28 16:19:10 +02:00
const string & subsample_name_arg ,
2011-12-14 17:19:14 +01:00
const OptionsList & options_list_arg ,
2017-06-01 19:58:32 +02:00
const SymbolTable & symbol_table_arg ) :
2012-03-28 16:19:10 +02:00
BasicOptionsStatement ( name_arg , subsample_name_arg , options_list_arg ) ,
2011-12-14 17:19:14 +01:00
symbol_table ( symbol_table_arg )
{
}
void
2015-05-28 11:42:12 +02:00
StdOptionsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2011-12-14 17:19:14 +01:00
{
string lhs_field ;
get_base_name ( symbol_table . getType ( name ) , lhs_field ) ;
2012-03-29 16:45:46 +02:00
output < < " eifind = get_new_or_existing_ei_index(' " < < lhs_field < < " _options_index', ' "
< < name < < " ', ''); " < < endl
< < " estimation_info. " < < lhs_field < < " _options_index(eifind) = {' " < < name < < " '}; " < < endl ;
2011-12-14 17:19:14 +01:00
2012-03-29 16:45:46 +02:00
lhs_field = " estimation_info. " + lhs_field + " (eifind) " ;
writeOptionsOutput ( output , lhs_field , " " ) ;
2011-12-14 17:19:14 +01:00
}
2017-02-08 18:29:57 +01:00
void
StdOptionsStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" std_options \" " ;
writeJsonOptionsOutput ( output ) ;
output < < " } " ;
}
2013-08-06 21:44:04 +02:00
void
StdOptionsStatement : : writeCOutput ( ostream & output , const string & basename )
{
output < < endl
< < " index = " ;
if ( is_structural_innovation ( symbol_table . getType ( name ) ) )
output < < " exo_names " ;
else
output < < " endo_names " ;
output < < " [ \" " < < name < < " \" ]; " < < endl ;
writeCOutputHelper ( output , " init " ) ;
if ( is_structural_innovation ( symbol_table . getType ( name ) ) )
output < < " msdsgeinfo->addStructuralInnovationOption(new ModFileStructuralInnovationOption( " ;
else
output < < " msdsgeinfo->addMeasurementErrorOption(new ModFileMeasurementErrorOption( " ;
output < < " index, init)); " < < endl ;
}
2011-12-14 17:19:14 +01:00
CorrOptionsStatement : : CorrOptionsStatement ( const string & name_arg1 , const string & name_arg2 ,
2012-03-28 16:19:10 +02:00
const string & subsample_name_arg ,
2011-12-14 17:19:14 +01:00
const OptionsList & options_list_arg ,
2017-06-01 19:58:32 +02:00
const SymbolTable & symbol_table_arg ) :
2012-03-28 16:19:10 +02:00
BasicOptionsStatement ( name_arg1 , subsample_name_arg , options_list_arg ) ,
2011-12-14 17:19:14 +01:00
name1 ( name_arg2 ) ,
symbol_table ( symbol_table_arg )
{
}
void
2012-01-23 16:52:27 +01:00
CorrOptionsStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2011-12-14 17:19:14 +01:00
{
if ( symbol_table . getType ( name ) ! = symbol_table . getType ( name1 ) )
{
cerr < < " ERROR: In the corr(A,B).options statement, A and B must be of the same type. "
< < " In your case, " < < name < < " and " < < name1 < < " are of different "
< < " types. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
void
2015-05-28 11:42:12 +02:00
CorrOptionsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2011-12-14 17:19:14 +01:00
{
string lhs_field ;
get_base_name ( symbol_table . getType ( name ) , lhs_field ) ;
2012-03-29 16:45:46 +02:00
output < < " eifind = get_new_or_existing_ei_index(' " < < lhs_field < < " _corr_options_index', ' "
< < name < < " ', ' " < < name1 < < " '); " < < endl
< < " estimation_info. " < < lhs_field < < " _corr_options_index(eifind) = {' "
2012-03-30 14:04:06 +02:00
< < name < < " : " < < name1 < < " '}; " < < endl ;
2011-12-14 17:19:14 +01:00
2012-03-29 16:45:46 +02:00
lhs_field = " estimation_info. " + lhs_field + " _corr(eifind) " ;
writeOptionsOutput ( output , lhs_field , name1 ) ;
2011-12-14 17:19:14 +01:00
}
2012-03-30 15:36:58 +02:00
2017-02-08 18:29:57 +01:00
void
CorrOptionsStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" corr_options \" "
< < " , \" name2 \" : \" " < < name1 < < " \" " ;
writeJsonOptionsOutput ( output ) ;
output < < " } " ;
}
2015-04-14 14:47:26 +02:00
void
CorrOptionsStatement : : writeCOutput ( ostream & output , const string & basename )
{
output < < endl
< < " index = " ;
if ( is_structural_innovation ( symbol_table . getType ( name ) ) )
output < < " exo_names " ;
else
output < < " endo_names " ;
output < < " [ \" " < < name < < " \" ]; " < < endl ;
output < < " index1 = " ;
if ( is_structural_innovation ( symbol_table . getType ( name1 ) ) )
output < < " exo_names " ;
else
output < < " endo_names " ;
output < < " [ \" " < < name1 < < " \" ]; " < < endl ;
writeCOutputHelper ( output , " init " ) ;
if ( is_structural_innovation ( symbol_table . getType ( name ) ) )
output < < " msdsgeinfo->addStructuralInnovationCorrOption(new ModFileStructuralInnovationCorrOption( " ;
else
output < < " msdsgeinfo->addMeasurementErrorCorrOption(new ModFileMeasurementErrorCorrOption( " ;
output < < " index, index1, init)); " < < endl ;
}
2012-03-30 15:36:58 +02:00
OptionsEqualStatement : : OptionsEqualStatement ( const string & to_declaration_type_arg ,
const string & to_name1_arg ,
const string & to_name2_arg ,
const string & to_subsample_name_arg ,
const string & from_declaration_type_arg ,
const string & from_name1_arg ,
const string & from_name2_arg ,
const string & from_subsample_name_arg ,
const SymbolTable & symbol_table_arg ) :
to_declaration_type ( to_declaration_type_arg ) ,
to_name1 ( to_name1_arg ) ,
to_name2 ( to_name2_arg ) ,
to_subsample_name ( to_subsample_name_arg ) ,
from_declaration_type ( from_declaration_type_arg ) ,
from_name1 ( from_name1_arg ) ,
from_name2 ( from_name2_arg ) ,
from_subsample_name ( from_subsample_name_arg ) ,
symbol_table ( symbol_table_arg )
{
}
void
OptionsEqualStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
2017-06-01 19:58:32 +02:00
if ( ( to_declaration_type ! = " par " & & to_declaration_type ! = " std " & & to_declaration_type ! = " corr " )
| | ( from_declaration_type ! = " par " & & from_declaration_type ! = " std " & & from_declaration_type ! = " corr " ) )
2012-03-30 15:36:58 +02:00
{
cerr < < " Internal Dynare Error " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
2017-02-08 18:29:57 +01:00
void
OptionsEqualStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" options_equal \" "
< < " , \" to_name1 \" : \" " < < to_name1 < < " \" " ;
if ( to_declaration_type = = " corr " )
output < < " , \" to_name2 \" : \" " < < to_name2 < < " \" " ;
output < < " , \" to_subsample \" : \" " < < to_subsample_name < < " \" "
< < " , \" from_name1 \" : \" " < < from_name1 < < " \" " ;
if ( to_declaration_type = = " corr " )
output < < " , \" from_name2 \" : \" " < < from_name2 < < " \" " ;
output < < " , \" from_subsample \" : \" " < < from_subsample_name < < " \" "
< < " } " ;
}
2012-03-30 15:36:58 +02:00
void
OptionsEqualStatement : : get_base_name ( const SymbolType symb_type , string & lhs_field ) const
{
if ( symb_type = = eExogenous | | symb_type = = eExogenousDet )
lhs_field = " structural_innovation " ;
else
lhs_field = " measurement_error " ;
}
void
2015-05-28 11:42:12 +02:00
OptionsEqualStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2012-03-30 15:36:58 +02:00
{
string lhs_field , rhs_field ;
if ( to_declaration_type = = " par " )
lhs_field = " parameter " ;
else
get_base_name ( symbol_table . getType ( to_name1 ) , lhs_field ) ;
if ( from_declaration_type = = " par " )
rhs_field = " parameter " ;
else
get_base_name ( symbol_table . getType ( from_name1 ) , rhs_field ) ;
if ( to_declaration_type = = " corr " )
lhs_field + = " _corr " ;
if ( from_declaration_type = = " corr " )
rhs_field + = " _corr " ;
output < < " ei_to_ind = get_new_or_existing_ei_index(' " < < lhs_field < < " _options_index', ' "
< < to_name1 < < " ', ' " < < to_name2 < < " '); " < < endl
< < " ei_from_ind = get_new_or_existing_ei_index(' " < < rhs_field < < " _options_index', ' "
< < from_name1 < < " ', ' " < < from_name2 < < " '); " < < endl
< < " estimation_info. " < < lhs_field < < " _options_index(ei_to_ind) = {' " < < to_name1 ;
if ( to_declaration_type = = " corr " )
output < < " : " < < to_name2 ;
output < < " '}; " < < endl ;
if ( to_declaration_type = = " par " )
2012-04-02 17:03:43 +02:00
lhs_field = " parameter " ;
2012-03-30 15:36:58 +02:00
if ( from_declaration_type = = " par " )
2012-04-02 17:03:43 +02:00
rhs_field = " parameter " ;
2012-03-30 15:36:58 +02:00
lhs_field = " estimation_info. " + lhs_field + " (ei_to_ind) " ;
rhs_field = " estimation_info. " + rhs_field + " (ei_from_ind) " ;
if ( to_subsample_name . empty ( ) )
lhs_field + = " .options " ;
else
{
output < < " subsamples_to_indx = get_existing_subsamples_indx(' " < < to_name1 < < " ',' " < < to_name2 < < " '); " < < endl
< < " ei_to_ss_ind = get_subsamples_range_indx(subsamples_to_indx, ' " < < to_subsample_name < < " '); " < < endl ;
lhs_field + = " .subsample_options(ei_to_ss_ind) " ;
}
if ( from_subsample_name . empty ( ) )
rhs_field + = " .options " ;
else
{
output < < " subsamples_from_indx = get_existing_subsamples_indx(' " < < from_name1 < < " ',' " < < from_name2 < < " '); " < < endl
< < " ei_from_ss_ind = get_subsamples_range_indx(subsamples_from_indx, ' " < < from_subsample_name < < " '); " < < endl ;
rhs_field + = " .subsample_options(ei_from_ss_ind) " ;
}
output < < lhs_field < < " = " < < rhs_field < < " ; " < < endl ;
}
2012-05-30 16:28:00 +02:00
CalibSmootherStatement : : CalibSmootherStatement ( const SymbolList & symbol_list_arg ,
const OptionsList & options_list_arg )
: symbol_list ( symbol_list_arg ) , options_list ( options_list_arg )
{
}
2013-10-28 14:22:23 +01:00
void
CalibSmootherStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
mod_file_struct . calib_smoother_present = true ;
}
2012-05-30 16:28:00 +02:00
void
2015-05-28 11:42:12 +02:00
CalibSmootherStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2012-05-30 16:28:00 +02:00
{
options_list . writeOutput ( output ) ;
symbol_list . writeOutput ( " var_list_ " , output ) ;
2013-06-28 11:14:24 +02:00
output < < " options_.smoother = 1; " < < endl ;
output < < " options_.order = 1; " < < endl ;
2017-01-09 18:10:15 +01:00
output < < " [oo_,M_,options_,bayestopt_]=evaluate_smoother('calibration',var_list_,M_,oo_,options_,bayestopt_,estim_params_); " < < endl ;
2012-05-30 16:28:00 +02:00
}
2012-06-08 17:36:32 +02:00
2017-02-08 18:29:57 +01:00
void
CalibSmootherStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" calib_smoother \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2012-06-08 17:36:32 +02:00
ExtendedPathStatement : : ExtendedPathStatement ( const OptionsList & options_list_arg )
: options_list ( options_list_arg )
{
}
void
ExtendedPathStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
2013-04-25 18:07:32 +02:00
mod_file_struct . extended_path_present = true ;
2012-06-08 17:36:32 +02:00
if ( options_list . num_options . find ( " periods " ) = = options_list . num_options . end ( ) )
{
cerr < < " ERROR: the 'periods' option of 'extended_path' is mandatory " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2015-06-04 14:16:52 +02:00
// Fill in option_occbin of mod_file_struct
OptionsList : : string_options_t : : const_iterator it = options_list . num_options . find ( " occbin " ) ;
if ( it ! = options_list . string_options . end ( ) )
mod_file_struct . occbin_option = true ;
2012-06-08 17:36:32 +02:00
}
void
2015-05-28 11:42:12 +02:00
ExtendedPathStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2012-06-08 17:36:32 +02:00
{
// Beware: options do not have the same name in the interface and in the M code...
2013-06-07 18:17:02 +02:00
for ( OptionsList : : num_options_t : : const_iterator it = options_list . num_options . begin ( ) ;
it ! = options_list . num_options . end ( ) ; + + it )
if ( it - > first ! = string ( " periods " ) )
output < < " options_. " < < it - > first < < " = " < < it - > second < < " ; " < < endl ;
2012-06-08 17:36:32 +02:00
2013-12-09 11:07:44 +01:00
output < < " extended_path([], " < < options_list . num_options . find ( " periods " ) - > second
2016-03-14 20:11:33 +01:00
< < " , [], options_, M_, oo_); " < < endl ;
2012-06-08 17:36:32 +02:00
}
2012-11-16 12:34:49 +01:00
2017-02-08 18:29:57 +01:00
void
ExtendedPathStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" extended_path \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2012-11-16 12:34:49 +01:00
ModelDiagnosticsStatement : : ModelDiagnosticsStatement ( )
{
}
void
2015-05-28 11:42:12 +02:00
ModelDiagnosticsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2012-11-16 12:34:49 +01:00
{
output < < " model_diagnostics(M_,options_,oo_); " < < endl ;
}
2013-08-06 21:44:04 +02:00
2017-02-08 18:29:57 +01:00
void
ModelDiagnosticsStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" model_diagnostics \" } " ;
}
2014-04-03 15:05:20 +02:00
Smoother2histvalStatement : : Smoother2histvalStatement ( const OptionsList & options_list_arg ) :
options_list ( options_list_arg )
{
}
void
2015-05-28 11:42:12 +02:00
Smoother2histvalStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2014-04-03 15:05:20 +02:00
{
options_list . writeOutput ( output , " options_smoother2histval " ) ;
output < < " smoother2histval(options_smoother2histval); " < < endl ;
}
2017-02-08 18:29:57 +01:00
void
Smoother2histvalStatement : : writeJsonOutput ( ostream & output ) const
{
output < < " { \" statementName \" : \" smoother_2_histval \" " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}