2008-02-03 11:28:36 +01:00
/*
2021-01-25 18:03:37 +01:00
* Copyright © 2003 - 2021 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
2021-06-09 16:52:20 +02:00
* along with Dynare . If not , see < https : //www.gnu.org/licenses/>.
2008-02-03 11:28:36 +01:00
*/
2009-04-28 18:21:39 +02:00
# include <cassert>
2008-02-03 11:28:36 +01:00
# include <iostream>
# include <sstream>
2021-09-08 17:06:10 +02:00
# include <algorithm>
# include <iterator>
2008-02-03 11:28:36 +01:00
using namespace std ;
# include "ComputingTasks.hh"
# include "Statement.hh"
2021-07-20 18:18:24 +02:00
# include "ParsingDriver.hh"
2008-02-03 11:28:36 +01:00
2019-04-23 14:51:14 +02:00
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wold-style-cast"
2011-12-19 17:32:02 +01:00
# include <boost/algorithm/string/trim.hpp>
# include <boost/algorithm/string/split.hpp>
# include <boost/tokenizer.hpp>
2019-04-23 14:51:14 +02:00
# pragma GCC diagnostic pop
2018-06-04 12:31:07 +02:00
# include <utility>
2020-02-04 17:48:37 +01:00
# include <algorithm>
2011-12-19 17:32:02 +01:00
2018-06-04 12:31:07 +02:00
SteadyStatement : : SteadyStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " steady " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
CheckStatement : : CheckStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2008-02-03 11:28:36 +01:00
{
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " check " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
ModelInfoStatement : : ModelInfoStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2008-08-25 17:06:36 +02:00
{
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " model_info " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
SimulStatement : : SimulStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( 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
{
2019-12-19 14:53:52 +01:00
// Translate the “datafile” option into “initval_file” (see dynare#1663)
auto options_list_new = options_list ; // Need a copy, because of const
if ( auto it = options_list_new . string_options . find ( " datafile " ) ;
it ! = options_list_new . string_options . end ( ) )
{
output < < " options_.initval_file = true; " < < endl
2020-05-14 16:36:35 +02:00
< < " options_initvalf = struct(); " < < endl
< < " options_initvalf.datafile = ' " < < it - > second < < " '; " < < endl
< < " oo_.initval_series = histvalf_initvalf('INITVALF', M_, options_initvalf); " < < endl ;
2019-12-19 14:53:52 +01:00
options_list_new . string_options . erase ( it ) ;
}
options_list_new . 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " simul " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
PerfectForesightSetupStatement : : PerfectForesightSetupStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2014-04-09 17:57:17 +02:00
{
}
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
{
2019-12-19 14:53:52 +01:00
auto options_list_new = options_list ; // Need a copy, because of const
if ( auto it = options_list_new . string_options . find ( " datafile " ) ;
it ! = options_list_new . string_options . end ( ) )
{
output < < " options_.initval_file = true; " < < endl
2020-05-14 16:36:35 +02:00
< < " options_initvalf = struct(); " < < endl
< < " options_initvalf.datafile = ' " < < it - > second < < " '; " < < endl
< < " oo_.initval_series = histvalf_initvalf('INITVALF', M_, options_initvalf); " < < endl ;
2019-12-19 14:53:52 +01:00
options_list_new . string_options . erase ( it ) ;
}
options_list_new . writeOutput ( output ) ;
2014-04-09 17:57:17 +02:00
output < < " perfect_foresight_setup; " < < endl ;
}
2017-02-08 18:29:57 +01:00
void
PerfectForesightSetupStatement : : writeJsonOutput ( ostream & output ) const
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " perfect_foresight_setup " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
PerfectForesightSolverStatement : : PerfectForesightSolverStatement ( OptionsList options_list_arg ) :
options_list ( move ( options_list_arg ) )
2014-04-09 17:57:17 +02:00
{
}
void
PerfectForesightSolverStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
mod_file_struct . perfect_foresight_solver_present = true ;
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " perfect_foresight_solver " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2021-07-09 17:14:22 +02:00
PerfectForesightWithExpectationErrorsSetupStatement : : PerfectForesightWithExpectationErrorsSetupStatement ( OptionsList options_list_arg ) :
options_list { move ( options_list_arg ) }
{
}
void
PerfectForesightWithExpectationErrorsSetupStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
options_list . writeOutput ( output ) ;
output < < " perfect_foresight_with_expectation_errors_setup; " < < endl ;
}
void
PerfectForesightWithExpectationErrorsSetupStatement : : writeJsonOutput ( ostream & output ) const
{
output < < R " ({ " statementName " : " perfect_foresight_with_expectation_errors_setup " ) " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
PerfectForesightWithExpectationErrorsSolverStatement : : PerfectForesightWithExpectationErrorsSolverStatement ( OptionsList options_list_arg ) :
options_list ( move ( options_list_arg ) )
{
}
void
PerfectForesightWithExpectationErrorsSolverStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
mod_file_struct . perfect_foresight_solver_present = true ;
}
void
PerfectForesightWithExpectationErrorsSolverStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
options_list . writeOutput ( output ) ;
output < < " perfect_foresight_with_expectation_errors_solver; " < < endl ;
}
void
PerfectForesightWithExpectationErrorsSolverStatement : : writeJsonOutput ( ostream & output ) const
{
output < < R " ({ " statementName " : " perfect_foresight_with_expectation_errors_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 ,
2018-06-04 12:31:07 +02:00
OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
prior_func { prior_func_arg } ,
options_list { move ( options_list_arg ) }
2015-10-13 17:16:10 +02:00
{
}
void
PriorPosteriorFunctionStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
2019-12-16 19:42:59 +01:00
if ( auto it2 = options_list . string_options . find ( " function " ) ;
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 ) ;
2019-12-16 19:42:59 +01:00
string type = prior_func ? " prior " : " posterior " ;
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
{
2019-12-16 19:42:59 +01:00
string type = prior_func ? " prior " : " posterior " ;
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " prior_posterior_function " , " type " : " ) " << type << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
StochSimulStatement : : StochSimulStatement ( SymbolList symbol_list_arg ,
OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
symbol_list { move ( symbol_list_arg ) } ,
options_list { move ( 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
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " order " ) ;
it ! = options_list . num_options . end ( ) )
2018-07-04 12:40:57 +02:00
mod_file_struct . order_option = max ( mod_file_struct . order_option , stoi ( it - > second ) ) ;
2008-11-04 12:00:54 +01:00
2009-10-20 18:55:31 +02:00
// Fill in mod_file_struct.partial_information
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " partial_information " ) ;
it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
2009-10-20 18:55:31 +02:00
mod_file_struct . partial_information = true ;
2009-12-09 12:50:58 +01:00
// Option k_order_solver (implicit when order >= 3)
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " k_order_solver " ) ;
( it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
2009-12-09 12:50:58 +01:00
| | mod_file_struct . order_option > = 3 )
mod_file_struct . k_order_solver = true ;
2010-05-31 18:38:49 +02:00
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " hp_filter " ) ,
it1 = options_list . num_options . find ( " bandpass.indicator " ) ,
it2 = options_list . num_options . find ( " one_sided_hp_filter " ) ;
( it ! = options_list . num_options . end ( ) & & it1 ! = options_list . num_options . end ( ) )
2017-06-01 19:58:32 +02:00
| | ( 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 ) ;
}
2019-09-09 16:16:36 +02:00
symbol_list . removeDuplicates ( " stoch_simul " , warnings ) ;
2019-12-19 14:48:55 +01:00
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous } ) ;
2019-12-19 14:48:55 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: stoch_simul: " < < e . message < < 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)
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " order " ) ,
it1 = options_list . num_options . find ( " k_order_solver " ) ;
( it1 ! = options_list . num_options . end ( ) & & it1 - > second = = " true " )
2018-07-04 12:40:57 +02:00
| | ( it ! = options_list . num_options . end ( ) & & stoi ( it - > second ) > = 3 ) )
2019-03-19 14:05:41 +01:00
output < < " options_.k_order_solver = true; " < < endl ;
2015-02-10 03:39:18 +01:00
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 ) ;
2020-02-24 14:06:59 +01:00
output < < " [info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " stoch_simul " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
ForecastStatement : : ForecastStatement ( SymbolList symbol_list_arg ,
OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
symbol_list { move ( symbol_list_arg ) } ,
options_list { move ( options_list_arg ) }
2008-05-01 14:04:48 +02:00
{
}
2019-12-19 14:48:55 +01:00
void
ForecastStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous } ) ;
2019-12-19 14:48:55 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: forecast: " < < e . message < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
2008-05-01 14:04:48 +02:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " forecast " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
RamseyModelStatement : : RamseyModelStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2014-03-08 10:05:25 +01:00
{
}
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 */
2019-12-11 19:02:00 +01:00
if ( auto it = options_list . num_options . find ( " order " ) ;
it ! = options_list . num_options . end ( ) )
2014-03-08 10:05:25 +01:00
{
2018-07-04 12:40:57 +02:00
int order = stoi ( it - > second ) ;
2014-03-08 10:05:25 +01:00
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
2019-12-11 19:02:00 +01:00
if ( auto it = options_list . num_options . find ( " partial_information " ) ;
it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
2014-03-08 10:05:25 +01:00
mod_file_struct . partial_information = true ;
// Option k_order_solver (implicit when order >= 3)
2019-12-11 19:02:00 +01:00
if ( auto it = options_list . num_options . find ( " k_order_solver " ) ;
( it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
2014-03-08 10:05:25 +01:00
| | mod_file_struct . order_option > = 3 )
mod_file_struct . k_order_solver = true ;
2019-12-12 16:03:59 +01:00
// Fill list of instruments
if ( auto it = options_list . symbol_list_options . find ( " instruments " ) ;
it ! = options_list . symbol_list_options . end ( ) )
mod_file_struct . instruments = it - > second ;
2014-03-08 10:05:25 +01:00
}
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)
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " order " ) ,
it1 = options_list . num_options . find ( " k_order_solver " ) ;
( it1 ! = options_list . num_options . end ( ) & & it1 - > second = = " true " )
2018-07-04 12:40:57 +02:00
| | ( it ! = options_list . num_options . end ( ) & & stoi ( it - > second ) > = 3 ) )
2019-03-19 14:05:41 +01:00
output < < " options_.k_order_solver = true; " < < endl ;
2015-02-10 03:39:18 +01:00
2019-03-19 14:05:41 +01:00
output < < " options_.ramsey_policy = true; " < < 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " ramsey_model " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
RamseyConstraintsStatement : : RamseyConstraintsStatement ( const SymbolTable & symbol_table_arg , constraints_t constraints_arg ) :
2018-10-04 17:18:27 +02:00
symbol_table { symbol_table_arg } ,
constraints { move ( constraints_arg ) }
2015-05-31 12:18:06 +02:00
{
}
void
RamseyConstraintsStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
2021-09-24 09:14:41 +02:00
if ( ! mod_file_struct . ramsey_model_present & & ! mod_file_struct . ramsey_policy_present )
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 ;
2018-06-04 15:03:26 +02:00
for ( auto it = constraints . begin ( ) ; it ! = constraints . end ( ) ; + + it )
2015-05-31 12:18:06 +02:00
{
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 )
{
2018-07-18 16:18:26 +02:00
case BinaryOpcode : : less :
2017-06-01 19:58:32 +02:00
output < < ' < ' ;
break ;
2018-07-18 16:18:26 +02:00
case BinaryOpcode : : greater :
2017-06-01 19:58:32 +02:00
output < < ' > ' ;
break ;
2018-07-18 16:18:26 +02:00
case BinaryOpcode : : lessEqual :
2017-06-01 19:58:32 +02:00
output < < " <= " ;
break ;
2018-07-18 16:18:26 +02:00
case BinaryOpcode : : greaterEqual :
2017-06-01 19:58:32 +02:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " ramsey_constraints " ) "
< < R " (, " ramsey_model_constraints " : [) " < < endl ;
2018-06-04 15:03:26 +02:00
for ( auto it = constraints . begin ( ) ; it ! = constraints . end ( ) ; + + it )
2017-02-08 18:29:57 +01:00
{
if ( it ! = constraints . begin ( ) )
2017-06-14 07:01:31 +02:00
output < < " , " ;
2019-04-03 16:32:52 +02:00
output < < R " ({ " constraint " : " ) " << symbol_table.getName(it->endo) << " " ;
2017-06-14 07:01:31 +02:00
switch ( it - > code )
{
2018-07-18 16:18:26 +02:00
case BinaryOpcode : : less :
2017-06-14 07:01:31 +02:00
output < < ' < ' ;
break ;
2018-07-18 16:18:26 +02:00
case BinaryOpcode : : greater :
2017-06-14 07:01:31 +02:00
output < < ' > ' ;
break ;
2018-07-18 16:18:26 +02:00
case BinaryOpcode : : lessEqual :
2017-06-14 07:01:31 +02:00
output < < " <= " ;
break ;
2018-07-18 16:18:26 +02:00
case BinaryOpcode : : greaterEqual :
2017-06-14 07:01:31 +02:00
output < < " >= " ;
break ;
default :
cerr < < " Ramsey constraints: this shouldn't happen. " < < endl ;
2019-12-16 19:42:59 +01:00
exit ( EXIT_FAILURE ) ;
2017-06-14 07:01:31 +02:00
}
2017-02-08 18:29:57 +01:00
output < < " " ;
2018-05-29 11:59:42 +02:00
it - > expression - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " } ) " << endl;
2017-02-08 18:29:57 +01:00
}
output < < " ] " < < endl ;
output < < " } " ;
}
2016-12-27 13:46:01 +01:00
RamseyPolicyStatement : : RamseyPolicyStatement ( const SymbolTable & symbol_table_arg ,
2019-12-19 14:48:55 +01:00
SymbolList symbol_list_arg ,
2018-06-04 12:31:07 +02:00
OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
symbol_table { symbol_table_arg } ,
2019-12-19 14:48:55 +01:00
symbol_list { move ( symbol_list_arg ) } ,
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2008-02-03 11:28:36 +01:00
{
}
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 */
2019-12-11 19:02:00 +01:00
if ( auto it = options_list . num_options . find ( " order " ) ;
it ! = options_list . num_options . end ( ) )
2008-11-04 11:52:06 +01:00
{
2018-07-04 12:40:57 +02:00
int order = stoi ( it - > second ) ;
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
2019-12-11 19:02:00 +01:00
if ( auto it = options_list . num_options . find ( " partial_information " ) ;
it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
2009-10-20 18:55:31 +02:00
mod_file_struct . partial_information = true ;
2009-12-09 12:50:58 +01:00
// Option k_order_solver (implicit when order >= 3)
2019-12-11 19:02:00 +01:00
if ( auto it = options_list . num_options . find ( " k_order_solver " ) ;
( it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
2009-12-09 12:50:58 +01:00
| | mod_file_struct . order_option > = 3 )
mod_file_struct . k_order_solver = true ;
2019-12-12 16:03:59 +01:00
// Fill list of instruments
if ( auto it = options_list . symbol_list_options . find ( " instruments " ) ;
it ! = options_list . symbol_list_options . end ( ) )
mod_file_struct . instruments = it - > second ;
2008-02-03 11:28:36 +01:00
2019-12-19 14:48:55 +01:00
try
2016-12-27 13:46:01 +01:00
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous } ) ;
2019-12-19 14:48:55 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: ramsey_policy: " < < e . message < < endl ;
exit ( EXIT_FAILURE ) ;
2016-12-27 13:46:01 +01:00
}
}
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)
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " order " ) ,
it1 = options_list . num_options . find ( " k_order_solver " ) ;
2019-12-20 16:59:30 +01:00
( it1 ! = options_list . num_options . end ( ) & & it1 - > second = = " true " )
2018-07-04 12:40:57 +02:00
| | ( it ! = options_list . num_options . end ( ) & & stoi ( it - > second ) > = 3 ) )
2019-03-19 14:05:41 +01:00
output < < " options_.k_order_solver = true; " < < endl ;
2015-02-10 03:39:18 +01:00
2008-02-03 11:28:36 +01:00
options_list . writeOutput ( output ) ;
2019-12-19 14:48:55 +01:00
symbol_list . writeOutput ( " var_list_ " , output ) ;
output < < " 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " ramsey_policy " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
2019-12-19 14:48:55 +01:00
if ( ! symbol_list . empty ( ) )
2017-02-08 18:29:57 +01:00
{
2019-12-19 14:48:55 +01:00
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
2017-02-08 18:29:57 +01:00
}
2019-12-19 14:48:55 +01:00
output < < " } " ;
2017-02-08 18:29:57 +01:00
}
2021-12-03 13:17:34 +01:00
EvaluatePlannerObjectiveStatement : : EvaluatePlannerObjectiveStatement ( OptionsList options_list_arg ) :
options_list { move ( options_list_arg ) }
{
}
2019-12-12 11:28:07 +01:00
void
2021-12-03 13:17:34 +01:00
EvaluatePlannerObjectiveStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2019-12-12 11:28:07 +01:00
{
2021-12-03 13:17:34 +01:00
options_list . writeOutput ( output ) ;
2019-12-12 11:28:07 +01:00
output < < " oo_.planner_objective_value = evaluate_planner_objective(M_, options_, oo_); " < < endl ;
}
void
2021-12-03 13:17:34 +01:00
EvaluatePlannerObjectiveStatement : : writeJsonOutput ( ostream & output ) const
2019-12-12 11:28:07 +01:00
{
2021-12-03 13:17:34 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
2019-12-12 11:28:07 +01:00
output < < R " ({ " statementName " : " evaluate_planner_objective " }) " ;
}
2018-06-04 12:31:07 +02:00
DiscretionaryPolicyStatement : : DiscretionaryPolicyStatement ( SymbolList symbol_list_arg ,
OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
symbol_list { move ( symbol_list_arg ) } ,
options_list { move ( options_list_arg ) }
2011-03-13 21:19:55 +01:00
{
}
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 */
2019-12-11 19:02:00 +01:00
if ( auto it = options_list . num_options . find ( " order " ) ;
it ! = options_list . num_options . end ( ) )
2011-03-13 21:19:55 +01:00
{
2018-07-04 12:40:57 +02:00
int order = stoi ( it - > second ) ;
2011-03-13 21:19:55 +01:00
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
2019-12-11 19:02:00 +01:00
if ( auto it = options_list . num_options . find ( " partial_information " ) ;
it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
2011-03-13 21:19:55 +01:00
mod_file_struct . partial_information = true ;
// Option k_order_solver (implicit when order >= 3)
2019-12-11 19:02:00 +01:00
if ( auto it = options_list . num_options . find ( " k_order_solver " ) ;
( it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
2011-03-13 21:19:55 +01:00
| | mod_file_struct . order_option > = 3 )
mod_file_struct . k_order_solver = true ;
2019-12-12 16:03:59 +01:00
// Fill list of instruments
if ( auto it = options_list . symbol_list_options . find ( " instruments " ) ;
it ! = options_list . symbol_list_options . end ( ) )
mod_file_struct . instruments = it - > second ;
2019-12-19 14:48:55 +01:00
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous } ) ;
2019-12-19 14:48:55 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: discretionary_policy: " < < e . message < < endl ;
exit ( EXIT_FAILURE ) ;
}
2011-03-13 21:19:55 +01:00
}
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)
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " order " ) ,
it1 = options_list . num_options . find ( " k_order_solver " ) ;
( it1 ! = options_list . num_options . end ( ) & & it1 - > second = = " true " )
2018-07-04 12:40:57 +02:00
| | ( it ! = options_list . num_options . end ( ) & & stoi ( it - > second ) > = 3 ) )
2019-03-19 14:05:41 +01:00
output < < " options_.k_order_solver = true; " < < endl ;
2015-02-10 03:39:18 +01:00
2011-03-13 21:19:55 +01:00
options_list . writeOutput ( output ) ;
symbol_list . writeOutput ( " var_list_ " , output ) ;
2020-02-24 14:06:59 +01:00
output < < " [info, oo_, options_, M_] = discretionary_policy(M_, options_, oo_, 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " discretionary_policy " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2021-07-13 15:38:25 +02:00
OccbinSetupStatement : : OccbinSetupStatement ( OptionsList options_list_arg ) :
options_list { move ( options_list_arg ) }
{
}
void
OccbinSetupStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
options_list . writeOutput ( output , " options_occbin_ " ) ;
output < < " [M_, options_] = occbin.setup(M_, options_, options_occbin_); " < < endl ;
}
void
OccbinSetupStatement : : writeJsonOutput ( ostream & output ) const
{
output < < R " ({ " statementName " : " occbin_setup " ) " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
OccbinSolverStatement : : OccbinSolverStatement ( OptionsList options_list_arg ) :
options_list { move ( options_list_arg ) }
{
}
void
OccbinSolverStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
options_list . writeOutput ( output , " options_.occbin " ) ;
output < < " oo_ = occbin.solver(M_, oo_, options_); " < < endl ;
}
void
OccbinSolverStatement : : writeJsonOutput ( ostream & output ) const
{
output < < R " ({ " statementName " : " occbin_solver " ) " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
OccbinWriteRegimesStatement : : OccbinWriteRegimesStatement ( OptionsList options_list_arg ) :
options_list { move ( options_list_arg ) }
{
}
void
OccbinWriteRegimesStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
options_list . writeOutput ( output , " options_.occbin " ) ;
output < < " occbin.write_regimes_to_xls(oo_.occbin.regime_history, M_, options_); " < < endl ;
}
void
OccbinWriteRegimesStatement : : writeJsonOutput ( ostream & output ) const
{
output < < R " ({ " statementName " : " occbin_write_regimes_xls " ) " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
OccbinGraphStatement : : OccbinGraphStatement ( SymbolList symbol_list_arg ,
OptionsList options_list_arg ) :
symbol_list { move ( symbol_list_arg ) } ,
options_list { move ( options_list_arg ) }
{
}
void
OccbinGraphStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
symbol_list . writeOutput ( " var_list_ " , output ) ;
options_list . writeOutput ( output , " options_occbin_ " ) ;
output < < " occbin.graph(M_, options_, options_occbin_, oo_, var_list_); " < < endl ;
}
void
OccbinGraphStatement : : writeJsonOutput ( ostream & output ) const
{
output < < R " ({ " statementName " : " occbin_graph " ) " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2020-02-04 17:48:37 +01:00
EstimationStatement : : EstimationStatement ( const SymbolTable & symbol_table_arg ,
SymbolList symbol_list_arg ,
2018-06-04 12:31:07 +02:00
OptionsList options_list_arg ) :
2020-02-04 17:48:37 +01:00
symbol_table { symbol_table_arg } ,
2018-10-04 17:18:27 +02:00
symbol_list { move ( symbol_list_arg ) } ,
options_list { move ( 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
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " order " ) ;
it ! = options_list . num_options . end ( ) )
2012-06-06 17:06:28 +02:00
{
2018-07-04 12:40:57 +02:00
int order = stoi ( it - > second ) ;
2017-06-01 19:58:32 +02:00
2012-06-06 17:06:28 +02:00
if ( order > 2 )
2019-12-20 11:48:50 +01:00
mod_file_struct . k_order_solver = true ;
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
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " partial_information " ) ;
it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
2009-10-20 18:55:31 +02:00
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
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " analytic_derivation " ) ;
it ! = options_list . num_options . end ( ) & & it - > second = = " 1 " )
2012-06-07 15:26:49 +02:00
mod_file_struct . estimation_analytic_derivation = true ;
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " dsge_var " ) ;
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
2019-12-16 19:42:59 +01:00
if ( options_list . string_options . find ( " dsge_var " ) ! = options_list . string_options . end ( ) )
2010-06-11 21:19:30 +02:00
mod_file_struct . dsge_var_estimated = true ;
// Fill in mod_file_struct.bayesian_irf_present
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " bayesian_irf " ) ;
it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
2010-06-11 21:19:30 +02:00
mod_file_struct . bayesian_irf_present = true ;
2019-12-16 19:42:59 +01:00
if ( options_list . num_options . find ( " dsge_varlag " ) ! = 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 ) ;
}
2019-12-19 14:48:55 +01:00
2020-07-17 11:59:11 +02:00
if ( auto it = options_list . num_options . find ( " mh_tune_jscale.status " ) ;
it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
2020-02-28 18:28:09 +01:00
{
2020-07-17 11:59:11 +02:00
if ( options_list . num_options . find ( " mh_jscale " ) ! = options_list . num_options . end ( ) )
{
cerr < < " ERROR: The mh_tune_jscale and mh_jscale options of the estimation statement are incompatible. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2020-02-28 18:28:09 +01:00
}
2020-07-17 11:59:11 +02:00
else if ( options_list . num_options . find ( " mh_tune_jscale.guess " ) ! = options_list . num_options . end ( ) )
2020-02-29 09:54:18 +01:00
{
cerr < < " ERROR: The option mh_tune_guess in estimation statement cannot be used without option mh_tune_jscale. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2020-07-17 11:59:11 +02:00
2020-02-29 09:54:18 +01:00
2020-02-04 17:48:37 +01:00
/* Check that we are not trying to estimate a parameter appearing in the
planner discount factor ( see dynare # 1173 ) */
vector < int > estimated_params_in_planner_discount ;
set_intersection ( mod_file_struct . estimated_parameters . begin ( ) ,
mod_file_struct . estimated_parameters . end ( ) ,
mod_file_struct . parameters_in_planner_discount . begin ( ) ,
mod_file_struct . parameters_in_planner_discount . end ( ) ,
back_inserter ( estimated_params_in_planner_discount ) ) ;
if ( ! estimated_params_in_planner_discount . empty ( ) )
{
cerr < < " ERROR: It is not possible to estimate a parameter ( "
< < symbol_table . getName ( estimated_params_in_planner_discount [ 0 ] )
< < " ) that appears in the discount factor of the planner (i.e. in the 'planner_discount' option). " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2019-12-19 14:48:55 +01:00
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous } ) ;
2019-12-19 14:48:55 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: estimation: " < < e . message < < 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
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " order " ) ;
it = = options_list . num_options . end ( ) )
2012-06-06 17:06:28 +02:00
output < < " options_.order = 1; " < < endl ;
2019-12-19 22:43:52 +01:00
else if ( stoi ( it - > second ) > = 2 )
{
output < < " options_.particle.status = true; " < < endl ;
if ( stoi ( it - > second ) > 2 )
2019-12-20 11:48:50 +01:00
output < < " options_.k_order_solver = true; " < < endl ;
2019-12-19 22:43:52 +01:00
}
2012-06-06 17:06:28 +02:00
2013-06-03 15:56:10 +02:00
// Do not check for the steady state in diffuse filter mode (#400)
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " diffuse_filter " ) ;
it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
2019-03-19 14:05:41 +01:00
output < < " options_.steadystate.nocheck = true; " < < endl ;
2013-06-03 15:56:10 +02:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " estimation " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
DynareSensitivityStatement : : DynareSensitivityStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2008-02-03 11:28:36 +01:00
{
}
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
{
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " identification " ) ;
it ! = options_list . num_options . end ( ) & & it - > second = = " 1 " )
2020-01-20 17:23:51 +01:00
{
mod_file_struct . identification_present = true ;
// The following triggers 3rd order derivatives, see preprocessor#40
mod_file_struct . identification_order = max ( mod_file_struct . identification_order , 2 ) ;
}
2019-01-09 14:48:25 +01:00
mod_file_struct . sensitivity_present = true ;
2009-10-14 18:16:43 +02:00
}
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 ) */
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " nodisplay " ) ;
it ! = options_list . num_options . end ( ) )
2012-06-15 15:35:00 +02:00
output < < " options_.nodisplay = " < < it - > second < < " ; " < < endl ;
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " nograph " ) ;
it ! = options_list . num_options . end ( ) )
2012-06-15 15:35:00 +02:00
output < < " options_.nograph = " < < it - > second < < " ; " < < endl ;
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . string_options . find ( " graph_format " ) ;
it ! = options_list . string_options . end ( ) )
output < < " options_.graph_format = ' " < < it - > 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " dynare_sensitivity " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
RplotStatement : : RplotStatement ( SymbolList symbol_list_arg ) :
2018-10-04 17:18:27 +02:00
symbol_list { move ( symbol_list_arg ) }
2008-02-03 11:28:36 +01:00
{
}
2019-12-23 16:22:23 +01:00
void
RplotStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous , SymbolType : : exogenous } ) ;
2019-12-23 16:22:23 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: rplot: " < < e . message < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " rplot " ) " ;
2017-02-08 18:29:57 +01:00
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2011-11-20 20:16:02 +01:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " unit_root_vars " , ) "
< < R " ( " diffuse_filter " : 1, ) "
< < R " ( " steady_state . nocheck " : 1}) " ;
2017-02-08 18:29:57 +01:00
}
2018-10-04 17:18:27 +02:00
PeriodsStatement : : PeriodsStatement ( int periods_arg ) : periods { periods_arg }
2008-02-03 11:28:36 +01:00
{
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " periods " , ) "
< < R " ( " periods " : ) " < < periods < < " } " ;
2017-02-08 18:29:57 +01:00
}
2018-10-04 17:18:27 +02:00
DsampleStatement : : DsampleStatement ( int val1_arg ) : val1 { val1_arg } , val2 { - 1 }
2008-02-03 11:28:36 +01:00
{
}
2018-10-04 17:18:27 +02:00
DsampleStatement : : DsampleStatement ( int val1_arg , int val2_arg ) : val1 { val1_arg } , val2 { val2_arg }
2008-02-03 11:28:36 +01:00
{
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " dsample " , ) "
< < R " ( " value1 " : ) " < < val1 < < " , "
< < R " ( " value2 " : ) " < < val2 < < " } " ;
2017-02-08 18:29:57 +01:00
}
2021-09-08 16:38:15 +02:00
AbstractEstimatedParamsStatement : : AbstractEstimatedParamsStatement ( vector < EstimationParams > estim_params_list_arg ,
const SymbolTable & symbol_table_arg ) :
2018-10-04 17:18:27 +02:00
estim_params_list { move ( estim_params_list_arg ) } ,
symbol_table { symbol_table_arg }
2008-02-03 11:28:36 +01:00
{
}
2010-06-11 21:19:30 +02:00
void
2021-09-08 16:38:15 +02:00
AbstractEstimatedParamsStatement : : commonCheckPass ( ) const
2010-06-11 21:19:30 +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 ;
2018-06-04 14:17:36 +02:00
set < pair < string , string > > already_declared_corr ;
2019-12-20 16:59:30 +01:00
for ( const auto & it : estim_params_list )
2013-02-26 12:37:35 +01:00
{
2018-06-04 12:26:16 +02:00
if ( it . type = = 3 ) // Correlation
2013-02-26 12:37:35 +01:00
{
// Use lexical ordering for the pair of symbols
2021-09-08 16:38:15 +02:00
auto x = it . name < it . name2 ? make_pair ( it . name , it . name2 ) : make_pair ( it . name2 , it . name ) ;
2013-02-26 12:37:35 +01:00
if ( already_declared_corr . find ( x ) = = already_declared_corr . end ( ) )
already_declared_corr . insert ( x ) ;
else
{
2021-09-08 16:38:15 +02:00
cerr < < " ERROR: in ` " < < blockName ( ) < < " ' block, the correlation between " < < it . name < < " and " < < it . name2 < < " is declared twice. " < < endl ;
2013-02-26 12:37:35 +01:00
exit ( EXIT_FAILURE ) ;
}
}
else
{
2018-06-04 12:26:16 +02:00
if ( already_declared . find ( it . name ) = = already_declared . end ( ) )
already_declared . insert ( it . name ) ;
2013-02-26 12:37:35 +01:00
else
{
2021-09-08 16:38:15 +02:00
cerr < < " ERROR: in ` " < < blockName ( ) < < " ' block, the symbol " < < it . name < < " is declared twice. " < < endl ;
2013-02-26 12:37:35 +01:00
exit ( EXIT_FAILURE ) ;
}
}
}
2021-09-08 17:06:10 +02:00
/* Check that a parameter declared in this block is not used in expressions
associated to other parameters in the same block ( see issue # 77 ) */
// First compute the symbol IDs of parameters declared in this block
set < int > declared_params ;
2021-09-08 18:59:46 +02:00
for ( const string & name : already_declared )
if ( name ! = " dsge_prior_weight " )
declared_params . insert ( symbol_table . getID ( name ) ) ;
2021-09-08 17:06:10 +02:00
// Then look for (apparently) recursive definitions
for ( const auto & it : estim_params_list )
{
set < int > used_params ;
it . init_val - > collectVariables ( SymbolType : : parameter , used_params ) ;
it . low_bound - > collectVariables ( SymbolType : : parameter , used_params ) ;
it . up_bound - > collectVariables ( SymbolType : : parameter , used_params ) ;
it . mean - > collectVariables ( SymbolType : : parameter , used_params ) ;
it . std - > collectVariables ( SymbolType : : parameter , used_params ) ;
it . p3 - > collectVariables ( SymbolType : : parameter , used_params ) ;
it . p4 - > collectVariables ( SymbolType : : parameter , used_params ) ;
it . jscale - > collectVariables ( SymbolType : : parameter , used_params ) ;
vector < int > intersect ;
set_intersection ( declared_params . begin ( ) , declared_params . end ( ) ,
used_params . begin ( ) , used_params . end ( ) ,
back_inserter ( intersect ) ) ;
if ( intersect . size ( ) > 0 )
{
cerr < < " ERROR: in ` " < < blockName ( ) < < " ' block, the value of estimated parameter "
< < symbol_table . getName ( intersect [ 0 ] ) < < " is used in the declaration for " ;
if ( it . type = = 3 )
cerr < < " correlation between " < < it . name < < " and " < < it . name2 ;
else // either a parameter, the stderr of an exo, or the measurement error of an endo
cerr < < " symbol " < < it . name ;
cerr < < " . This behaviour is undefined. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
2021-09-08 16:38:15 +02:00
}
EstimatedParamsStatement : : EstimatedParamsStatement ( vector < EstimationParams > estim_params_list_arg ,
const SymbolTable & symbol_table_arg ) :
AbstractEstimatedParamsStatement ( move ( estim_params_list_arg ) , symbol_table_arg )
{
}
void
EstimatedParamsStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
commonCheckPass ( ) ;
for ( const auto & it : estim_params_list )
{
if ( it . name = = " dsge_prior_weight " )
mod_file_struct . dsge_prior_weight_in_estimated_params = true ;
// Handle case of degenerate beta prior
if ( it . prior = = PriorDistributions : : beta )
try
{
if ( it . mean - > eval ( eval_context_t ( ) ) = = 0.5
& & it . std - > eval ( eval_context_t ( ) ) = = 0.5 )
{
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
}
}
2013-11-29 14:50:58 +01:00
// Fill in mod_file_struct.estimated_parameters (related to #469)
2019-12-20 16:59:30 +01:00
for ( const auto & it : estim_params_list )
2018-06-04 12:26:16 +02:00
if ( it . type = = 2 & & it . name ! = " dsge_prior_weight " )
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
{
2018-10-25 10:08:21 +02:00
output < < " estim_params_.var_exo = zeros(0, 10); " < < endl
< < " estim_params_.var_endo = zeros(0, 10); " < < endl
2018-10-26 11:11:10 +02:00
< < " estim_params_.corrx = zeros(0, 11); " < < endl
< < " estim_params_.corrn = zeros(0, 11); " < < endl
2018-10-25 10:08:21 +02:00
< < " estim_params_.param_vals = zeros(0, 10); " < < endl ;
2008-02-03 11:28:36 +01:00
2019-12-20 16:59:30 +01:00
for ( const auto & it : estim_params_list )
2008-02-03 11:28:36 +01:00
{
2018-06-04 12:26:16 +02:00
int symb_id = symbol_table . getTypeSpecificID ( it . name ) + 1 ;
SymbolType symb_type = symbol_table . getType ( it . name ) ;
2009-01-22 16:05:38 +01:00
2018-06-04 12:26:16 +02:00
switch ( it . type )
2008-02-03 11:28:36 +01:00
{
case 1 :
2018-07-17 18:34:07 +02:00
if ( symb_type = = SymbolType : : exogenous )
2008-02-03 11:28:36 +01:00
output < < " estim_params_.var_exo = [estim_params_.var_exo; " ;
2018-07-17 18:34:07 +02:00
else if ( symb_type = = SymbolType : : endogenous )
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 :
2018-07-17 18:34:07 +02:00
if ( symb_type = = SymbolType : : exogenous )
2008-02-03 11:28:36 +01:00
output < < " estim_params_.corrx = [estim_params_.corrx; " ;
2018-07-17 18:34:07 +02:00
else if ( symb_type = = SymbolType : : endogenous )
2008-02-03 11:28:36 +01:00
output < < " estim_params_.corrn = [estim_params_.corrn; " ;
2018-10-26 11:11:10 +02: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 < < " , " ;
2018-06-04 12:26:16 +02:00
it . init_val - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " , " ;
2018-06-04 12:26:16 +02:00
it . low_bound - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " , " ;
2018-06-04 12:26:16 +02:00
it . up_bound - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " , "
2018-07-18 16:52:12 +02:00
< < static_cast < int > ( it . prior ) < < " , " ;
2018-06-04 12:26:16 +02:00
it . mean - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " , " ;
2018-06-04 12:26:16 +02:00
it . std - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " , " ;
2018-06-04 12:26:16 +02:00
it . p3 - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " , " ;
2018-06-04 12:26:16 +02:00
it . p4 - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " , " ;
2018-06-04 12:26:16 +02:00
it . jscale - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " ]; " < < endl ;
2008-02-03 11:28:36 +01:00
}
}
2017-02-08 18:29:57 +01:00
void
EstimatedParamsStatement : : writeJsonOutput ( ostream & output ) const
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " estimated_params " , ) "
< < R " ( " params " : [) " ;
2019-12-16 19:42:59 +01:00
for ( auto it = estim_params_list . begin ( ) ; it ! = estim_params_list . end ( ) ; + + it )
2017-02-08 18:29:57 +01:00
{
if ( it ! = estim_params_list . begin ( ) )
output < < " , " ;
output < < " { " ;
switch ( it - > type )
{
case 1 :
2019-04-03 16:32:52 +02:00
output < < R " ( " var " : " ) " << it->name << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
break ;
case 2 :
2019-04-03 16:32:52 +02:00
output < < R " ( " param " : " ) " << it->name << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
break ;
case 3 :
2019-04-03 16:32:52 +02:00
output < < R " ( " var1 " : " ) " << it->name << R " ( " ,) "
< < R " ( " var2 " : " ) " << it->name2 << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
break ;
}
2019-04-03 16:32:52 +02:00
output < < R " (, " init_val " : " ) " ;
2018-05-29 11:59:42 +02:00
it - > init_val - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " , " lower_bound " : " ) " ;
2018-05-29 11:59:42 +02:00
it - > low_bound - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " , " upper_bound " : " ) " ;
2018-05-29 11:59:42 +02:00
it - > up_bound - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " , " prior_distribution " : ) "
2018-07-18 16:52:12 +02:00
< < static_cast < int > ( it - > prior )
2019-04-03 16:32:52 +02:00
< < R " (, " mean " : " ) " ;
2018-05-29 11:59:42 +02:00
it - > mean - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " , " std " : " ) " ;
2018-05-29 11:59:42 +02:00
it - > std - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " , " p3 " : " ) " ;
2018-05-29 11:59:42 +02:00
it - > p3 - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " , " p4 " : " ) " ;
2018-05-29 11:59:42 +02:00
it - > p4 - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " , " jscale " : " ) " ;
2018-05-29 11:59:42 +02:00
it - > jscale - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " } ) " << endl;
2017-02-08 18:29:57 +01:00
}
output < < " ] "
< < " } " ;
}
2018-06-04 12:31:07 +02:00
EstimatedParamsInitStatement : : EstimatedParamsInitStatement ( vector < EstimationParams > estim_params_list_arg ,
2013-11-06 10:36:58 +01:00
const SymbolTable & symbol_table_arg ,
const bool use_calibration_arg ) :
2021-09-08 16:38:15 +02:00
AbstractEstimatedParamsStatement ( move ( estim_params_list_arg ) , symbol_table_arg ) ,
2018-10-04 17:18:27 +02:00
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 )
{
2021-09-08 16:38:15 +02:00
commonCheckPass ( ) ;
2013-12-09 16:23:49 +01:00
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 ;
2018-10-25 10:08:21 +02:00
bool skipline = false ;
2019-12-20 16:59:30 +01:00
for ( const auto & it : estim_params_list )
2008-02-03 11:28:36 +01:00
{
2018-06-04 12:26:16 +02:00
int symb_id = symbol_table . getTypeSpecificID ( it . name ) + 1 ;
SymbolType symb_type = symbol_table . getType ( it . name ) ;
2009-01-22 16:05:38 +01:00
2018-06-04 12:26:16 +02:00
if ( it . type < 3 )
2008-02-03 11:28:36 +01:00
{
2018-07-17 18:34:07 +02:00
if ( symb_type = = SymbolType : : exogenous )
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 ;
2018-10-25 10:08:21 +02:00
output < < " if isempty(tmp1) " < < endl ;
output < < " disp(sprintf('The standard deviation of %s is not estimated (the value provided in estimated_params_init is not used).', M_.exo_names{ " < < symb_id < < " })) " < < endl ;
skipline = true ;
output < < " else " < < endl ;
output < < " estim_params_.var_exo(tmp1,2) = " ;
2018-06-04 12:26:16 +02:00
it . init_val - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " ; " < < endl ;
2018-10-25 10:08:21 +02:00
output < < " end " < < endl ;
2008-02-03 11:28:36 +01:00
}
2018-07-17 18:34:07 +02:00
else if ( symb_type = = SymbolType : : endogenous )
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 ;
2018-10-25 10:08:21 +02:00
output < < " if isempty(tmp1) " < < endl ;
output < < " disp(sprintf('The standard deviation of the measurement error on %s is not estimated (the value provided in estimated_params_init is not used).', M_.endo_names{ " < < symb_id < < " })) " < < endl ;
skipline = true ;
output < < " else " < < endl ;
output < < " estim_params_.var_endo(tmp1,2) = " ;
2018-06-04 12:26:16 +02:00
it . init_val - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " ; " < < endl ;
2018-10-25 10:08:21 +02:00
output < < " end " < < endl ;
2008-02-03 11:28:36 +01:00
}
2018-07-17 18:34:07 +02:00
else if ( symb_type = = SymbolType : : parameter )
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 ;
2018-10-25 10:08:21 +02:00
output < < " if isempty(tmp1) " < < endl ;
output < < " disp(sprintf('Parameter %s is not estimated (the value provided in estimated_params_init is not used).', M_.param_names{ " < < symb_id < < " })) " < < endl ;
skipline = true ;
output < < " else " < < endl ;
output < < " estim_params_.param_vals(tmp1,2) = " ;
2018-06-04 12:26:16 +02:00
it . init_val - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " ; " < < endl ;
2018-10-25 10:08:21 +02:00
output < < " end " < < endl ;
2008-02-03 11:28:36 +01:00
}
}
else
{
2018-07-17 18:34:07 +02:00
if ( symb_type = = SymbolType : : exogenous )
2008-02-03 11:28:36 +01:00
{
2018-06-04 12:26:16 +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 ;
2018-10-25 10:08:21 +02:00
output < < " if isempty(tmp1) " < < endl ;
output < < " disp(sprintf('The correlation between %s and %s is not estimated (the value provided in estimated_params_init is not used).', M_.exo_names{ "
< < symb_id < < " }, M_.exo_names{ " < < symbol_table . getTypeSpecificID ( it . name2 ) + 1 < < " })) " < < endl ;
skipline = true ;
output < < " else " < < endl ;
output < < " estim_params_.corrx(tmp1,3) = " ;
2018-06-04 12:26:16 +02:00
it . init_val - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " ; " < < endl ;
2018-10-25 10:08:21 +02:00
output < < " end " < < endl ;
2008-02-03 11:28:36 +01:00
}
2018-07-17 18:34:07 +02:00
else if ( symb_type = = SymbolType : : endogenous )
2008-02-03 11:28:36 +01:00
{
2018-06-04 12:26:16 +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 ;
2018-10-25 10:08:21 +02:00
output < < " if isempty(tmp1) " < < endl ;
output < < " disp(sprintf('The correlation between measurement errors on %s and %s is not estimated (the value provided in estimated_params_init is not used).', M_.endo_names{ "
< < symb_id < < " }, M_.endo_names{ " < < symbol_table . getTypeSpecificID ( it . name2 ) + 1 < < " })) " < < endl ;
skipline = true ;
output < < " else " < < endl ;
output < < " estim_params_.corrn(tmp1,3) = " ;
2018-06-04 12:26:16 +02:00
it . init_val - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " ; " < < endl ;
2018-10-25 10:08:21 +02:00
output < < " end " < < endl ;
2008-02-03 11:28:36 +01:00
}
}
}
2018-10-25 10:08:21 +02:00
if ( skipline = = true )
output < < " skipline() " < < endl ;
2008-02-03 11:28:36 +01:00
}
2017-02-08 18:29:57 +01:00
void
EstimatedParamsInitStatement : : writeJsonOutput ( ostream & output ) const
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " estimated_params_init " ) " ;
2017-02-08 18:29:57 +01:00
if ( use_calibration )
2019-04-03 16:32:52 +02:00
output < < R " (, " use_calibration_initialization " : 1) " ;
2017-02-08 18:29:57 +01:00
2019-04-03 16:32:52 +02:00
output < < R " (, " params " : [) " ;
2019-12-16 19:42:59 +01:00
for ( auto it = estim_params_list . begin ( ) ; it ! = estim_params_list . end ( ) ; + + it )
2017-02-08 18:29:57 +01:00
{
if ( it ! = estim_params_list . begin ( ) )
output < < " , " ;
output < < " { " ;
switch ( it - > type )
{
case 1 :
2019-04-03 16:32:52 +02:00
output < < R " ( " var " : " ) " << it->name << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
break ;
case 2 :
2019-04-03 16:32:52 +02:00
output < < R " ( " param " : " ) " << it->name << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
break ;
case 3 :
2019-04-03 16:32:52 +02:00
output < < R " ( " var1 " : " ) " << it->name << R " ( " ,) "
< < R " ( " var2 " : " ) " << it->name2 << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
break ;
}
2019-04-03 16:32:52 +02:00
output < < R " (, " init_val " : " ) " ;
2018-05-29 11:59:42 +02:00
it - > init_val - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " } ) " ;
2017-02-08 18:29:57 +01:00
}
output < < " ] "
< < " } " ;
}
2018-06-04 12:31:07 +02:00
EstimatedParamsBoundsStatement : : EstimatedParamsBoundsStatement ( vector < EstimationParams > estim_params_list_arg ,
2008-02-03 11:28:36 +01:00
const SymbolTable & symbol_table_arg ) :
2021-09-08 16:38:15 +02:00
AbstractEstimatedParamsStatement ( move ( estim_params_list_arg ) , symbol_table_arg )
{
}
void
EstimatedParamsBoundsStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2008-02-03 11:28:36 +01:00
{
2021-09-08 16:38:15 +02:00
commonCheckPass ( ) ;
2008-02-03 11:28:36 +01:00
}
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
{
2019-12-20 16:59:30 +01:00
for ( const auto & it : estim_params_list )
2008-02-03 11:28:36 +01:00
{
2018-06-04 12:26:16 +02:00
int symb_id = symbol_table . getTypeSpecificID ( it . name ) + 1 ;
SymbolType symb_type = symbol_table . getType ( it . name ) ;
2009-01-22 16:05:38 +01:00
2018-06-04 12:26:16 +02:00
if ( it . type < 3 )
2008-02-03 11:28:36 +01:00
{
2018-07-17 18:34:07 +02:00
if ( symb_type = = SymbolType : : exogenous )
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) = " ;
2018-06-04 12:26:16 +02:00
it . low_bound - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " ; " < < endl ;
output < < " estim_params_.var_exo(tmp1,4) = " ;
2018-06-04 12:26:16 +02:00
it . up_bound - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
2018-07-17 18:34:07 +02:00
else if ( symb_type = = SymbolType : : endogenous )
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) = " ;
2018-06-04 12:26:16 +02:00
it . low_bound - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " ; " < < endl ;
output < < " estim_params_.var_endo(tmp1,4) = " ;
2018-06-04 12:26:16 +02:00
it . up_bound - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
2018-07-17 18:34:07 +02:00
else if ( symb_type = = SymbolType : : parameter )
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) = " ;
2018-06-04 12:26:16 +02:00
it . low_bound - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " ; " < < endl ;
output < < " estim_params_.param_vals(tmp1,4) = " ;
2018-06-04 12:26:16 +02:00
it . up_bound - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
}
else
{
2018-07-17 18:34:07 +02:00
if ( symb_type = = SymbolType : : exogenous )
2008-02-03 11:28:36 +01:00
{
2018-06-04 12:26:16 +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) = " ;
2018-06-04 12:26:16 +02:00
it . low_bound - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " ; " < < endl ;
output < < " estim_params_.corrx(tmp1,5) = " ;
2018-06-04 12:26:16 +02:00
it . up_bound - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
2018-07-17 18:34:07 +02:00
else if ( symb_type = = SymbolType : : endogenous )
2008-02-03 11:28:36 +01:00
{
2018-06-04 12:26:16 +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) = " ;
2018-06-04 12:26:16 +02:00
it . low_bound - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " ; " < < endl ;
output < < " estim_params_.corrn(tmp1,5) = " ;
2018-06-04 12:26:16 +02:00
it . up_bound - > writeOutput ( output ) ;
2009-01-22 16:05:38 +01:00
output < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
}
}
}
2017-02-08 18:29:57 +01:00
void
EstimatedParamsBoundsStatement : : writeJsonOutput ( ostream & output ) const
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " estimated_params_bounds " , ) "
< < R " ( " params " : [) " ;
2017-02-08 18:29:57 +01:00
2019-12-16 19:42:59 +01:00
for ( auto it = estim_params_list . begin ( ) ; it ! = estim_params_list . end ( ) ; + + it )
2017-02-08 18:29:57 +01:00
{
if ( it ! = estim_params_list . begin ( ) )
output < < " , " ;
output < < " { " ;
switch ( it - > type )
{
case 1 :
2019-04-03 16:32:52 +02:00
output < < R " ( " var " : " ) " << it->name << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
case 2 :
2019-04-03 16:32:52 +02:00
output < < R " ( " param " : " ) " << it->name << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
break ;
case 3 :
2019-04-03 16:32:52 +02:00
output < < R " ( " var1 " : " ) " << it->name << R " ( " ,) "
< < R " ( " var2 " : " ) " << it->name2 << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
break ;
}
2019-04-03 16:32:52 +02:00
output < < R " (, " lower_bound " : ) " ;
2018-05-29 11:59:42 +02:00
it - > low_bound - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " (, " upper_bound " : ) " ;
2018-05-29 11:59:42 +02:00
it - > up_bound - > writeJsonOutput ( output , { } , { } ) ;
2017-02-08 18:29:57 +01:00
output < < " } " ;
}
output < < " ] "
< < " } " ;
}
2020-06-29 11:38:41 +02:00
DeterministicTrendsStatement : : DeterministicTrendsStatement ( trend_elements_t trend_elements_arg ,
const SymbolTable & symbol_table_arg ) :
trend_elements { move ( trend_elements_arg ) } ,
symbol_table { symbol_table_arg }
{
}
void
DeterministicTrendsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
output < < " options_.trend_coeff = {}; " < < endl ;
for ( const auto & trend_element : trend_elements )
{
SymbolType type = symbol_table . getType ( trend_element . first ) ;
if ( type = = SymbolType : : endogenous )
{
output < < " tmp1 = strmatch(' " < < trend_element . first < < " ',M_.endogenous_names,'exact'); " < < endl ;
output < < " options_.deterministic_trend_coeffs{tmp1} = ' " ;
trend_element . second - > writeOutput ( output ) ;
output < < " '; " < < endl ;
}
else
cerr < < " Warning : Non-variable symbol used in deterministic_trends: " < < trend_element . first < < endl ;
}
}
void
DeterministicTrendsStatement : : writeJsonOutput ( ostream & output ) const
{
output < < R " ({ " statementName " : " deterministic_trends " , ) "
< < R " ( " trends " : {) " ;
bool printed = false ;
for ( const auto & trend_element : trend_elements )
{
if ( symbol_table . getType ( trend_element . first ) = = SymbolType : : endogenous )
{
if ( printed )
output < < " , " ;
output < < R " ( " ) " << trend_element.first << R " ( " : " ) " ;
trend_element . second - > writeJsonOutput ( output , { } , { } ) ;
output < < R " ( " ) " << endl;
printed = true ;
}
else
cerr < < " Warning : Non-variable symbol used in deterministic_trends: " < < trend_element . first < < endl ;
}
output < < " } "
< < " } " ;
}
2018-06-04 12:31:07 +02:00
ObservationTrendsStatement : : ObservationTrendsStatement ( trend_elements_t trend_elements_arg ,
2008-02-03 11:28:36 +01:00
const SymbolTable & symbol_table_arg ) :
2018-10-04 17:18:27 +02:00
trend_elements { move ( trend_elements_arg ) } ,
symbol_table { symbol_table_arg }
2008-02-03 11:28:36 +01:00
{
}
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 ;
2019-12-20 16:59:30 +01:00
for ( const auto & trend_element : trend_elements )
2008-02-03 11:28:36 +01:00
{
2018-06-04 12:26:16 +02:00
SymbolType type = symbol_table . getType ( trend_element . first ) ;
2018-07-17 18:34:07 +02:00
if ( type = = SymbolType : : endogenous )
2008-02-03 11:28:36 +01:00
{
2018-06-04 12:26:16 +02:00
output < < " tmp1 = strmatch(' " < < trend_element . first < < " ',options_.varobs,'exact'); " < < endl ;
2008-02-03 11:28:36 +01:00
output < < " options_.trend_coeffs{tmp1} = ' " ;
2018-06-04 12:26:16 +02:00
trend_element . second - > writeOutput ( output ) ;
2008-02-03 11:28:36 +01:00
output < < " '; " < < endl ;
}
else
2018-06-04 12:26:16 +02:00
cerr < < " Warning : Non-variable symbol used in observation_trends: " < < trend_element . first < < endl ;
2008-02-03 11:28:36 +01:00
}
}
2017-02-08 18:29:57 +01:00
void
ObservationTrendsStatement : : writeJsonOutput ( ostream & output ) const
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " observation_trends " , ) "
< < R " ( " trends " : {) " ;
2017-02-08 18:29:57 +01:00
bool printed = false ;
2019-12-20 16:59:30 +01:00
for ( const auto & trend_element : trend_elements )
2017-02-08 18:29:57 +01:00
{
2018-07-17 18:34:07 +02:00
if ( symbol_table . getType ( trend_element . first ) = = SymbolType : : endogenous )
2017-02-08 18:29:57 +01:00
{
if ( printed )
output < < " , " ;
2019-04-03 16:32:52 +02:00
output < < R " ( " ) " << trend_element.first << R " ( " : " ) " ;
2018-06-04 12:26:16 +02:00
trend_element . second - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " ) " << endl;
2017-02-08 18:29:57 +01:00
printed = true ;
}
else
2018-06-04 12:26:16 +02:00
cerr < < " Warning : Non-variable symbol used in observation_trends: " < < trend_element . first < < endl ;
2017-02-08 18:29:57 +01:00
}
output < < " } "
< < " } " ;
}
2021-01-18 16:42:20 +01:00
FilterInitialStateStatement : : FilterInitialStateStatement ( filter_initial_state_elements_t filter_initial_state_elements_arg ,
const SymbolTable & symbol_table_arg ) :
filter_initial_state_elements { move ( filter_initial_state_elements_arg ) } ,
symbol_table { symbol_table_arg }
{
}
void
FilterInitialStateStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
output < < " M_.filter_initial_state = cell(M_.endo_nbr, 2); " < < endl ;
for ( const auto & [ key , val ] : filter_initial_state_elements )
{
auto [ symb_id , lag ] = key ;
SymbolType type = symbol_table . getType ( symb_id ) ;
if ( ( type = = SymbolType : : endogenous & & lag < 0 ) | | type = = SymbolType : : exogenous )
{
try
{
// This function call must remain the 1st statement in this block
symb_id = symbol_table . searchAuxiliaryVars ( symb_id , lag ) ;
}
catch ( SymbolTable : : SearchFailedException & e )
{
if ( type = = SymbolType : : endogenous )
{
cerr < < " filter_initial_state: internal error, please contact the developers " ;
exit ( EXIT_FAILURE ) ;
}
// We don't fail for exogenous, because they are not replaced by
// auxiliary variables in deterministic mode.
}
}
output < < " M_.filter_initial_state( "
< < symbol_table . getTypeSpecificID ( symb_id ) + 1
< < " ,:) = {' " < < symbol_table . getName ( symb_id ) < < " ', ' " ;
val - > writeOutput ( output ) ;
output < < " ;'}; " < < endl ;
}
}
void
FilterInitialStateStatement : : writeJsonOutput ( ostream & output ) const
{
output < < R " ({ " statementName " : " filter_initial_state " , ) "
< < R " ( " states " : [) " ;
for ( auto it = filter_initial_state_elements . begin ( ) ;
it ! = filter_initial_state_elements . end ( ) ; + + it )
{
if ( it ! = filter_initial_state_elements . begin ( ) )
output < < " , " ;
auto & [ key , val ] = * it ;
auto & [ symb_id , lag ] = key ;
output < < R " ({ " var " : " ) " << symbol_table.getName(symb_id)
< < R " ( " , " lag " : ) " << lag
< < R " (, " value " : " ) " ;
val - > writeJsonOutput ( output , { } , { } ) ;
output < < R " ( " } ) " ;
}
output < < " ] } " ;
}
2018-06-04 12:31:07 +02:00
OsrParamsStatement : : OsrParamsStatement ( SymbolList symbol_list_arg , const SymbolTable & symbol_table_arg ) :
2018-10-04 17:18:27 +02:00
symbol_list { move ( 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 ;
2019-12-23 16:22:23 +01:00
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : parameter } ) ;
2019-12-23 16:22:23 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: osr: " < < e . message < < endl ;
exit ( EXIT_FAILURE ) ;
}
2011-03-03 16:30:53 +01:00
}
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 ( ) ;
2019-12-20 16:59:30 +01:00
for ( auto & symbol : symbols )
2019-12-16 19:42:59 +01:00
output < < " M_.osr.param_indices( " < < + + i < < " ) = " < < symbol_table . getTypeSpecificID ( symbol ) + 1 < < " ; " < < endl ;
2008-02-03 11:28:36 +01:00
}
2017-02-08 18:29:57 +01:00
void
OsrParamsStatement : : writeJsonOutput ( ostream & output ) const
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " osr_params " ) " ;
2017-02-08 18:29:57 +01:00
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
OsrParamsBoundsStatement : : OsrParamsBoundsStatement ( vector < OsrParams > osr_params_list_arg ) :
2018-10-04 17:18:27 +02:00
osr_params_list { move ( osr_params_list_arg ) }
2016-05-20 15:35:09 +02:00
{
}
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 ;
2019-12-20 16:59:30 +01:00
for ( const auto & it : osr_params_list )
2016-05-10 18:01:00 +02:00
{
2018-06-04 12:26:16 +02:00
output < < " M_.osr.param_bounds(strcmp(M_.osr.param_names, ' " < < it . name < < " '), :) = [ " ;
it . low_bound - > writeOutput ( output ) ;
2016-05-10 18:01:00 +02:00
output < < " , " ;
2018-06-04 12:26:16 +02:00
it . up_bound - > writeOutput ( output ) ;
2016-05-10 18:01:00 +02:00
output < < " ]; " < < endl ;
}
}
2017-02-08 18:29:57 +01:00
void
OsrParamsBoundsStatement : : writeJsonOutput ( ostream & output ) const
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " osr_params_bounds " ) "
< < R " (, " bounds " : [) " ;
2019-12-16 19:42:59 +01:00
for ( auto it = osr_params_list . begin ( ) ; it ! = osr_params_list . end ( ) ; + + it )
2017-02-08 18:29:57 +01:00
{
if ( it ! = osr_params_list . begin ( ) )
output < < " , " ;
2019-04-03 16:32:52 +02:00
output < < R " ({ " parameter " : " ) " << it->name << R " ( " ,) "
< < R " ( " bounds " : [ " ) " ;
2018-05-29 11:59:42 +02:00
it - > low_bound - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " , " ) " ;
2018-05-29 11:59:42 +02:00
it - > up_bound - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " ] ) "
2017-02-08 18:29:57 +01:00
< < " } " ;
}
output < < " ] "
< < " } " ;
}
2019-12-20 10:29:12 +01:00
OsrStatement : : OsrStatement ( SymbolList symbol_list_arg ,
OptionsList options_list_arg ) :
symbol_list { move ( symbol_list_arg ) } ,
options_list { move ( options_list_arg ) }
{
}
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
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " order " ) ;
it ! = options_list . num_options . end ( ) )
2018-07-04 12:40:57 +02:00
mod_file_struct . order_option = max ( mod_file_struct . order_option , stoi ( it - > second ) ) ;
2008-11-04 12:00:54 +01:00
2009-10-20 18:55:31 +02:00
// Fill in mod_file_struct.partial_information
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " partial_information " ) ;
it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
2009-10-20 18:55:31 +02:00
mod_file_struct . partial_information = true ;
2009-12-09 12:50:58 +01:00
// Option k_order_solver (implicit when order >= 3)
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " k_order_solver " ) ;
( it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
2009-12-09 12:50:58 +01:00
| | mod_file_struct . order_option > = 3 )
mod_file_struct . k_order_solver = true ;
2019-12-19 14:48:55 +01:00
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous } ) ;
2019-12-19 14:48:55 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: osr: " < < e . message < < endl ;
exit ( EXIT_FAILURE ) ;
}
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)
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " order " ) ,
it1 = options_list . num_options . find ( " k_order_solver " ) ;
( it1 ! = options_list . num_options . end ( ) & & it1 - > second = = " true " )
2018-07-04 12:40:57 +02:00
| | ( it ! = options_list . num_options . end ( ) & & stoi ( it - > second ) > = 3 ) )
2019-03-19 14:05:41 +01:00
output < < " options_.k_order_solver = true; " < < endl ;
2015-02-10 03:39:18 +01:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " osr " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
OptimWeightsStatement : : OptimWeightsStatement ( var_weights_t var_weights_arg ,
covar_weights_t covar_weights_arg ,
2008-02-03 11:28:36 +01:00
const SymbolTable & symbol_table_arg ) :
2018-10-04 17:18:27 +02:00
var_weights { move ( var_weights_arg ) } ,
covar_weights { move ( covar_weights_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
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
2019-12-16 19:42:59 +01:00
for ( const auto & [ name , value ] : var_weights )
2008-02-03 11:28:36 +01:00
{
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
}
2019-12-16 19:42:59 +01:00
for ( const auto & [ names , value ] : covar_weights )
2008-02-03 11:28:36 +01:00
{
2019-12-16 19:42:59 +01:00
int id1 = symbol_table . getTypeSpecificID ( names . first ) + 1 ;
int id2 = symbol_table . getTypeSpecificID ( names . second ) + 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " optim_weights " , ) "
< < R " ( " weights " : [) " ;
2019-12-16 19:42:59 +01:00
for ( auto it = var_weights . begin ( ) ; it ! = var_weights . end ( ) ; + + it )
2017-02-08 18:29:57 +01:00
{
if ( it ! = var_weights . begin ( ) )
output < < " , " ;
2019-04-03 16:32:52 +02:00
output < < R " ({ " name " : " ) " << it->first << R " ( " ) "
< < R " (, " value " : " ) " ;
2018-05-29 11:59:42 +02:00
it - > second - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " } ) " ;
2017-02-08 18:29:57 +01:00
}
2019-12-16 19:42:59 +01:00
for ( auto it = covar_weights . begin ( ) ; it ! = covar_weights . end ( ) ; + + it )
2017-02-08 18:29:57 +01:00
{
if ( it ! = covar_weights . begin ( ) | | ! var_weights . empty ( ) )
output < < " , " ;
2019-04-03 16:32:52 +02:00
output < < R " ({ " name1 " : " ) " << it->first.first << R " ( " ) "
< < R " (, " name2 " : " ) " << it->first.second << R " ( " ) "
< < R " (, " value " : " ) " ;
2018-05-29 11:59:42 +02:00
it - > second - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " } ) " ;
2017-02-08 18:29:57 +01:00
}
output < < " ] "
< < " } " ;
}
2018-06-04 12:31:07 +02:00
DynaSaveStatement : : DynaSaveStatement ( SymbolList symbol_list_arg ,
string filename_arg ) :
2018-10-04 17:18:27 +02:00
symbol_list { move ( symbol_list_arg ) } ,
filename { move ( filename_arg ) }
2008-02-03 11:28:36 +01:00
{
}
2019-12-19 14:48:55 +01:00
void
DynaSaveStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous , SymbolType : : exogenous } ) ;
2019-12-19 14:48:55 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: dynasave: " < < e . message < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " dynasave " , ) "
< < R " ( " filename " : " ) " << filename << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
DynaTypeStatement : : DynaTypeStatement ( SymbolList symbol_list_arg ,
string filename_arg ) :
symbol_list ( move ( symbol_list_arg ) ) ,
filename ( move ( filename_arg ) )
2008-02-03 11:28:36 +01:00
{
}
2019-12-19 14:48:55 +01:00
void
DynaTypeStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous , SymbolType : : exogenous } ) ;
2019-12-19 14:48:55 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: dynatype: " < < e . message < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " dynatype " , ) "
< < R " ( " filename " : " ) " << filename << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
ModelComparisonStatement : : ModelComparisonStatement ( filename_list_t filename_list_arg ,
OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
filename_list { move ( filename_list_arg ) } ,
options_list { move ( options_list_arg ) }
2008-02-03 11:28:36 +01:00
{
}
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
2019-12-20 16:59:30 +01:00
for ( const auto & it : filename_list )
2008-02-03 11:28:36 +01:00
{
2018-06-04 12:26:16 +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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " model_comparison " ) " ;
2017-02-08 18:29:57 +01:00
if ( ! filename_list . empty ( ) )
2019-04-03 16:32:52 +02:00
output < < R " (, " filename_list " : {) " ;
2017-02-08 18:29:57 +01:00
2019-12-16 19:42:59 +01:00
for ( auto it = filename_list . begin ( ) ; it ! = filename_list . end ( ) ; + + it )
2017-02-08 18:29:57 +01:00
{
if ( it ! = filename_list . begin ( ) )
output < < " , " ;
2019-04-03 16:32:52 +02:00
output < < R " ( " name " : " ) " << it->first << R " ( " ) "
< < R " ( " prior " : " ) " << it->second << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
}
if ( ! filename_list . empty ( ) )
output < < " } " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-10-09 18:27:19 +02:00
PlannerObjectiveStatement : : PlannerObjectiveStatement ( const StaticModel & model_tree_arg ) :
2019-12-20 16:59:30 +01:00
model_tree { model_tree_arg }
2008-02-03 11:28:36 +01:00
{
}
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
{
2018-07-31 12:42:08 +02:00
assert ( model_tree . equation_number ( ) = = 1 ) ;
if ( model_tree . exoPresentInEqs ( ) )
2016-08-12 11:50:57 +02:00
{
2021-11-19 17:32:45 +01:00
cerr < < " ERROR: You cannot include exogenous variables (or variables of undeclared type) in the planner objective. Please "
2016-08-12 11:50:57 +02:00
< < " 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
}
2018-10-09 18:27:19 +02:00
const StaticModel &
PlannerObjectiveStatement : : getPlannerObjective ( ) const
2011-03-21 18:40:57 +01:00
{
return model_tree ;
}
2008-02-03 11:28:36 +01:00
void
2021-06-04 16:20:29 +02:00
PlannerObjectiveStatement : : computingPass ( const ModFileStructure & mod_file_struct )
2008-02-03 11:28:36 +01:00
{
2021-06-04 16:20:29 +02:00
model_tree . computingPass ( max ( 3 , mod_file_struct . order_option ) , 0 , { } , false , 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
{
2021-04-22 14:52:29 +02:00
output < < " M_.NNZDerivatives_objective = [ " ;
for ( int i = 1 ; i < static_cast < int > ( model_tree . getNNZDerivatives ( ) . size ( ) ) ; i + + )
output < < ( i > model_tree . getComputedDerivsOrder ( ) ? - 1 : model_tree . getNNZDerivatives ( ) [ i ] ) < < " ; " ;
2021-06-11 12:37:31 +02:00
output < < " ]; " < < endl ;
output < < " M_.objective_tmp_nbr = [ " ;
for ( const auto & temporary_terms_derivative : model_tree . getTemporaryTermsDerivatives ( ) )
output < < temporary_terms_derivative . size ( ) < < " ; " ;
output < < " ]; " < < endl ;
2018-10-26 11:44:26 +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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " planner_objective " ) "
2017-02-27 15:40:34 +01:00
< < " , " ;
if ( computing_pass_called )
2018-07-31 12:42:08 +02:00
model_tree . writeJsonComputingPassOutput ( output , false ) ;
2017-02-27 15:40:34 +01:00
else
2018-07-31 12:42:08 +02:00
model_tree . writeJsonOutput ( output ) ;
2017-02-27 15:40:34 +01:00
output < < " } " ;
2017-02-08 18:29:57 +01:00
}
2018-06-04 12:31:07 +02:00
BVARDensityStatement : : BVARDensityStatement ( int maxnlags_arg , OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
maxnlags { maxnlags_arg } ,
options_list { move ( options_list_arg ) }
2008-02-03 11:28:36 +01:00
{
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " bvar_density " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
BVARForecastStatement : : BVARForecastStatement ( int nlags_arg , OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
nlags { nlags_arg } ,
options_list { move ( options_list_arg ) }
2008-02-03 11:28:36 +01:00
{
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " bvar_forecast " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
SBVARStatement : : SBVARStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2009-07-26 19:07:07 +02:00
{
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " sbvar " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
MSSBVAREstimationStatement : : MSSBVAREstimationStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2009-07-26 19:07:07 +02:00
{
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " ms_sbvar_estimation " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
MSSBVARSimulationStatement : : MSSBVARSimulationStatement ( OptionsList options_list_arg ) :
options_list ( move ( options_list_arg ) )
2011-05-11 19:02:39 +02:00
{
}
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
2019-12-16 19:42:59 +01:00
if ( ( options_list . num_options . find ( " ms.mh_replic " ) ! = options_list . num_options . end ( )
| | options_list . num_options . find ( " ms.thinning_factor " ) ! = options_list . num_options . end ( ) )
& & ( options_list . num_options . find ( " ms.drop " ) = = options_list . num_options . end ( ) ) )
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " ms_sbvar_simulation " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
MSSBVARComputeMDDStatement : : MSSBVARComputeMDDStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2011-05-11 19:02:39 +02:00
{
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " ms_sbvar_compute_mdd " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
MSSBVARComputeProbabilitiesStatement : : MSSBVARComputeProbabilitiesStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2011-05-11 19:02:39 +02:00
{
}
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
2019-12-16 19:42:59 +01:00
if ( options_list . num_options . find ( " ms.real_time_smoothed_probabilities " ) ! = options_list . num_options . end ( )
& & 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " ms_sbvar_compute_probabilities " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
MSSBVARIrfStatement : : MSSBVARIrfStatement ( SymbolList symbol_list_arg ,
OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
symbol_list { move ( symbol_list_arg ) } ,
options_list { move ( options_list_arg ) }
2011-05-11 19:02:39 +02:00
{
}
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
2019-12-16 19:42:59 +01:00
bool regime_present = options_list . num_options . find ( " ms.regime " ) ! = options_list . num_options . end ( ) ;
bool regimes_present = options_list . num_options . find ( " ms.regimes " ) ! = options_list . num_options . end ( ) ;
bool filtered_probabilities_present = options_list . num_options . find ( " ms.filtered_probabilities " ) ! = options_list . num_options . end ( ) ;
2011-10-10 18:33:16 +02:00
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 ) ;
}
2019-12-19 14:48:55 +01:00
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous } ) ;
2019-12-19 14:48:55 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: ms_irf: " < < e . message < < 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " ms_sbvar_irf " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
MSSBVARForecastStatement : : MSSBVARForecastStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2011-05-11 19:02:39 +02:00
{
}
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
2019-12-16 19:42:59 +01:00
if ( options_list . num_options . find ( " ms.regimes " ) ! = options_list . num_options . end ( )
& & 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " ms_sbvar_forecast " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
MSSBVARVarianceDecompositionStatement : : MSSBVARVarianceDecompositionStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2011-05-11 19:02:39 +02:00
{
}
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
2019-12-16 19:42:59 +01:00
bool regime_present = options_list . num_options . find ( " ms.regime " ) ! = options_list . num_options . end ( ) ;
bool regimes_present = options_list . num_options . find ( " ms.regimes " ) ! = options_list . num_options . end ( ) ;
bool filtered_probabilities_present = options_list . num_options . find ( " ms.filtered_probabilities " ) ! = options_list . num_options . end ( ) ;
2011-10-19 17:25:46 +02:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " ms_sbvar_variance_decomposition " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-10-04 17:18:27 +02:00
IdentificationStatement : : IdentificationStatement ( OptionsList options_list_arg )
: options_list { move ( options_list_arg ) }
2009-04-20 15:58:15 +02:00
{
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " max_dim_cova_group " ) ;
it ! = options_list . num_options . end ( ) & & stoi ( it - > second ) = = 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 ;
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " order " ) ;
it ! = options_list . num_options . end ( ) )
2019-07-05 17:44:10 +02:00
{
int order = stoi ( it - > second ) ;
2019-08-22 17:00:36 +02:00
if ( order < 1 | | order > 3 )
2019-07-05 17:44:10 +02:00
{
2019-08-22 17:00:36 +02:00
cerr < < " ERROR: the order option of identification command must be between 1 and 3 " < < endl ;
2019-07-05 17:44:10 +02:00
exit ( EXIT_FAILURE ) ;
}
mod_file_struct . identification_order = max ( mod_file_struct . identification_order , order ) ;
}
else
2020-01-20 17:23:51 +01:00
// The default value for order is 1 (which triggers 2nd order dynamic derivatives, see preprocessor#40)
2019-07-05 17:44:10 +02:00
mod_file_struct . identification_order = max ( mod_file_struct . identification_order , 1 ) ;
2009-04-20 15:58:15 +02:00
}
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 ) */
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " nodisplay " ) ;
it ! = options_list . num_options . end ( ) )
2012-06-15 15:35:00 +02:00
output < < " options_.nodisplay = " < < it - > second < < " ; " < < endl ;
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " nograph " ) ;
it ! = options_list . num_options . end ( ) )
2012-06-15 15:35:00 +02:00
output < < " options_.nograph = " < < it - > second < < " ; " < < endl ;
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . string_options . find ( " graph_format " ) ;
it ! = options_list . string_options . end ( ) )
output < < " options_.graph_format = ' " < < it - > 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " identification " ) " ;
2017-02-08 18:29:57 +01:00
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 ) :
2018-10-04 17:18:27 +02:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " write_latex_dynamic_model " }) " ;
2017-02-08 18:29:57 +01:00
}
2017-08-24 15:35:10 +02:00
WriteLatexStaticModelStatement : : WriteLatexStaticModelStatement ( const StaticModel & static_model_arg , bool write_equation_tags_arg ) :
static_model ( static_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
WriteLatexStaticModelStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2009-04-30 15:14:33 +02:00
{
2017-08-24 15:35:10 +02:00
static_model . writeLatexFile ( basename , write_equation_tags ) ;
2009-04-30 15:14:33 +02:00
}
2009-07-23 10:31:48 +02:00
2017-02-08 18:29:57 +01:00
void
WriteLatexStaticModelStatement : : writeJsonOutput ( ostream & output ) const
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " write_latex_static_model " }) " ;
2017-02-08 18:29:57 +01:00
}
2017-08-24 15:35:10 +02:00
WriteLatexOriginalModelStatement : : WriteLatexOriginalModelStatement ( const DynamicModel & original_model_arg , bool write_equation_tags_arg ) :
2018-10-04 17:18:27 +02:00
original_model { original_model_arg } ,
write_equation_tags { write_equation_tags_arg }
2015-02-16 08:31:30 +01:00
{
}
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
{
2017-08-24 15:35:10 +02:00
original_model . writeLatexOriginalFile ( basename , write_equation_tags ) ;
2015-02-16 08:31:30 +01:00
}
2017-02-08 18:29:57 +01:00
void
WriteLatexOriginalModelStatement : : writeJsonOutput ( ostream & output ) const
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " write_latex_original_model " }) " ;
2017-02-08 18:29:57 +01:00
}
2017-08-30 11:32:01 +02:00
WriteLatexSteadyStateModelStatement : : WriteLatexSteadyStateModelStatement ( const SteadyStateModel & steady_state_model_arg ) :
2018-10-04 17:18:27 +02:00
steady_state_model { steady_state_model_arg }
2017-08-30 11:32:01 +02:00
{
}
2017-08-30 15:46:17 +02:00
void
WriteLatexSteadyStateModelStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
mod_file_struct . write_latex_steady_state_model_present = true ;
}
2017-08-30 11:32:01 +02:00
void
WriteLatexSteadyStateModelStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
steady_state_model . writeLatexSteadyStateFile ( basename ) ;
}
void
WriteLatexSteadyStateModelStatement : : writeJsonOutput ( ostream & output ) const
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " write_latex_steady_state_model " }) " ;
2017-08-30 11:32:01 +02:00
}
2018-06-04 12:31:07 +02:00
ShockDecompositionStatement : : ShockDecompositionStatement ( SymbolList symbol_list_arg ,
OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
symbol_list { move ( symbol_list_arg ) } ,
options_list { move ( options_list_arg ) }
2009-07-23 10:31:48 +02:00
{
}
2019-12-20 11:10:32 +01:00
void
ShockDecompositionStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
if ( auto it = options_list . num_options . find ( " shock_decomp.with_epilogue " ) ;
it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
mod_file_struct . with_epilogue_option = true ;
2019-12-19 14:48:55 +01:00
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous } ) ;
2019-12-19 14:48:55 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: shock_decomposition: " < < e . message < < endl ;
exit ( EXIT_FAILURE ) ;
}
2019-12-20 11:10:32 +01:00
}
2009-07-23 10:31:48 +02:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " shock_decomposition " ) " ;
2017-02-08 18:29:57 +01:00
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
}
2018-06-04 12:31:07 +02:00
RealtimeShockDecompositionStatement : : RealtimeShockDecompositionStatement ( SymbolList symbol_list_arg ,
OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
symbol_list { move ( symbol_list_arg ) } ,
options_list { move ( options_list_arg ) }
2017-03-21 14:58:15 +01:00
{
}
2019-12-20 11:10:32 +01:00
void
RealtimeShockDecompositionStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
if ( auto it = options_list . num_options . find ( " shock_decomp.with_epilogue " ) ;
it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
mod_file_struct . with_epilogue_option = true ;
2019-12-19 14:48:55 +01:00
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous } ) ;
2019-12-19 14:48:55 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: realtime_shock_decomposition: " < < e . message < < endl ;
exit ( EXIT_FAILURE ) ;
}
2019-12-20 11:10:32 +01:00
}
2017-03-21 14:58:15 +01:00
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 ;
}
2019-04-12 14:26:27 +02:00
void
RealtimeShockDecompositionStatement : : writeJsonOutput ( ostream & output ) const
{
output < < R " ({ " statementName " : " realtime_shock_decomposition " ) " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
PlotShockDecompositionStatement : : PlotShockDecompositionStatement ( SymbolList symbol_list_arg ,
OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
symbol_list { move ( symbol_list_arg ) } ,
options_list { move ( options_list_arg ) }
2017-03-22 11:30:35 +01:00
{
}
2019-12-23 16:22:23 +01:00
void
PlotShockDecompositionStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous , SymbolType : : epilogue } ) ;
2019-12-23 16:22:23 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: plot_shock_decomposition: " < < e . message < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
2017-03-22 11:30:35 +01:00
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 ) ;
2019-12-14 08:42:09 +01:00
output < < " oo_ = plot_shock_decomposition(M_, oo_, options_, var_list_); " < < endl ;
2017-03-22 11:30:35 +01:00
}
2017-03-21 14:58:15 +01:00
2019-04-12 14:26:27 +02:00
void
PlotShockDecompositionStatement : : writeJsonOutput ( ostream & output ) const
{
output < < R " ({ " statementName " : " plot_shock_decomposition " ) " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
InitialConditionDecompositionStatement : : InitialConditionDecompositionStatement ( SymbolList symbol_list_arg ,
OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
symbol_list { move ( symbol_list_arg ) } ,
options_list { move ( options_list_arg ) }
2017-03-31 12:50:17 +02:00
{
}
2019-12-20 11:10:32 +01:00
void
InitialConditionDecompositionStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
if ( auto it = options_list . num_options . find ( " initial_condition_decomp.with_epilogue " ) ;
it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
mod_file_struct . with_epilogue_option = true ;
2019-12-19 14:48:55 +01:00
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous } ) ;
2019-12-19 14:48:55 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: initial_condition_decomposition: " < < e . message < < endl ;
exit ( EXIT_FAILURE ) ;
}
2019-12-20 11:10:32 +01:00
}
2017-03-31 12:50:17 +02:00
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 ) ;
2017-11-23 19:29:25 +01:00
output < < " oo_ = initial_condition_decomposition(M_, oo_, options_, var_list_, bayestopt_, estim_params_); " < < endl ;
2017-03-31 12:50:17 +02:00
}
2017-03-21 14:58:15 +01:00
2019-04-12 14:26:27 +02:00
void
InitialConditionDecompositionStatement : : writeJsonOutput ( ostream & output ) const
{
output < < R " ({ " statementName " : " initial_condition_decomposition " ) " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2019-12-14 08:42:09 +01:00
SqueezeShockDecompositionStatement : : SqueezeShockDecompositionStatement ( SymbolList symbol_list_arg )
: symbol_list { move ( symbol_list_arg ) }
{
}
2019-12-19 14:48:55 +01:00
void
SqueezeShockDecompositionStatement : : checkPass ( ModFileStructure & mod_file_struct ,
WarningConsolidation & warnings )
{
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous } ) ;
2019-12-19 14:48:55 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: squeeze_shock_decomposition: " < < e . message < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
2019-12-14 08:42:09 +01:00
void
SqueezeShockDecompositionStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
if ( symbol_list . empty ( ) )
output < < " oo_ = squeeze_shock_decomposition(M_, oo_, options_); " < < endl ;
else
{
symbol_list . writeOutput ( " var_list_ " , output ) ;
2019-12-20 10:34:37 +01:00
output < < " oo_ = squeeze_shock_decomposition(M_, oo_, options_, var_list_); " < < endl ;
2019-12-14 08:42:09 +01:00
}
}
void
SqueezeShockDecompositionStatement : : writeJsonOutput ( ostream & output ) const
{
output < < R " ({ " statementName " : " squeeze_shock_decomposition " ) " ;
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
ConditionalForecastStatement : : ConditionalForecastStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2009-10-16 19:23:57 +02:00
{
}
2019-04-03 14:26:02 +02:00
void
ConditionalForecastStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
if ( options_list . string_options . find ( " parameter_set " ) = = options_list . string_options . end ( ) )
{
cerr < < " ERROR: You must pass the `parameter_set` option to conditional_forecast " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
2009-10-16 19:23:57 +02:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " conditional_forecast " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
PlotConditionalForecastStatement : : PlotConditionalForecastStatement ( int periods_arg , SymbolList symbol_list_arg ) :
2018-10-04 17:18:27 +02:00
periods { periods_arg } ,
symbol_list { move ( symbol_list_arg ) }
2009-10-16 19:23:57 +02:00
{
}
2019-12-19 14:48:55 +01:00
void
PlotConditionalForecastStatement : : checkPass ( ModFileStructure & mod_file_struct ,
WarningConsolidation & warnings )
{
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous } ) ;
2019-12-19 14:48:55 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: plot_conditional_forecast: " < < e . message < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
2009-10-16 19:23:57 +02:00
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 )
2019-11-29 12:14:43 +01:00
output < < " plot_icforecast(var_list_,[],options_,oo_); " < < endl ;
2009-10-22 16:42:12 +02:00
else
2019-11-29 12:14:43 +01:00
output < < " plot_icforecast(var_list_, " < < periods < < " ,options_,oo_); " < < 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " plot_conditional_forecast " , ) "
< < R " ( " periods " : ) " < < periods ;
2017-02-08 18:29:57 +01:00
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
SvarIdentificationStatement : : SvarIdentificationStatement ( svar_identification_restrictions_t restrictions_arg ,
2018-10-04 17:18:27 +02:00
bool upper_cholesky_present_arg ,
bool lower_cholesky_present_arg ,
bool constants_exclusion_present_arg ,
2009-12-04 22:32:19 +01:00
const SymbolTable & symbol_table_arg ) :
2018-10-04 17:18:27 +02:00
restrictions { move ( restrictions_arg ) } ,
upper_cholesky_present { upper_cholesky_present_arg } ,
lower_cholesky_present { lower_cholesky_present_arg } ,
constants_exclusion_present { constants_exclusion_present_arg } ,
symbol_table { symbol_table_arg }
2009-12-04 22:32:19 +01:00
{
}
int
SvarIdentificationStatement : : getMaxLag ( ) const
{
int max_lag = 0 ;
2019-12-20 16:59:30 +01:00
for ( const auto & restriction : restrictions )
2018-06-04 12:26:16 +02:00
if ( restriction . lag > max_lag )
max_lag = restriction . 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 ) ;
}
2019-12-16 19:42:59 +01:00
output < < " options_.ms.Qi = cell( " < < n < < " ,1); " < < endl
< < " options_.ms.Ri = cell( " < < n < < " ,1); " < < endl ;
2009-12-04 22:32:19 +01:00
2019-12-16 19:42:59 +01:00
for ( auto & it : restrictions )
2009-12-04 22:32:19 +01:00
{
2019-12-16 19:42:59 +01:00
assert ( it . lag > = 0 ) ;
if ( it . lag = = 0 )
output < < " options_.ms.Qi{ " < < it . equation < < " }( " < < it . restriction_nbr < < " , " < < it . variable + 1 < < " ) = " ;
2017-06-01 19:58:32 +02:00
else
{
2019-12-16 19:42:59 +01:00
int col = ( it . lag - 1 ) * n + it . variable + 1 ;
2017-06-01 19:58:32 +02:00
if ( col > k )
2012-01-04 12:11:35 +01:00
{
2019-12-16 19:42:59 +01:00
cerr < < " ERROR: lag = " < < it . lag < < " , num endog vars = " < < n < < " current endog var index = " < < it . variable < < " . Index "
2019-08-27 14:20:00 +02:00
< < " out of bounds. If the above does not represent a logical error, please report this to the Dynare Team. " < < endl ;
2012-01-04 12:11:35 +01:00
exit ( EXIT_FAILURE ) ;
}
2019-12-16 19:42:59 +01:00
output < < " options_.ms.Ri{ " < < it . equation < < " }( " < < it . restriction_nbr < < " , " < < col < < " ) = " ;
2017-06-01 19:58:32 +02:00
}
2019-12-16 19:42:59 +01:00
it . value - > writeOutput ( output ) ;
2012-01-03 18:09:14 +01:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " svar_identification " ) " ;
2017-02-08 18:29:57 +01:00
if ( upper_cholesky_present )
2019-04-03 16:32:52 +02:00
output < < R " (, " upper_cholesky " : 1) " ;
2017-02-08 18:29:57 +01:00
if ( lower_cholesky_present )
2019-04-03 16:32:52 +02:00
output < < R " (, " lower_cholesky " : 1) " ;
2017-02-08 18:29:57 +01:00
if ( constants_exclusion_present )
2019-04-03 16:32:52 +02:00
output < < R " (, " constants_exclusion " : 1) " ;
2017-02-08 18:29:57 +01:00
if ( ! upper_cholesky_present & & ! lower_cholesky_present )
{
2019-04-03 16:32:52 +02:00
output < < R " (, " nlags " : ) " < < getMaxLag ( )
< < R " (, " restrictions " : [) " ;
2017-02-08 18:29:57 +01:00
2019-12-16 19:42:59 +01:00
for ( auto it = restrictions . begin ( ) ; it ! = restrictions . end ( ) ; + + it )
2017-02-08 18:29:57 +01:00
{
if ( it ! = restrictions . begin ( ) )
output < < " , " ;
output < < " { "
2019-04-03 16:32:52 +02:00
< < R " ( " equation_number " : ) " < < it - > equation < < " , "
< < R " ( " restriction_number " : ) " < < it - > restriction_nbr < < " , "
< < R " ( " variable " : " ) " << symbol_table.getName(it->variable) << R " ( " , ) "
< < R " ( " expression " : " ) " ;
2017-02-08 18:29:57 +01:00
it - > value - > writeOutput ( output ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " } ) " ;
2017-02-08 18:29:57 +01:00
}
output < < " ] " ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
MarkovSwitchingStatement : : MarkovSwitchingStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2009-12-08 17:46:13 +01:00
{
2019-12-16 19:42:59 +01:00
if ( auto it_num = options_list . num_options . find ( " ms.restrictions " ) ;
it_num ! = options_list . num_options . end ( ) )
2011-12-19 17:32:02 +01:00
{
using namespace boost ;
2019-12-16 19:42:59 +01:00
auto it_num_regimes = options_list . num_options . find ( " ms.number_of_regimes " ) ;
2019-12-20 16:59:30 +01:00
assert ( it_num_regimes ! = options_list . num_options . end ( ) ) ;
2018-07-04 15:34:13 +02:00
auto num_regimes = stoi ( it_num_regimes - > second ) ;
2011-12-19 17:32:02 +01:00
vector < string > tokenizedRestrictions ;
split ( tokenizedRestrictions , it_num - > second , is_any_of ( " [ " ) , token_compress_on ) ;
2019-12-20 16:59:30 +01:00
for ( auto & tokenizedRestriction : tokenizedRestrictions )
2018-06-04 12:26:16 +02:00
if ( tokenizedRestriction . size ( ) > 0 )
2011-12-19 17:32:02 +01:00
{
vector < string > restriction ;
2018-06-04 12:26:16 +02:00
split ( restriction , tokenizedRestriction , is_any_of ( " ], " ) ) ;
2019-12-16 19:42:59 +01:00
for ( auto it1 = restriction . begin ( ) ; it1 ! = restriction . end ( ) ; )
2011-12-19 17:32:02 +01:00
if ( it1 - > empty ( ) )
restriction . erase ( it1 ) ;
else
2019-12-16 19:42:59 +01:00
+ + it1 ;
2011-12-19 17:32:02 +01:00
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
{
2018-07-04 15:34:13 +02:00
auto from_regime = stoi ( restriction [ 0 ] ) ;
auto to_regime = stoi ( restriction [ 1 ] ) ;
2011-12-19 17:32:02 +01:00
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 ) ;
}
2018-06-04 16:36:46 +02:00
if ( restriction_map . find ( { from_regime , to_regime } ) ! =
2011-12-19 17:32:02 +01:00
restriction_map . end ( ) )
{
cerr < < " ERROR: two restrictions were given for: " < < from_regime < < " , "
< < to_regime < < endl ;
exit ( EXIT_FAILURE ) ;
}
2018-07-04 15:34:13 +02:00
auto transition_probability = stod ( restriction [ 2 ] ) ;
2011-12-19 17:32:02 +01:00
if ( transition_probability > 1.0 )
{
cerr < < " ERROR: the transition probability, " < < transition_probability
< < " must be less than 1 " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2018-06-04 16:36:46 +02:00
restriction_map [ { from_regime , to_regime } ] = transition_probability ;
2011-12-19 17:32:02 +01:00
}
2018-07-04 15:34:13 +02:00
catch ( const invalid_argument & )
2011-12-19 17:32:02 +01:00
{
cerr < < " ERROR: The first two arguments for a restriction must be integers "
< < " specifying the regime and the last must be a double specifying the "
2018-06-04 12:26:16 +02:00
< < " transition probability. You wrote [ " < < tokenizedRestriction < < endl ;
2011-12-19 17:32:02 +01:00
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
{
2018-06-04 15:03:26 +02:00
auto itChain = options_list . num_options . find ( " ms.chain " ) ;
2012-01-03 16:51:52 +01:00
assert ( itChain ! = options_list . num_options . end ( ) ) ;
2018-07-04 12:40:57 +02:00
int chainNumber = stoi ( itChain - > second ) ;
2012-01-03 16:51:52 +01:00
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 ) ;
}
2019-12-16 19:42:59 +01:00
if ( auto it_num = options_list . num_options . find ( " ms.restrictions " ) ;
it_num ! = options_list . num_options . end ( ) )
2011-12-19 17:32:02 +01:00
{
using namespace boost ;
2019-12-16 19:42:59 +01:00
auto 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 ( ) ) ;
2018-07-04 15:34:13 +02:00
auto num_regimes = stoi ( 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 + + )
2018-06-04 16:36:46 +02:00
if ( restriction_map . find ( { row + 1 , col + 1 } ) ! = restriction_map . end ( ) )
2011-12-19 17:32:02 +01:00
{
2018-06-04 16:36:46 +02:00
row_trans_prob_sum [ row ] + = restriction_map [ { row + 1 , col + 1 } ] ;
col_trans_prob_sum [ col ] + = restriction_map [ { row + 1 , col + 1 } ] ;
2011-12-19 17:32:02 +01:00
}
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 ( ) ) ;
2018-07-04 14:52:37 +02:00
if ( stod ( itDuration - > second ) | | 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 ( ) ) ;
2018-07-04 12:40:57 +02:00
for ( int i = 0 ; i < stoi ( itNOR - > second ) ; 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
2017-02-08 18:29:57 +01:00
void
MarkovSwitchingStatement : : writeJsonOutput ( ostream & output ) const
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " markov_switching " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! restriction_map . empty ( ) )
output < < " , { " ;
2019-12-16 19:42:59 +01:00
for ( auto it = restriction_map . begin ( ) ; it ! = restriction_map . end ( ) ; + + it )
2017-02-08 18:29:57 +01:00
{
if ( it ! = restriction_map . begin ( ) )
output < < " , " ;
2019-04-03 16:32:52 +02:00
output < < R " ({ " current_period_regime " : ) " < < it - > first . first
< < R " (, " next_period_regime " : ) " < < it - > first . second
< < R " (, " transition_probability " : ) " < < it - > second
2017-02-08 18:29:57 +01:00
< < " } " ;
}
if ( ! restriction_map . empty ( ) )
output < < " } " ;
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
SvarStatement : : SvarStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2009-12-09 01:38:53 +01:00
{
}
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
{
2019-12-16 19:42:59 +01:00
auto 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
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
{
2019-12-16 19:42:59 +01:00
auto it = options_list . num_options . find ( " ms.chain " ) ;
assert ( it ! = options_list . num_options . end ( ) ) ;
output < < " options_.ms.ms_chain( " < < it - > second < < " ) " ;
2009-12-09 01:38:53 +01:00
2019-12-16 19:42:59 +01:00
if ( auto it0 = options_list . string_options . find ( " ms.coefficients " ) ;
it0 ! = options_list . string_options . end ( ) )
2009-12-09 01:38:53 +01:00
output < < " . " < < it0 - > second ;
2019-12-16 19:42:59 +01:00
else if ( auto it1 = options_list . string_options . find ( " ms.variances " ) ;
it1 ! = options_list . string_options . end ( ) )
2009-12-09 01:38:53 +01:00
output < < " . " < < it1 - > second ;
else
2019-12-16 19:42:59 +01:00
output < < " . " < < options_list . string_options . find ( " ms.constants " ) - > second ;
2009-12-09 01:38:53 +01:00
2009-12-10 23:49:50 +01:00
output < < " .equations = " ;
2019-12-16 19:42:59 +01:00
if ( auto itv = options_list . vector_int_options . find ( " ms.equations " ) ;
itv ! = options_list . vector_int_options . end ( ) )
2009-12-10 23:49:50 +01:00
{
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 < < " [ " ;
2018-06-04 12:26:16 +02:00
for ( int viit : itv - > second )
output < < viit < < " ; " ;
2009-12-10 23:49:50 +01:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " svar " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2015-08-24 11:21:06 +02:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " svar_global_identification " }) " ;
2017-02-08 18:29:57 +01:00
}
2018-06-04 12:31:07 +02:00
SetTimeStatement : : SetTimeStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2011-11-29 17:14:26 +01:00
{
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " set_time " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
EstimationDataStatement : : EstimationDataStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2011-12-06 15:42:57 +01:00
{
}
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 ;
2019-12-16 19:42:59 +01:00
if ( auto it = options_list . num_options . find ( " nobs " ) ;
it ! = options_list . num_options . end ( ) )
2018-07-04 12:40:57 +02:00
if ( stoi ( it - > second ) < = 0 )
2011-12-06 15:42:57 +01:00
{
cerr < < " ERROR: The nobs option of the data statement only accepts positive integers. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2019-12-16 19:42:59 +01: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 ) ;
}
2019-12-16 19:42:59 +01: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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " estimation_data " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
SubsamplesStatement : : SubsamplesStatement ( string name1_arg ,
string name2_arg ,
2018-07-31 10:49:23 +02:00
subsample_declaration_map_t subsample_declaration_map_arg ,
const SymbolTable & symbol_table_arg ) :
2018-10-04 17:18:27 +02:00
name1 { move ( name1_arg ) } ,
name2 { move ( name2_arg ) } ,
2019-01-15 11:08:47 +01:00
subsample_declaration_map { move ( subsample_declaration_map_arg ) } ,
2018-07-31 10:49:23 +02:00
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 ;
2018-06-04 15:03:26 +02:00
for ( auto it = subsample_declaration_map . begin ( ) ;
2019-12-16 19:42:59 +01:00
it ! = subsample_declaration_map . end ( ) ; + + it , map_indx + + )
2012-03-28 16:19:10 +02:00
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 ;
2018-07-17 18:34:07 +02:00
if ( symb_type = = SymbolType : : parameter )
2012-04-02 17:54:05 +02:00
lhs_field = " parameter " ;
2018-07-17 18:34:07 +02:00
else if ( symb_type = = SymbolType : : exogenous | | symb_type = = SymbolType : : exogenousDet )
2012-04-02 17:54:05 +02:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " subsamples " ) "
< < R " (, " name1 " : " ) " << name1 << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
if ( ! name2 . empty ( ) )
2019-04-03 16:32:52 +02:00
output < < R " (, " name2 " : " ) " << name2 << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
2019-04-03 16:32:52 +02:00
output < < R " (, " declarations " : {) " ;
2018-06-04 15:03:26 +02:00
for ( auto it = subsample_declaration_map . begin ( ) ;
2019-12-16 19:42:59 +01:00
it ! = subsample_declaration_map . end ( ) ; + + it )
2017-02-08 18:29:57 +01:00
{
if ( it ! = subsample_declaration_map . begin ( ) )
output < < " , " ;
output < < " { "
2019-04-03 16:32:52 +02:00
< < R " ( " range_index " : " ) " << it->first << R " ( " ) "
< < R " (, " date1 " : " ) " << it->second.first << R " ( " ) "
< < R " (, " date2 " : " ) " << it->second.second << R " ( " ) "
2017-02-08 18:29:57 +01:00
< < " } " ;
}
output < < " } "
< < " } " ;
}
2018-06-04 12:31:07 +02:00
SubsamplesEqualStatement : : SubsamplesEqualStatement ( string to_name1_arg ,
string to_name2_arg ,
string from_name1_arg ,
string from_name2_arg ,
2018-07-31 10:49:23 +02:00
const SymbolTable & symbol_table_arg ) :
2018-10-04 17:18:27 +02:00
to_name1 { move ( to_name1_arg ) } ,
to_name2 { move ( to_name2_arg ) } ,
from_name1 { move ( from_name1_arg ) } ,
from_name2 { move ( from_name2_arg ) } ,
2018-07-31 10:49:23 +02:00
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 ;
2018-07-17 18:34:07 +02:00
if ( symb_type = = SymbolType : : parameter )
2012-04-02 18:06:19 +02:00
lhs_field = " parameter " ;
2018-07-17 18:34:07 +02:00
else if ( symb_type = = SymbolType : : exogenous | | symb_type = = SymbolType : : exogenousDet )
2012-04-02 18:06:19 +02:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " subsamples_equal " ) "
< < R " (, " to_name1 " : " ) " << to_name1 << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
if ( ! to_name2 . empty ( ) )
2019-04-03 16:32:52 +02:00
output < < R " (, " to_name2 " : " ) " << to_name2 << R " ( " ) " ;
output < < R " (, " from_name1 " : " ) " << from_name1 << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
if ( ! from_name2 . empty ( ) )
2019-04-03 16:32:52 +02:00
output < < R " (, " from_name2 " : " ) " << from_name2 << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
output < < " } " ;
}
2018-07-31 10:49:23 +02:00
JointPriorStatement : : JointPriorStatement ( vector < string > joint_parameters_arg ,
PriorDistributions prior_shape_arg ,
2018-06-04 12:31:07 +02:00
OptionsList options_list_arg ) :
2018-07-31 10:49:23 +02:00
joint_parameters { move ( joint_parameters_arg ) } ,
2018-10-04 17:18:27 +02:00
prior_shape { prior_shape_arg } ,
options_list { move ( options_list_arg ) }
2015-03-03 15:08:33 +01:00
{
}
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 ) ;
}
2018-07-18 16:52:12 +02:00
if ( prior_shape = = PriorDistributions : : noShape )
2015-03-03 15:08:33 +01:00
{
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 ) ;
}
2019-12-16 19:42:59 +01:00
if ( auto it_num = options_list . num_options . find ( " domain " ) ;
it_num ! = options_list . num_options . end ( ) )
2015-03-03 15:08:33 +01:00
{
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
{
2019-12-20 16:59:30 +01:00
for ( const auto & joint_parameter : joint_parameters )
2015-03-03 15:08:33 +01:00
output < < " eifind = get_new_or_existing_ei_index('joint_parameter_prior_index', ' "
2018-06-04 12:26:16 +02:00
< < joint_parameter < < " ', ''); " < < endl
< < " estimation_info.joint_parameter_prior_index(eifind) = {' " < < joint_parameter < < " '}; " < < endl ;
2015-03-03 15:08:33 +01:00
output < < " key = {[ " ;
2019-12-20 16:59:30 +01:00
for ( const auto & joint_parameter : joint_parameters )
2018-06-04 12:26:16 +02:00
output < < " get_new_or_existing_ei_index('joint_parameter_prior_index', ' " < < joint_parameter < < " ', '') ... "
2015-03-03 15:08:33 +01:00
< < 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 ) ;
2018-07-18 16:52:12 +02:00
assert ( prior_shape ! = PriorDistributions : : noShape ) ;
output < < lhs_field < < " .shape = " < < static_cast < int > ( prior_shape ) < < " ; " < < endl ;
2015-03-03 15:08:33 +01:00
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
{
output < < lhs_field < < " . " < < field < < " = { " ;
2017-06-01 19:58:32 +02:00
if ( field = = " variance " )
2015-03-09 17:58:06 +01:00
output < < " { " ;
2019-12-16 19:42:59 +01:00
if ( auto itn = options_list . num_options . find ( field ) ;
itn ! = options_list . num_options . end ( ) )
2015-03-03 15:08:33 +01:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " joint_prior " ) "
< < R " (, " key " : [) " ;
2019-12-16 19:42:59 +01:00
for ( auto it = joint_parameters . begin ( ) ; it ! = joint_parameters . end ( ) ; + + it )
2017-02-08 18:29:57 +01:00
{
if ( it ! = joint_parameters . begin ( ) )
output < < " , " ;
2019-04-03 16:32:52 +02:00
output < < R " ( " ) " << *it << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
}
output < < " ] " ;
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
2019-04-03 16:32:52 +02:00
output < < R " (, " shape " : ) " ;
2017-06-14 07:01:31 +02:00
switch ( prior_shape )
2017-02-08 18:29:57 +01:00
{
2018-07-18 16:52:12 +02:00
case PriorDistributions : : beta :
2019-04-03 16:32:52 +02:00
output < < R " ( " beta " ) " ;
2017-02-08 18:29:57 +01:00
break ;
2018-07-18 16:52:12 +02:00
case PriorDistributions : : gamma :
2019-04-03 16:32:52 +02:00
output < < R " ( " gamma " ) " ;
2017-02-08 18:29:57 +01:00
break ;
2018-07-18 16:52:12 +02:00
case PriorDistributions : : normal :
2019-04-03 16:32:52 +02:00
output < < R " ( " normal " ) " ;
2017-02-08 18:29:57 +01:00
break ;
2018-07-18 16:52:12 +02:00
case PriorDistributions : : invGamma :
2019-04-03 16:32:52 +02:00
output < < R " ( " inv_gamma " ) " ;
2017-02-08 18:29:57 +01:00
break ;
2018-07-18 16:52:12 +02:00
case PriorDistributions : : uniform :
2019-04-03 16:32:52 +02:00
output < < R " ( " uniform " ) " ;
2017-02-08 18:29:57 +01:00
break ;
2018-07-18 16:52:12 +02:00
case PriorDistributions : : invGamma2 :
2019-04-03 16:32:52 +02:00
output < < R " ( " inv_gamma2 " ) " ;
2017-02-08 18:29:57 +01:00
break ;
2018-07-18 16:52:12 +02:00
case PriorDistributions : : dirichlet :
2019-04-03 16:32:52 +02:00
output < < R " ( " dirichlet " ) " ;
2017-02-08 18:29:57 +01:00
break ;
2018-07-18 16:52:12 +02:00
case PriorDistributions : : weibull :
2019-04-03 16:32:52 +02:00
output < < R " ( " weibull " ) " ;
2017-02-08 18:29:57 +01:00
break ;
2018-07-18 16:52:12 +02:00
case PriorDistributions : : noShape :
2017-02-08 18:29:57 +01:00
cerr < < " Impossible case. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
output < < " } " ;
}
2015-03-03 15:08:33 +01:00
2018-06-04 12:31:07 +02:00
BasicPriorStatement : : BasicPriorStatement ( string name_arg ,
string subsample_name_arg ,
2018-07-31 10:49:23 +02:00
PriorDistributions prior_shape_arg ,
expr_t variance_arg ,
2018-06-04 12:31:07 +02:00
OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
name { move ( name_arg ) } ,
subsample_name { move ( subsample_name_arg ) } ,
prior_shape { prior_shape_arg } ,
variance { variance_arg } ,
options_list { move ( 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
{
2018-07-18 16:52:12 +02:00
if ( prior_shape = = PriorDistributions : : noShape )
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 ) ;
}
2019-12-16 19:42:59 +01:00
if ( auto it_stdev = options_list . num_options . find ( " stdev " ) ;
( it_stdev = = options_list . num_options . end ( ) & & ! variance )
| | ( it_stdev ! = options_list . num_options . end ( ) & & variance ) )
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 ) ;
}
2019-12-16 19:42:59 +01:00
if ( auto it_num = options_list . num_options . find ( " domain " ) ;
it_num ! = options_list . num_options . end ( ) )
2012-01-02 22:44:50 +01:00
{
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
{
2018-07-17 18:34:07 +02:00
if ( symb_type = = SymbolType : : exogenous | | symb_type = = SymbolType : : exogenousDet )
2013-08-06 21:29:11 +02:00
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
{
2018-07-17 18:34:07 +02:00
if ( symb_type = = SymbolType : : exogenous | | symb_type = = SymbolType : : exogenousDet )
2011-12-11 15:35:26 +01:00
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 ) ;
2018-07-18 16:52:12 +02:00
assert ( prior_shape ! = PriorDistributions : : noShape ) ;
output < < lhs_field < < " .shape = " < < static_cast < int > ( prior_shape ) < < " ; " < < endl ;
2012-03-29 15:21:32 +02:00
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
{
2019-12-16 19:42:59 +01:00
if ( auto itn = options_list . num_options . find ( field ) ;
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
{
2019-04-03 16:32:52 +02:00
output < < R " (, " name " : " ) " << name << R " ( " ) "
< < R " (, " subsample " : " ) " << subsample_name << R " ( " ) "
2017-02-08 18:29:57 +01:00
< < " , " ;
writeJsonShape ( output ) ;
2019-12-16 19:42:59 +01:00
if ( variance )
2017-02-08 18:29:57 +01:00
{
2019-04-03 16:32:52 +02:00
output < < R " (, " variance " : " ) " ;
2018-05-29 11:59:42 +02:00
variance - > writeJsonOutput ( output , { } , { } ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " ) " ;
2017-02-08 18:29:57 +01:00
}
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
}
void
BasicPriorStatement : : writeJsonShape ( ostream & output ) const
{
2019-04-03 16:32:52 +02:00
output < < R " ( " shape " : ) " ;
2017-02-08 18:29:57 +01:00
switch ( prior_shape )
{
2018-07-18 16:52:12 +02:00
case PriorDistributions : : beta :
2019-04-03 16:32:52 +02:00
output < < R " ( " beta " ) " ;
2017-02-08 18:29:57 +01:00
break ;
2018-07-18 16:52:12 +02:00
case PriorDistributions : : gamma :
2019-04-03 16:32:52 +02:00
output < < R " ( " gamma " ) " ;
2017-02-08 18:29:57 +01:00
break ;
2018-07-18 16:52:12 +02:00
case PriorDistributions : : normal :
2019-04-03 16:32:52 +02:00
output < < R " ( " normal " ) " ;
2017-02-08 18:29:57 +01:00
break ;
2018-07-18 16:52:12 +02:00
case PriorDistributions : : invGamma :
2019-04-03 16:32:52 +02:00
output < < R " ( " inv_gamma " ) " ;
2017-02-08 18:29:57 +01:00
break ;
2018-07-18 16:52:12 +02:00
case PriorDistributions : : uniform :
2019-04-03 16:32:52 +02:00
output < < R " ( " uniform " ) " ;
2017-02-08 18:29:57 +01:00
break ;
2018-07-18 16:52:12 +02:00
case PriorDistributions : : invGamma2 :
2019-04-03 16:32:52 +02:00
output < < R " ( " inv_gamma2 " ) " ;
2017-02-08 18:29:57 +01:00
break ;
2018-07-18 16:52:12 +02:00
case PriorDistributions : : dirichlet :
2019-04-03 16:32:52 +02:00
output < < R " ( " dirichlet " ) " ;
2017-02-08 18:29:57 +01:00
break ;
2018-07-18 16:52:12 +02:00
case PriorDistributions : : weibull :
2019-04-03 16:32:52 +02:00
output < < R " ( " weibull " ) " ;
2017-02-08 18:29:57 +01:00
break ;
2018-07-18 16:52:12 +02:00
case PriorDistributions : : noShape :
assert ( prior_shape ! = PriorDistributions : : noShape ) ;
2017-02-08 18:29:57 +01:00
}
}
2018-07-31 10:49:23 +02:00
PriorStatement : : PriorStatement ( string name_arg ,
string subsample_name_arg ,
PriorDistributions prior_shape_arg ,
expr_t variance_arg ,
OptionsList options_list_arg ) :
BasicPriorStatement { move ( name_arg ) , move ( subsample_name_arg ) , prior_shape_arg , variance_arg , move ( 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " prior " ) " ;
2017-02-08 18:29:57 +01:00
writeJsonPriorOutput ( output ) ;
output < < " } " ;
}
2018-07-31 10:49:23 +02:00
StdPriorStatement : : StdPriorStatement ( string name_arg ,
string subsample_name_arg ,
PriorDistributions prior_shape_arg ,
expr_t variance_arg ,
OptionsList options_list_arg ,
const SymbolTable & symbol_table_arg ) :
BasicPriorStatement { move ( name_arg ) , move ( subsample_name_arg ) , prior_shape_arg , variance_arg , move ( options_list_arg ) } ,
symbol_table { symbol_table_arg }
2011-12-11 15:35:26 +01:00
{
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " std_prior " ) " ;
2017-02-08 18:29:57 +01:00
writeJsonPriorOutput ( output ) ;
output < < " } " ;
}
2018-07-31 10:49:23 +02:00
CorrPriorStatement : : CorrPriorStatement ( string name_arg1 , string name_arg2 ,
string subsample_name_arg ,
PriorDistributions prior_shape_arg ,
expr_t variance_arg ,
OptionsList options_list_arg ,
const SymbolTable & symbol_table_arg ) :
BasicPriorStatement { move ( name_arg1 ) , move ( subsample_name_arg ) , prior_shape_arg , variance_arg , move ( options_list_arg ) } ,
2018-10-04 17:18:27 +02:00
name1 { move ( name_arg2 ) } ,
2018-07-31 10:49:23 +02:00
symbol_table { symbol_table_arg }
2011-12-11 15:35:26 +01:00
{
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " corr_prior " ) "
< < R " (, " name2 " : " ) " << name1 << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
writeJsonPriorOutput ( output ) ;
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
PriorEqualStatement : : PriorEqualStatement ( string to_declaration_type_arg ,
string to_name1_arg ,
string to_name2_arg ,
string to_subsample_name_arg ,
string from_declaration_type_arg ,
string from_name1_arg ,
string from_name2_arg ,
string from_subsample_name_arg ,
2018-07-31 10:49:23 +02:00
const SymbolTable & symbol_table_arg ) :
2018-10-04 17:18:27 +02:00
to_declaration_type { move ( to_declaration_type_arg ) } ,
to_name1 { move ( to_name1_arg ) } ,
to_name2 { move ( to_name2_arg ) } ,
to_subsample_name { move ( to_subsample_name_arg ) } ,
from_declaration_type { move ( from_declaration_type_arg ) } ,
from_name1 { move ( from_name1_arg ) } ,
from_name2 { move ( from_name2_arg ) } ,
from_subsample_name { move ( from_subsample_name_arg ) } ,
2018-07-31 10:49:23 +02:00
symbol_table { symbol_table_arg }
2015-04-14 11:33:02 +02:00
{
}
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
{
2018-07-17 18:34:07 +02:00
if ( symb_type = = SymbolType : : exogenous | | symb_type = = SymbolType : : exogenousDet )
2012-03-30 14:55:25 +02:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " prior_equal " ) "
< < R " (, " to_name1 " : " ) " << to_name1 << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
if ( to_declaration_type = = " corr " )
2019-04-03 16:32:52 +02:00
output < < R " (, " to_name2 " : " ) " << to_name2 << R " ( " ) " ;
output < < R " (, " to_subsample " : " ) " << to_subsample_name << R " ( " ) "
< < R " (, " from_name1 " : " ) " << from_name1 << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
if ( to_declaration_type = = " corr " )
2019-04-03 16:32:52 +02:00
output < < R " (, " from_name2 " : " ) " << from_name2 << R " ( " ) " ;
output < < R " (, " from_subsample " : " ) " << from_subsample_name << R " ( " ) "
2017-02-08 18:29:57 +01:00
< < " } " ;
}
2018-06-04 12:31:07 +02:00
BasicOptionsStatement : : BasicOptionsStatement ( string name_arg ,
string subsample_name_arg ,
OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
name { move ( name_arg ) } ,
subsample_name { move ( subsample_name_arg ) } ,
options_list { move ( 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
{
2019-12-16 19:42:59 +01:00
return symb_type = = SymbolType : : exogenous | | symb_type = = SymbolType : : exogenousDet ;
2013-08-06 21:44:04 +02:00
}
2011-12-14 17:19:14 +01:00
void
BasicOptionsStatement : : get_base_name ( const SymbolType symb_type , string & lhs_field ) const
{
2018-07-17 18:34:07 +02:00
if ( symb_type = = SymbolType : : exogenous | | symb_type = = SymbolType : : exogenousDet )
2011-12-14 17:19:14 +01:00
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
{
2019-12-16 19:42:59 +01:00
if ( auto itn = options_list . num_options . find ( field ) ;
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
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " (, " name " : " ) " << name << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
if ( ! subsample_name . empty ( ) )
2019-04-03 16:32:52 +02:00
output < < R " (, " subsample_name " : " ) " << subsample_name << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
}
2018-07-31 10:49:23 +02:00
OptionsStatement : : OptionsStatement ( string name_arg ,
string subsample_name_arg ,
OptionsList options_list_arg ) :
BasicOptionsStatement { move ( name_arg ) , move ( subsample_name_arg ) , move ( 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " options " ) " ;
2017-02-08 18:29:57 +01:00
writeJsonOptionsOutput ( output ) ;
output < < " } " ;
}
2018-07-31 10:49:23 +02:00
StdOptionsStatement : : StdOptionsStatement ( string name_arg ,
string subsample_name_arg ,
OptionsList options_list_arg ,
const SymbolTable & symbol_table_arg ) :
BasicOptionsStatement { move ( name_arg ) , move ( subsample_name_arg ) , move ( options_list_arg ) } ,
symbol_table { symbol_table_arg }
2011-12-14 17:19:14 +01:00
{
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " std_options " ) " ;
2017-02-08 18:29:57 +01:00
writeJsonOptionsOutput ( output ) ;
output < < " } " ;
}
2018-07-31 10:49:23 +02:00
CorrOptionsStatement : : CorrOptionsStatement ( string name_arg1 , string name_arg2 ,
string subsample_name_arg ,
OptionsList options_list_arg ,
const SymbolTable & symbol_table_arg ) :
BasicOptionsStatement { move ( name_arg1 ) , move ( subsample_name_arg ) , move ( options_list_arg ) } ,
name1 { move ( name_arg2 ) } ,
symbol_table { symbol_table_arg }
2011-12-14 17:19:14 +01:00
{
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " corr_options " ) "
< < R " (, " name2 " : " ) " << name1 << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
writeJsonOptionsOutput ( output ) ;
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
OptionsEqualStatement : : OptionsEqualStatement ( string to_declaration_type_arg ,
string to_name1_arg ,
string to_name2_arg ,
string to_subsample_name_arg ,
string from_declaration_type_arg ,
string from_name1_arg ,
string from_name2_arg ,
string from_subsample_name_arg ,
2018-07-31 10:49:23 +02:00
const SymbolTable & symbol_table_arg ) :
2018-10-04 17:18:27 +02:00
to_declaration_type { move ( to_declaration_type_arg ) } ,
to_name1 { move ( to_name1_arg ) } ,
to_name2 { move ( to_name2_arg ) } ,
to_subsample_name { move ( to_subsample_name_arg ) } ,
from_declaration_type { move ( from_declaration_type_arg ) } ,
from_name1 { move ( from_name1_arg ) } ,
from_name2 { move ( from_name2_arg ) } ,
from_subsample_name { move ( from_subsample_name_arg ) } ,
2018-07-31 10:49:23 +02:00
symbol_table { symbol_table_arg }
2012-03-30 15:36:58 +02:00
{
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " options_equal " ) "
< < R " (, " to_name1 " : " ) " << to_name1 << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
if ( to_declaration_type = = " corr " )
2019-04-03 16:32:52 +02:00
output < < R " (, " to_name2 " : " ) " << to_name2 << R " ( " ) " ;
output < < R " (, " to_subsample " : " ) " << to_subsample_name << R " ( " ) "
< < R " (, " from_name1 " : " ) " << from_name1 << R " ( " ) " ;
2017-02-08 18:29:57 +01:00
if ( to_declaration_type = = " corr " )
2019-04-03 16:32:52 +02:00
output < < R " (, " from_name2 " : " ) " << from_name2 << R " ( " ) " ;
output < < R " (, " from_subsample " : " ) " << from_subsample_name << R " ( " ) "
2017-02-08 18:29:57 +01:00
< < " } " ;
}
2012-03-30 15:36:58 +02:00
void
OptionsEqualStatement : : get_base_name ( const SymbolType symb_type , string & lhs_field ) const
{
2018-07-17 18:34:07 +02:00
if ( symb_type = = SymbolType : : exogenous | | symb_type = = SymbolType : : exogenousDet )
2012-03-30 15:36:58 +02:00
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
2018-06-04 12:31:07 +02:00
CalibSmootherStatement : : CalibSmootherStatement ( SymbolList symbol_list_arg ,
OptionsList options_list_arg )
2018-10-04 17:18:27 +02:00
: symbol_list { move ( symbol_list_arg ) } , options_list { move ( options_list_arg ) }
2012-05-30 16:28:00 +02:00
{
}
2013-10-28 14:22:23 +01:00
void
CalibSmootherStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
mod_file_struct . calib_smoother_present = true ;
2019-12-19 14:48:55 +01:00
try
{
2020-01-07 11:55:12 +01:00
symbol_list . checkPass ( warnings , { SymbolType : : endogenous } ) ;
2019-12-19 14:48:55 +01:00
}
catch ( SymbolList : : SymbolListException & e )
{
cerr < < " ERROR: calib_smoother: " < < e . message < < endl ;
exit ( EXIT_FAILURE ) ;
}
2013-10-28 14:22:23 +01:00
}
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 ) ;
2019-12-16 19:42:59 +01:00
if ( options_list . string_options . find ( " parameter_set " ) = = options_list . string_options . end ( ) )
2017-08-28 18:19:41 +02:00
output < < " options_.parameter_set = 'calibration'; " < < endl ;
2012-05-30 16:28:00 +02:00
symbol_list . writeOutput ( " var_list_ " , output ) ;
2019-03-19 14:05:41 +01:00
output < < " options_.smoother = true; " < < endl
2017-08-28 17:46:50 +02:00
< < " options_.order = 1; " < < endl
2017-08-28 18:19:41 +02:00
< < " [oo_, M_, options_, bayestopt_] = evaluate_smoother(options_.parameter_set, 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " calib_smoother " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
if ( ! symbol_list . empty ( ) )
{
output < < " , " ;
symbol_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2018-06-04 12:31:07 +02:00
ExtendedPathStatement : : ExtendedPathStatement ( OptionsList options_list_arg )
2018-10-04 17:18:27 +02:00
: options_list { move ( options_list_arg ) }
2012-06-08 17:36:32 +02:00
{
}
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 ) ;
}
}
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...
2019-12-20 16:59:30 +01:00
for ( const auto & num_option : options_list . num_options )
2019-12-16 19:42:59 +01:00
if ( num_option . first ! = " periods " )
2018-06-04 12:26:16 +02:00
output < < " options_. " < < num_option . first < < " = " < < num_option . 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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " extended_path " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2012-11-16 12:34:49 +01:00
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " model_diagnostics " }) " ;
2017-02-08 18:29:57 +01:00
}
2018-06-04 12:31:07 +02:00
Smoother2histvalStatement : : Smoother2histvalStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2014-04-03 15:05:20 +02:00
{
}
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
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " smoother_2_histval " ) " ;
2017-02-08 18:29:57 +01:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2017-10-05 15:09:04 +02:00
2021-06-24 15:04:21 +02:00
MethodOfMomentsStatement : : MethodOfMomentsStatement ( OptionsList options_list_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) }
2017-10-05 15:09:04 +02:00
{
}
2019-12-19 14:48:55 +01:00
void
2020-07-08 18:42:14 +02:00
MethodOfMomentsStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2019-12-19 14:48:55 +01:00
{
2020-07-08 18:42:14 +02:00
mod_file_struct . mom_estimation_present = true ;
// Fill in option_order of mod_file_struct
if ( auto it = options_list . num_options . find ( " order " ) ;
it ! = options_list . num_options . end ( ) )
{
int order = stoi ( it - > second ) ;
2019-12-19 14:48:55 +01:00
2020-07-08 18:42:14 +02:00
if ( order > 2 )
mod_file_struct . k_order_solver = true ;
2017-10-05 15:09:04 +02:00
2020-12-11 13:27:23 +01:00
mod_file_struct . mom_order = order ;
2020-07-08 18:42:14 +02:00
mod_file_struct . order_option = max ( mod_file_struct . order_option , order ) ;
2017-10-05 15:09:04 +02:00
}
2020-07-08 18:42:14 +02:00
if ( options_list . string_options . find ( " datafile " ) = = options_list . string_options . end ( ) )
2020-12-11 13:27:23 +01:00
{
cerr < < " ERROR: The method_of_moments statement requires a data file to be supplied via the datafile option. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2020-07-08 18:42:14 +02:00
if ( options_list . string_options . find ( " mom.mom_method " ) = = options_list . string_options . end ( ) )
2020-12-11 13:27:23 +01:00
{
cerr < < " ERROR: The method_of_moments statement requires a method to be supplied via the mom_method option. Possible values are GMM or SMM. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
if ( auto it = options_list . string_options . find ( " mom.mom_method " ) ;
it ! = options_list . string_options . end ( ) & & it - > second = = " GMM " )
mod_file_struct . GMM_present = true ;
if ( auto it = options_list . num_options . find ( " mom.analytic_standard_errors " ) ;
it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
mod_file_struct . analytic_standard_errors_present = true ;
2021-01-08 15:04:13 +01:00
2020-12-11 13:27:23 +01:00
if ( ! mod_file_struct . GMM_present & & mod_file_struct . analytic_standard_errors_present )
{
cerr < < " ERROR: The analytic_standard_errors statement requires the GMM option. " < < endl ;
exit ( EXIT_FAILURE ) ;
2021-01-08 15:04:13 +01:00
}
if ( auto it = options_list . num_options . find ( " mom.analytic_jacobian " ) ;
it ! = options_list . num_options . end ( ) & & it - > second = = " true " )
mod_file_struct . analytic_jacobian_present = true ;
if ( ! mod_file_struct . GMM_present & & mod_file_struct . analytic_jacobian_present )
{
cerr < < " ERROR: The analytic_jacobian statement requires the GMM option. " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2019-12-19 14:48:55 +01:00
}
2017-10-05 15:09:04 +02:00
void
2020-07-08 18:42:14 +02:00
MethodOfMomentsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2017-10-05 15:09:04 +02:00
{
2020-07-08 18:42:14 +02:00
options_list . writeOutput ( output , " options_mom_ " ) ;
2021-08-15 20:44:24 +02:00
output < < " [oo_, options_mom_, M_] = mom.run(bayestopt_, options_, oo_, estim_params_, M_, options_mom_); " < < endl ;
2017-10-05 15:09:04 +02:00
}
void
2020-07-08 18:42:14 +02:00
MethodOfMomentsStatement : : writeJsonOutput ( ostream & output ) const
2017-10-05 15:09:04 +02:00
{
2020-07-08 18:42:14 +02:00
output < < R " ({ " statementName " : " method_of_moments " ) " ;
2017-10-05 15:09:04 +02:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
output < < " } " ;
}
2017-10-06 14:49:14 +02:00
2020-07-08 18:42:14 +02:00
2018-06-04 12:31:07 +02:00
GenerateIRFsStatement : : GenerateIRFsStatement ( OptionsList options_list_arg ,
vector < string > generate_irf_names_arg ,
2018-06-04 14:17:36 +02:00
vector < map < string , double > > generate_irf_elements_arg ) :
2018-10-04 17:18:27 +02:00
options_list { move ( options_list_arg ) } ,
generate_irf_names { move ( generate_irf_names_arg ) } ,
generate_irf_elements { move ( generate_irf_elements_arg ) }
2017-10-06 14:49:14 +02:00
{
}
void
GenerateIRFsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
options_list . writeOutput ( output ) ;
if ( generate_irf_names . empty ( ) )
2017-10-09 11:18:42 +02:00
return ;
2017-10-06 14:49:14 +02:00
output < < " options_.irf_opt.irf_shock_graphtitles = { " ;
2019-12-20 16:59:30 +01:00
for ( const auto & generate_irf_name : generate_irf_names )
2018-06-04 12:26:16 +02:00
output < < " ' " < < generate_irf_name < < " '; " ;
2017-10-06 14:49:14 +02:00
output < < " }; " < < endl ;
2017-10-09 11:18:42 +02:00
output < < " options_.irf_opt.irf_shocks = zeros(M_.exo_nbr, "
< < generate_irf_names . size ( ) < < " ); " < < endl ;
for ( size_t i = 0 ; i < generate_irf_names . size ( ) ; i + + )
{
map < string , double > m = generate_irf_elements [ i ] ;
2019-12-20 16:59:30 +01:00
for ( auto & it : m )
2017-10-09 11:18:42 +02:00
output < < " options_.irf_opt.irf_shocks(M_.exo_names == ' "
2019-12-16 19:42:59 +01:00
< < it . first < < " ', " < < i + 1 < < " ) = "
< < it . second < < " ; " < < endl ;
2017-10-09 11:18:42 +02:00
}
2017-10-06 14:49:14 +02:00
}
void
GenerateIRFsStatement : : writeJsonOutput ( ostream & output ) const
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " generate_irfs " ) " ;
2017-10-06 14:49:14 +02:00
if ( options_list . getNumberOfOptions ( ) )
{
output < < " , " ;
options_list . writeJsonOutput ( output ) ;
}
2017-10-09 11:18:42 +02:00
if ( ! generate_irf_names . empty ( ) )
2017-10-06 14:49:14 +02:00
{
2019-04-03 16:32:52 +02:00
output < < R " (, " irf_elements " : [) " ;
2017-10-09 11:18:42 +02:00
for ( size_t i = 0 ; i < generate_irf_names . size ( ) ; i + + )
2017-10-06 14:49:14 +02:00
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " name " : " ) " << generate_irf_names[i] << R " ( " , " shocks " : [) " ;
2017-10-09 11:18:42 +02:00
map < string , double > m = generate_irf_elements [ i ] ;
size_t idx = 0 ;
2019-12-16 19:42:59 +01:00
for ( auto it = m . begin ( ) ; it ! = m . end ( ) ; + + it , idx + + )
2017-10-09 11:18:42 +02:00
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " exogenous_variable " : " ) " << it->first << R " ( " , ) "
< < R " ( " exogenous_variable_value " : " ) " << it->second << R " ( " }) " ;
2017-10-09 11:18:42 +02:00
if ( idx + 1 < m . size ( ) )
output < < " , " ;
}
output < < " ]} " ;
if ( i + 1 < generate_irf_names . size ( ) )
2017-10-06 14:49:14 +02:00
output < < " , " ;
}
output < < " ] " ;
}
output < < " } " ;
}
2018-08-01 19:41:44 +02:00
2018-08-22 16:57:36 +02:00
VarExpectationModelStatement : : VarExpectationModelStatement ( string model_name_arg ,
2018-11-28 17:32:55 +01:00
expr_t expression_arg ,
2018-08-22 16:57:36 +02:00
string aux_model_name_arg ,
string horizon_arg ,
expr_t discount_arg ,
2021-07-01 17:56:07 +02:00
int time_shift_arg ,
2018-08-22 16:57:36 +02:00
const SymbolTable & symbol_table_arg ) :
2018-11-28 17:32:55 +01:00
model_name { move ( model_name_arg ) } , expression { expression_arg } ,
2018-08-22 16:57:36 +02:00
aux_model_name { move ( aux_model_name_arg ) } , horizon { move ( horizon_arg ) } ,
2021-07-01 17:56:07 +02:00
discount { discount_arg } , time_shift { time_shift_arg } , symbol_table { symbol_table_arg }
2018-08-01 19:41:44 +02:00
{
2018-11-29 16:01:49 +01:00
}
void
2019-10-22 14:56:28 +02:00
VarExpectationModelStatement : : substituteUnaryOpNodes ( const lag_equivalence_table_t & nodes , ExprNode : : subst_table_t & subst_table )
2018-11-29 16:01:49 +01:00
{
vector < BinaryOpNode * > neweqs ;
2019-10-22 14:56:28 +02:00
expression = expression - > substituteUnaryOpNodes ( nodes , subst_table , neweqs ) ;
2018-11-29 16:01:49 +01:00
if ( neweqs . size ( ) > 0 )
{
cerr < < " ERROR: the 'expression' option of var_expectation_model contains a variable with a unary operator that is not present in the VAR model " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
void
2019-10-22 14:56:28 +02:00
VarExpectationModelStatement : : substituteDiff ( const lag_equivalence_table_t & nodes , ExprNode : : subst_table_t & subst_table )
2018-11-29 16:01:49 +01:00
{
vector < BinaryOpNode * > neweqs ;
2019-10-22 14:56:28 +02:00
expression = expression - > substituteDiff ( nodes , subst_table , neweqs ) ;
2018-11-29 16:01:49 +01:00
if ( neweqs . size ( ) > 0 )
2018-11-28 17:32:55 +01:00
{
2018-11-29 16:01:49 +01:00
cerr < < " ERROR: the 'expression' option of var_expectation_model contains a diff'd variable that is not present in the VAR model " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
void
VarExpectationModelStatement : : matchExpression ( )
{
try
{
auto vpc = expression - > matchLinearCombinationOfVariables ( ) ;
for ( const auto & it : vpc )
{
if ( get < 1 > ( it ) ! = 0 )
throw ExprNode : : MatchFailureException { " lead/lags are not allowed " } ;
if ( symbol_table . getType ( get < 0 > ( it ) ) ! = SymbolType : : endogenous )
throw ExprNode : : MatchFailureException { " Variable is not an endogenous " } ;
vars_params_constants . emplace_back ( get < 0 > ( it ) , get < 2 > ( it ) , get < 3 > ( it ) ) ;
}
}
catch ( ExprNode : : MatchFailureException & e )
{
cerr < < " ERROR: expression in var_expectation_model is not of the expected form: " < < e . message < < endl ;
exit ( EXIT_FAILURE ) ;
2018-11-28 17:32:55 +01:00
}
2018-08-01 19:41:44 +02:00
}
void
VarExpectationModelStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
string mstruct = " M_.var_expectation. " + model_name ;
2018-08-22 16:57:36 +02:00
output < < mstruct < < " .auxiliary_model_name = ' " < < aux_model_name < < " '; " < < endl
2021-07-01 17:56:07 +02:00
< < mstruct < < " .horizon = " < < horizon < < ' ; ' < < endl
< < mstruct < < " .time_shift = " < < time_shift < < ' ; ' < < endl ;
2018-11-28 17:32:55 +01:00
2018-11-29 16:01:49 +01:00
if ( ! vars_params_constants . size ( ) )
{
cerr < < " ERROR: VarExpectationModelStatement::writeOutput: matchExpression() has not been called " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2018-11-28 17:32:55 +01:00
ostringstream vars_list , params_list , constants_list ;
for ( auto it = vars_params_constants . begin ( ) ; it ! = vars_params_constants . end ( ) ; + + it )
{
if ( it ! = vars_params_constants . begin ( ) )
{
vars_list < < " , " ;
params_list < < " , " ;
constants_list < < " , " ;
}
vars_list < < symbol_table . getTypeSpecificID ( get < 0 > ( * it ) ) + 1 ;
if ( get < 1 > ( * it ) = = - 1 )
params_list < < " NaN " ;
else
params_list < < symbol_table . getTypeSpecificID ( get < 1 > ( * it ) ) + 1 ;
constants_list < < get < 2 > ( * it ) ;
}
output < < mstruct < < " .expr.vars = [ " < < vars_list . str ( ) < < " ]; " < < endl
< < mstruct < < " .expr.params = [ " < < params_list . str ( ) < < " ]; " < < endl
< < mstruct < < " .expr.constants = [ " < < constants_list . str ( ) < < " ]; " < < endl ;
2019-12-16 19:42:59 +01:00
if ( auto disc_var = dynamic_cast < const VariableNode * > ( discount ) ;
disc_var )
2018-11-28 14:32:26 +01:00
output < < mstruct < < " .discount_index = " < < symbol_table . getTypeSpecificID ( disc_var - > symb_id ) + 1 < < ' ; ' < < endl ;
2018-08-01 19:41:44 +02:00
else
{
output < < mstruct < < " .discount_value = " ;
discount - > writeOutput ( output ) ;
output < < ' ; ' < < endl ;
}
output < < mstruct < < " .param_indices = [ " ;
for ( int param_id : aux_params_ids )
2018-08-04 11:46:31 +02:00
output < < symbol_table . getTypeSpecificID ( param_id ) + 1 < < ' ' ;
2018-08-01 19:41:44 +02:00
output < < " ]; " < < endl ;
}
void
VarExpectationModelStatement : : writeJsonOutput ( ostream & output ) const
{
2019-04-03 16:32:52 +02:00
output < < R " ({ " statementName " : " var_expectation_model " ,) "
< < R " ( " model_name " : " ) " << model_name << R " ( " , ) "
< < R " ( " expression " : " ) " ;
2018-11-28 17:32:55 +01:00
expression - > writeOutput ( output ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " , ) "
< < R " ( " auxiliary_model_name " : " ) " << aux_model_name << R " ( " , ) "
< < R " ( " horizon " : " ) " << horizon << R " ( " , ) "
< < R " ( " discount " : " ) " ;
2018-08-01 19:41:44 +02:00
discount - > writeOutput ( output ) ;
2019-04-03 16:32:52 +02:00
output < < R " ( " } ) " ;
2018-08-01 19:41:44 +02:00
}
2020-07-28 18:29:45 +02:00
MatchedMomentsStatement : : MatchedMomentsStatement ( const SymbolTable & symbol_table_arg ,
vector < tuple < vector < int > , vector < int > , vector < int > > > moments_arg ) :
symbol_table { symbol_table_arg } , moments { move ( moments_arg ) }
{
}
void
MatchedMomentsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
output < < " M_.matched_moments = { " < < endl ;
for ( const auto & [ symb_ids , lags , powers ] : moments )
{
output < < " [ " ;
for ( int s : symb_ids )
output < < symbol_table . getTypeSpecificID ( s ) + 1 < < ' , ' ;
output < < " ], [ " ;
for ( int l : lags )
output < < l < < ' , ' ;
output < < " ], [ " ;
for ( int p : powers )
output < < p < < ' , ' ;
output < < " ], " < < endl ;
}
output < < " }; " < < endl ;
}
void
MatchedMomentsStatement : : writeJsonOutput ( ostream & output ) const
{
output < < R " ({ " statementName " : " matched_moments " , " moments " : [) " < < endl ;
for ( auto it = moments . begin ( ) ; it ! = moments . end ( ) ; + + it )
{
const auto & [ symb_ids , lags , powers ] = * it ;
output < < R " ( { " endos " : [) " ;
for ( auto it2 = symb_ids . begin ( ) ; it2 ! = symb_ids . end ( ) ; + + it2 )
{
if ( it2 ! = symb_ids . begin ( ) )
output < < ' , ' ;
output < < symbol_table . getTypeSpecificID ( * it2 ) + 1 ;
}
output < < R " (], " lags " : [) " ;
for ( auto it2 = lags . begin ( ) ; it2 ! = lags . end ( ) ; + + it2 )
{
if ( it2 ! = lags . begin ( ) )
output < < ' , ' ;
output < < * it2 ;
}
output < < R " (], " powers " : [) " ;
for ( auto it2 = powers . begin ( ) ; it2 ! = powers . end ( ) ; + + it2 )
{
if ( it2 ! = powers . begin ( ) )
output < < ' , ' ;
output < < * it2 ;
}
output < < " ]} " ;
if ( next ( it ) ! = moments . end ( ) )
output < < ' , ' ;
output < < endl ;
}
output < < " ]} " < < endl ;
}
2021-07-15 16:24:21 +02:00
2021-07-21 16:16:39 +02:00
OccbinConstraintsStatement : : OccbinConstraintsStatement ( const DataTree & data_tree_arg ,
2021-07-20 12:20:19 +02:00
const vector < tuple < string , BinaryOpNode * , BinaryOpNode * , expr_t , expr_t > > constraints_arg )
2021-07-21 16:16:39 +02:00
: data_tree { data_tree_arg } , constraints { constraints_arg }
2021-07-15 16:24:21 +02:00
{
}
void
OccbinConstraintsStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
{
if ( mod_file_struct . occbin_constraints_present )
{
cerr < < " ERROR: Multiple 'occbin_constraints' blocks are not allowed " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2021-07-20 12:20:19 +02:00
if ( constraints . size ( ) > 2 )
{
cerr < < " ERROR: only up to two constraints are supported in 'occbin_constraints' block " < < endl ;
exit ( EXIT_FAILURE ) ;
}
2021-07-15 16:24:21 +02:00
mod_file_struct . occbin_constraints_present = true ;
}
void
OccbinConstraintsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
2021-07-20 12:20:19 +02:00
output < < " M_.occbin.constraint_nbr = " < < constraints . size ( ) < < ' ; ' < < endl
< < " M_.occbin.pswitch = [ " < < endl ;
2021-07-15 16:24:21 +02:00
for ( const auto & [ name , bind , relax , error_bind , error_relax ] : constraints )
2021-07-21 16:16:39 +02:00
output < < data_tree . symbol_table . getTypeSpecificID ( ParsingDriver : : buildOccbinBindParamName ( name ) ) + 1 < < ' ' ;
2021-07-20 12:20:19 +02:00
output < < " ]; " < < endl
< < " options_.occbin = struct(); " < < endl
< < " options_.occbin = occbin.set_default_options(options_.occbin, M_); " < < endl
< < " oo_.dr=set_state_space(oo_.dr,M_,options_); " < < endl ;
string filename = " + " + basename + " /occbin_difference.m " ;
ofstream diff_output ;
diff_output . open ( filename , ios : : out | ios : : binary ) ;
if ( ! diff_output . is_open ( ) )
2021-07-15 16:24:21 +02:00
{
2021-07-20 12:20:19 +02:00
cerr < < " Error: Can't open file " < < filename < < " for writing " < < endl ;
exit ( EXIT_FAILURE ) ;
}
diff_output < < " function [binding, relax, err] = occbin_difference(zdatalinear, params, steady_state) " < < endl ;
int idx = 1 ;
for ( const auto & [ name , bind , relax , error_bind , error_relax ] : constraints )
{
diff_output < < " binding.constraint_ " < < idx < < " = " ;
dynamic_cast < ExprNode * > ( bind ) - > writeOutput ( diff_output , ExprNodeOutputType : : occbinDifferenceFile ) ;
diff_output < < ' ; ' < < endl
< < " relax.constraint_ " < < idx < < " = " ;
2021-07-15 16:24:21 +02:00
if ( relax )
2021-07-20 12:20:19 +02:00
dynamic_cast < ExprNode * > ( relax ) - > writeOutput ( diff_output , ExprNodeOutputType : : occbinDifferenceFile ) ;
else
diff_output < < " ~binding.constraint_ " < < idx ;
diff_output < < ' ; ' < < endl
< < " err.binding_constraint_ " < < idx < < " = " ;
2021-07-15 16:24:21 +02:00
if ( error_bind )
2021-07-20 12:20:19 +02:00
error_bind - > writeOutput ( diff_output , ExprNodeOutputType : : occbinDifferenceFile ) ;
else
{
diff_output < < " abs(( " ;
bind - > arg1 - > writeOutput ( diff_output , ExprNodeOutputType : : occbinDifferenceFile ) ;
diff_output < < " )-( " ;
bind - > arg2 - > writeOutput ( diff_output , ExprNodeOutputType : : occbinDifferenceFile ) ;
diff_output < < " )) " ;
}
diff_output < < ' ; ' < < endl
< < " err.relax_constraint_ " < < idx < < " = " ;
2021-07-15 16:24:21 +02:00
if ( error_relax )
2021-07-20 12:20:19 +02:00
error_relax - > writeOutput ( diff_output , ExprNodeOutputType : : occbinDifferenceFile ) ;
else if ( relax )
{
diff_output < < " abs(( " ;
relax - > arg1 - > writeOutput ( diff_output , ExprNodeOutputType : : occbinDifferenceFile ) ;
diff_output < < " )-( " ;
relax - > arg2 - > writeOutput ( diff_output , ExprNodeOutputType : : occbinDifferenceFile ) ;
diff_output < < " )) " ;
}
else if ( ! error_bind )
/* If relax, error_relax and error_bind have not been specified, then
error_bind and error_relax have the same default value . */
diff_output < < " err.binding_constraint_ " < < idx ;
else
{
/* If relax and error_relax have not been specified, but error_bind
has been specified , then we need to compute the default value for
error_relax since it is different from error_bind . */
diff_output < < " abs(( " ;
bind - > arg1 - > writeOutput ( diff_output , ExprNodeOutputType : : occbinDifferenceFile ) ;
diff_output < < " )-( " ;
bind - > arg2 - > writeOutput ( diff_output , ExprNodeOutputType : : occbinDifferenceFile ) ;
diff_output < < " )) " ;
}
diff_output < < ' ; ' < < endl ;
idx + + ;
2021-07-15 16:24:21 +02:00
}
2021-07-20 12:20:19 +02:00
diff_output < < " end " < < endl ;
diff_output . close ( ) ;
2021-07-15 16:24:21 +02:00
}
void
OccbinConstraintsStatement : : writeJsonOutput ( ostream & output ) const
{
output < < R " ({ " statementName " : " occbin_constraints " , " constraints " : [) " < < endl ;
for ( auto it = constraints . begin ( ) ; it ! = constraints . end ( ) ; + + it )
{
auto [ name , bind , relax , error_bind , error_relax ] = * it ;
output < < R " ({ " name " : " ) " << name << R " ( " , " bind " : " ) " ;
2021-07-20 12:20:19 +02:00
dynamic_cast < ExprNode * > ( bind ) - > writeJsonOutput ( output , { } , { } ) ;
2021-07-15 16:24:21 +02:00
output < < R " ( " , " relax " : " ) " ;
if ( relax )
2021-07-20 12:20:19 +02:00
dynamic_cast < ExprNode * > ( relax ) - > writeJsonOutput ( output , { } , { } ) ;
2021-07-15 16:24:21 +02:00
output < < R " ( " , " error_bind " : " ) " ;
if ( error_bind )
error_bind - > writeJsonOutput ( output , { } , { } ) ;
output < < R " ( " , " error_relax " : " ) " ;
if ( error_relax )
error_relax - > writeJsonOutput ( output , { } , { } ) ;
output < < R " ( " } ) " ;
if ( next ( it ) ! = constraints . end ( ) )
output < < ' , ' ;
output < < endl ;
}
output < < " ]} " < < endl ;
}