diff --git a/others/C/dynare_driver.h b/others/C/dynare_driver.h deleted file mode 100644 index 14588c2cdf7a5249a8491df6c5f9cae68a1ca6e0..0000000000000000000000000000000000000000 --- a/others/C/dynare_driver.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2014 DynareTeam - * - * This 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. - * - * This code 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. - * - * More information is available at <http://www.gnu.org/licenses/>. - */ - -#ifndef _DYNARE_C_DRIVER_H -#define _DYNARE_C_DRIVER_H - -struct aux_vars_t -{ - int endo_index, type, orig_index, orig_lead_lag; -}; - -#endif // ! _DYNARE_C_DRIVER_H diff --git a/others/cpp/dynare_cpp_driver.cc b/others/cpp/dynare_cpp_driver.cc deleted file mode 100644 index 2beec52600a7bfd0d8130e736aebc81fe61165f0..0000000000000000000000000000000000000000 --- a/others/cpp/dynare_cpp_driver.cc +++ /dev/null @@ -1,414 +0,0 @@ -/* - * Copyright (C) 2011-2012 Houtan Bastani, Daniel Waggoner, Tao Zha - * - * This 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. - * - * This code 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. - * - * More information is available at <http://www.gnu.org/licenses/>. - */ - -#include <cstdlib> -#include <vector> -#include <string> -#include <iostream> -#include <assert.h> - -using namespace std; - -#include "dynare_cpp_driver.hh" - -DynareInfo::DynareInfo(map<string, int > exo_names_arg, - map<string, int > exo_det_names_arg, - map<string, int > endo_names_arg, - map<string, int > param_names_arg, - vector< double > params_arg, - vector<aux_vars_t> aux_vars_arg, - vector<int> predetermined_variables_arg, - vector<int> varobs_arg, - vector<int> NNZDerivatives_arg) : - NNZDerivatives(NNZDerivatives_arg) -{ - endo_nbr = endo_names.size(); - exo_nbr = exo_names.size(); - exo_det_nbr = exo_det_names.size(); - param_nbr = param_names.size(); - - exo_names = exo_names_arg; - exo_det_names = exo_det_names_arg; - endo_names = endo_names_arg; - param_names = param_names_arg; - params = params_arg; - std::cout << params_arg[0] << std::endl; - std::cout << params[0] << std::endl; - aux_vars = aux_vars_arg; - predetermined_variables = predetermined_variables_arg; -} - -DynareInfo::~DynareInfo() -{ - for (vector<MarkovSwitching *>::iterator it = markov_switching_vector.begin(); - it < markov_switching_vector.end(); it++) - delete *it; - - for (vector<ModFilePrior *>::iterator it = prior_vector.begin(); - it < prior_vector.end(); it++) - delete *it; - - for (vector<ModFileStructuralInnovationPrior *>::iterator it = structural_innovation_prior_vector.begin(); - it < structural_innovation_prior_vector.end(); it++) - delete *it; - - for (vector<ModFileMeasurementErrorPrior *>::iterator it = measurement_error_prior_vector.begin(); - it < measurement_error_prior_vector.end(); it++) - delete *it; - - for (vector<ModFileStructuralInnovationCorrPrior *>::iterator it = structural_innovation_corr_prior_vector.begin(); - it < structural_innovation_corr_prior_vector.end(); it++) - delete *it; - - for (vector<ModFileMeasurementErrorCorrPrior *>::iterator it = measurement_error_corr_prior_vector.begin(); - it < measurement_error_corr_prior_vector.end(); it++) - delete *it; - - markov_switching_vector.clear(); - prior_vector.clear(); - structural_innovation_prior_vector.clear(); - measurement_error_prior_vector.clear(); - structural_innovation_corr_prior_vector.clear(); - measurement_error_corr_prior_vector.clear(); - exo_names.clear(); - exo_det_names.clear(); - endo_names.clear(); - param_names.clear(); - params.clear(); - aux_vars.clear(); - predetermined_variables.clear(); - varobs.clear(); - NNZDerivatives.clear(); -} - -string -DynareInfo::get_exo_name_by_index(int index) throw (ValueNotSetException) -{ - for (map<string, int >::iterator it = exo_names.begin(); - it != exo_names.end(); it++) - if (it->second == index) - return it->first; - throw ValueNotSetException("get_exo_name_by_index" + index); -} - -int -DynareInfo::get_exo_index_by_name(string name) throw (ValueNotSetException) -{ - map<string, int >::iterator it = exo_names.find(name); - if (it != exo_names.end()) - return it->second; - throw ValueNotSetException("get_exo_name_by_name" + name); -} - -string -DynareInfo::get_exo_det_name_by_index(int index) throw (ValueNotSetException) -{ - for (map<string, int >::iterator it = exo_det_names.begin(); - it != exo_det_names.end(); it++) - if (it->second == index) - return it->first; - throw ValueNotSetException("get_exo_det_name_by_index" + index); -} - -int -DynareInfo::get_exo_det_index_by_name(string name) throw (ValueNotSetException) -{ - map<string, int >::iterator it = exo_det_names.find(name); - if (it != exo_det_names.end()) - return it->second; - throw ValueNotSetException("get_exo_det_name_by_name" + name); -} - -string -DynareInfo::get_endo_name_by_index(int index) throw (ValueNotSetException) -{ - for (map<string, int >::iterator it = endo_names.begin(); - it != endo_names.end(); it++) - if (it->second == index) - return it->first; - throw ValueNotSetException("get_endo_name_by_index" + index); -} - -int -DynareInfo::get_endo_index_by_name(string name) throw (ValueNotSetException) -{ - map<string, int >::iterator it = endo_names.find(name); - if (it != endo_names.end()) - return it->second; - throw ValueNotSetException("get_endo_name_by_name" + name); -} - -string -DynareInfo::get_param_name_by_index(int index) throw (ValueNotSetException) -{ - for (map<string, int >::iterator it = param_names.begin(); - it != param_names.end(); it++) - if (it->second == index) - return it->first; - throw ValueNotSetException("get_param_name_by_index" + index); -} - -int -DynareInfo::get_param_index_by_name(string name) throw (ValueNotSetException) -{ - map<string, int >::iterator it = param_names.find(name); - if (it != param_names.end()) - return it->second; - throw ValueNotSetException("get_param_name_by_name" + name); -} - -double -DynareInfo::get_param_value_by_index(int index) throw (ValueNotSetException) -{ - return params[index]; - // map<int, double >::iterator it = params.find(index); - // if (it != params.end()) - // return it->second; - // throw ValueNotSetException("get_param_value_by_index" + index); -} - -MarkovSwitching::MarkovSwitching(const int chain_arg, - const int number_of_regimes_arg, - const int number_of_lags_arg, - const bool number_of_lags_was_passed_arg, - const vector<int> parameters_arg, - const vector<double> duration_arg, - const restriction_map_t restriction_map_arg) : - chain(chain_arg), - number_of_regimes(number_of_regimes_arg), - number_of_lags(number_of_lags_arg), - number_of_lags_was_passed(number_of_lags_was_passed_arg), - parameters(parameters_arg), - duration(duration_arg), - restriction_map(restriction_map_arg) -{ - assert(chain >= 1); - assert(number_of_regimes > 0); - if (number_of_lags_was_passed) - assert(number_of_lags > 0); - assert(!parameters.empty()); - assert(!duration.empty()); -} - -int -MarkovSwitching::get_number_of_lags() throw (ValueNotSetException) -{ - if (number_of_lags_has_val()) - return number_of_lags; - throw ValueNotSetException("number_of_lags"); -} - -restriction_map_t -MarkovSwitching::get_restriction_map() throw (ValueNotSetException) -{ - if (restriction_map_has_val()) - return restriction_map; - throw ValueNotSetException("restriction_map"); -} - -BasicModFilePrior::BasicModFilePrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double mode_arg, - const double stdev_arg, - const double variance_arg, - const vector <double> domain_arg) : - index(index_arg), - shape(shape_arg), - mean(mean_arg), - mode(mode_arg), - stdev(stdev_arg), - variance(variance_arg), - domain(domain_arg) -{ - assert(index >= 0); - assert(!shape.empty()); - if (stdev_has_val()) - assert(stdev >= 0); - if (variance_has_val()) - assert(variance >= 0); - if (domain_has_val()) - assert(domain.size() == 2); -} - -double -BasicModFilePrior::get_mean() throw (ValueNotSetException) -{ - if (mean_has_val()) - return mean; - throw ValueNotSetException("mean"); -}; - -double -BasicModFilePrior::get_mode() throw (ValueNotSetException) -{ - if (mode_has_val()) - return mode; - throw ValueNotSetException("mode"); -}; - -double -BasicModFilePrior::get_stdev() throw (ValueNotSetException) -{ - if (stdev_has_val()) - return stdev; - throw ValueNotSetException("stdev"); -}; - -double -BasicModFilePrior::get_variance() throw (ValueNotSetException) -{ - if (variance_has_val()) - return variance; - throw ValueNotSetException("variance"); -}; - -vector<double> -BasicModFilePrior::get_domain() throw (ValueNotSetException) -{ - if (domain_has_val()) - return domain; - throw ValueNotSetException("domain"); -}; - -ModFilePrior::ModFilePrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double mode_arg, - const double stdev_arg, - const double variance_arg, - const vector <double> domain_arg) : - BasicModFilePrior(index_arg, - shape_arg, - mean_arg, - mode_arg, - stdev_arg, - variance_arg, - domain_arg) -{ -} - -ModFileStructuralInnovationPrior::ModFileStructuralInnovationPrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg) : - BasicModFilePrior(index_arg, - shape_arg, - mean_arg, - mode_arg, - stdev_arg, - variance_arg, - domain_arg) -{ -} - -ModFileMeasurementErrorPrior::ModFileMeasurementErrorPrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg) : - BasicModFilePrior(index_arg, - shape_arg, - mean_arg, - mode_arg, - stdev_arg, - variance_arg, - domain_arg) -{ -} - -ModFileStructuralInnovationCorrPrior::ModFileStructuralInnovationCorrPrior(const int index1_arg, - const int index2_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg) : - BasicModFilePrior(index1_arg, - shape_arg, - mean_arg, - mode_arg, - stdev_arg, - variance_arg, - domain_arg), - index2(index2_arg) -{ - assert(index2 >= 0); -} - -ModFileMeasurementErrorCorrPrior::ModFileMeasurementErrorCorrPrior(const int index1_arg, - const int index2_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg) : - BasicModFilePrior(index1_arg, - shape_arg, - mean_arg, - mode_arg, - stdev_arg, - variance_arg, - domain_arg), - index2(index2_arg) -{ - assert(index2 >= 0); -} - -BasicModFileOption::BasicModFileOption(const int index_arg, - const double init_arg) : - index(index_arg), - init(init_arg) -{ - assert(index >= 0); - assert(!isnan(init)); -} - -ModFileOption::ModFileOption(const int index_arg, const double init_arg) : - BasicModFileOption(index_arg, init_arg) -{ -} - -ModFileStructuralInnovationOption::ModFileStructuralInnovationOption(const int index_arg, const double init_arg) : - BasicModFileOption(index_arg, init_arg) -{ -} - -ModFileMeasurementErrorOption::ModFileMeasurementErrorOption(const int index_arg, const double init_arg) : - BasicModFileOption(index_arg, init_arg) -{ -} - -ModFileStructuralInnovationCorrOption::ModFileStructuralInnovationCorrOption(const int index1_arg, const int index2_arg, const double init_arg) : - BasicModFileOption(index1_arg, init_arg), - index2(index2_arg) -{ - assert(index2 >= 0); -} - -ModFileMeasurementErrorCorrOption::ModFileMeasurementErrorCorrOption(const int index1_arg, const int index2_arg, const double init_arg) : - BasicModFileOption(index1_arg, init_arg), - index2(index2_arg) -{ - assert(index2 >= 0); -} diff --git a/others/cpp/dynare_cpp_driver.hh b/others/cpp/dynare_cpp_driver.hh deleted file mode 100644 index afdbc21a2ffa8d23d53e45a69981171f19692cd3..0000000000000000000000000000000000000000 --- a/others/cpp/dynare_cpp_driver.hh +++ /dev/null @@ -1,605 +0,0 @@ -/* - * Copyright (C) 2011-2012 Houtan Bastani, Daniel Waggoner, Tao Zha - * - * This 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. - * - * This code 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. - * - * More information is available at <http://www.gnu.org/licenses/>. - */ - -#ifndef _DYNARE_CPP_DRIVER_HH -#define _DYNARE_CPP_DRIVER_HH - -#include <cstdlib> -#include <vector> -#include <string> -#include <map> -#include <limits> - -using namespace std; - -struct aux_vars_t -{ - int endo_index, type, orig_index, orig_lead_lag; -}; - -typedef map<pair<int, int >, double> restriction_map_t; - -class ValueNotSetException -{ -public: - string name; - ValueNotSetException(const string &name_arg) : name(name_arg) - { - } -}; - -class MarkovSwitching -{ -private: - const int chain, number_of_regimes, number_of_lags; - const bool number_of_lags_was_passed; - const vector<int> parameters; - const vector<double> duration; - const restriction_map_t restriction_map; -public: - MarkovSwitching(const int chain_arg, - const int number_of_regimes_arg, - const int number_of_lags_arg, - const bool number_of_lags_was_passed_arg, - const vector<int> parameters_arg, - const vector<double> duration_arg, - const restriction_map_t restriction_map_arg); - - inline bool - number_of_lags_has_val() const - { - return number_of_lags_was_passed; - }; - inline bool - restriction_map_has_val() const - { - return !restriction_map.empty(); - }; - - inline int - get_chain() const - { - return chain; - }; - inline int - get_number_of_regimes() const - { - return number_of_regimes; - }; - int get_number_of_lags() throw (ValueNotSetException); - inline vector<int> - get_parameters() - { - return parameters; - }; - inline vector<double> - get_duration() - { - return duration; - }; - restriction_map_t get_restriction_map() throw (ValueNotSetException); -}; - -class BasicModFilePrior -{ -private: - inline bool - isnan(double x) const - { - return (x != x); - }; -protected: - const int index; - const string shape; - const double mean, mode, stdev, variance; - const vector <double> domain; - - BasicModFilePrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double mode_arg, - const double stdev_arg, - const double variance_arg, - const vector <double> domain_arg); -public: - inline bool - mean_has_val() const - { - return !isnan(mean); - }; - inline bool - mode_has_val() const - { - return !isnan(mode); - }; - inline bool - stdev_has_val() const - { - return !isnan(stdev); - }; - inline bool - variance_has_val() const - { - return !isnan(variance); - }; - inline bool - domain_has_val() const - { - return (domain.size() == 2); - }; - - inline int - get_index() const - { - return index; - }; - inline string - get_shape() const - { - return shape; - }; - double get_mean() throw (ValueNotSetException); - double get_mode() throw (ValueNotSetException); - double get_stdev() throw (ValueNotSetException); - double get_variance() throw (ValueNotSetException); - vector<double> get_domain() throw (ValueNotSetException); -}; - -class ModFilePrior : public BasicModFilePrior -{ -public: - ModFilePrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double mode_arg, - const double stdev_arg, - const double variance_arg, - const vector <double> domain_arg); -}; - -class ModFileStructuralInnovationPrior : public BasicModFilePrior -{ -public: - ModFileStructuralInnovationPrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double mode_arg, - const double stdev_arg, - const double variance_arg, - const vector <double> domain_arg); -}; - -class ModFileMeasurementErrorPrior : public BasicModFilePrior -{ -public: - ModFileMeasurementErrorPrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg); -}; - -class ModFileStructuralInnovationCorrPrior : public BasicModFilePrior -{ -private: - const int index2; -public: - ModFileStructuralInnovationCorrPrior(const int index1_arg, - const int index2_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg); -}; - -class ModFileMeasurementErrorCorrPrior : public BasicModFilePrior -{ -private: - const int index2; -public: - ModFileMeasurementErrorCorrPrior(const int index1_arg, - const int index2_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg); -}; - -class BasicModFileOption -{ -private: - inline bool - isnan(double x) const - { - return (x != x); - }; -protected: - const int index; - const double init; - - BasicModFileOption(const int index_arg, - const double init_arg); -public: - inline int - get_index() const - { - return index; - }; - inline double - get_init() const - { - return init; - }; -}; - -class ModFileOption : public BasicModFileOption -{ -public: - ModFileOption(const int index_arg, - const double init_arg); -}; - -class ModFileStructuralInnovationOption : public BasicModFileOption -{ -public: - ModFileStructuralInnovationOption(const int index_arg, - const double init_arg); -}; - -class ModFileMeasurementErrorOption : public BasicModFileOption -{ -public: - ModFileMeasurementErrorOption(const int index_arg, - const double init_arg); -}; - -class ModFileStructuralInnovationCorrOption : public BasicModFileOption -{ -private: - const int index2; -public: - ModFileStructuralInnovationCorrOption(const int index1_arg, - const int index2_arg, - const double init_arg); -}; - -class ModFileMeasurementErrorCorrOption : public BasicModFileOption -{ -private: - const int index2; -public: - ModFileMeasurementErrorCorrOption(const int index1_arg, - const int index2_arg, - const double init_arg); -}; - -class DynareInfo -{ -private: - vector<MarkovSwitching *> markov_switching_vector; - vector<ModFilePrior *> prior_vector; - vector<ModFileStructuralInnovationPrior *> structural_innovation_prior_vector; - vector<ModFileMeasurementErrorPrior *> measurement_error_prior_vector; - vector<ModFileStructuralInnovationCorrPrior *> structural_innovation_corr_prior_vector; - vector<ModFileMeasurementErrorCorrPrior *> measurement_error_corr_prior_vector; - vector<ModFileOption *> option_vector; - vector<ModFileStructuralInnovationOption *> structural_innovation_option_vector; - vector<ModFileMeasurementErrorOption *> measurement_error_option_vector; - vector<ModFileStructuralInnovationCorrOption *> structural_innovation_corr_option_vector; - vector<ModFileMeasurementErrorCorrOption *> measurement_error_corr_option_vector; - map<string, int > exo_names, exo_det_names, endo_names, param_names; - vector< double > params; - vector<aux_vars_t> aux_vars; - vector<int> predetermined_variables; - vector<int> varobs; - vector<size_t> zeta_fwrd, zeta_back, zeta_mixed, zeta_static; - vector<int> NNZDerivatives; - int endo_nbr, exo_nbr, exo_det_nbr, param_nbr, nstatic, nfwrd, nback, nmixed; -public: - DynareInfo(void); // this function is automatically written by the Dynare preprocessor - DynareInfo(map<string, int > exo_names_arg, - map<string, int > exo_det_names_arg, - map<string, int > endo_names_arg, - map<string, int > param_names_arg, - vector< double > params_arg, - vector<aux_vars_t> aux_vars_arg, - vector<int> predetermined_variables_arg, - vector<int> varobs_arg, - vector<int> NNZDerivatives_arg); - - inline void - addMarkovSwitching(MarkovSwitching *ms) - { - markov_switching_vector.push_back(ms); - }; - - inline void - addPrior(ModFilePrior *p) - { - prior_vector.push_back(p); - }; - inline void - addStructuralInnovationPrior(ModFileStructuralInnovationPrior *sip) - { - structural_innovation_prior_vector.push_back(sip); - }; - inline void - addMeasurementErrorPrior(ModFileMeasurementErrorPrior *mep) - { - measurement_error_prior_vector.push_back(mep); - }; - inline void - addStructuralInnovationCorrPrior(ModFileStructuralInnovationCorrPrior *sicp) - { - structural_innovation_corr_prior_vector.push_back(sicp); - }; - inline void - addMeasurementErrorCorrPrior(ModFileMeasurementErrorCorrPrior *mecp) - { - measurement_error_corr_prior_vector.push_back(mecp); - }; - - inline void - addOption(ModFileOption *o) - { - option_vector.push_back(o); - }; - inline void - addStructuralInnovationOption(ModFileStructuralInnovationOption *sio) - { - structural_innovation_option_vector.push_back(sio); - }; - inline void - addMeasurementErrorOption(ModFileMeasurementErrorOption *meo) - { - measurement_error_option_vector.push_back(meo); - }; - inline void - addStructuralInnovationCorrOption(ModFileStructuralInnovationCorrOption *sico) - { - structural_innovation_corr_option_vector.push_back(sico); - }; - inline void - addMeasurementErrorCorrOption(ModFileMeasurementErrorCorrOption *meco) - { - measurement_error_corr_option_vector.push_back(meco); - }; - - inline bool - markov_switching_has_val() - { - return !markov_switching_vector.empty(); - }; - inline bool - prior_has_val() - { - return !prior_vector.empty(); - }; - inline bool - structural_innovation_prior_has_val() - { - return !structural_innovation_prior_vector.empty(); - }; - inline bool - measurement_error_prior_has_val() - { - return !measurement_error_prior_vector.empty(); - }; - inline bool - structural_innovation_corr_prior_has_val() - { - return !structural_innovation_corr_prior_vector.empty(); - }; - inline bool - measurement_error_corr_prior_has_val() - { - return !measurement_error_corr_prior_vector.empty(); - }; - - inline bool - option_has_val() - { - return !option_vector.empty(); - }; - inline bool - structural_innovation_option_has_val() - { - return !structural_innovation_option_vector.empty(); - }; - inline bool - measurement_error_option_has_val() - { - return !measurement_error_option_vector.empty(); - }; - inline bool - structural_innovation_corr_option_has_val() - { - return !structural_innovation_corr_option_vector.empty(); - }; - inline bool - measurement_error_corr_option_has_val() - { - return !measurement_error_corr_option_vector.empty(); - }; - - inline vector<MarkovSwitching *> - get_markov_switching() - { - return markov_switching_vector; - }; - inline vector<ModFilePrior *> - get_prior() - { - return prior_vector; - }; - inline vector<ModFileStructuralInnovationPrior *> - get_structural_innovation_prior() - { - return structural_innovation_prior_vector; - }; - inline vector<ModFileMeasurementErrorPrior *> - get_measurement_error_prior() - { - return measurement_error_prior_vector; - }; - inline vector<ModFileStructuralInnovationCorrPrior *> - get_structural_innovation_corr_prior() - { - return structural_innovation_corr_prior_vector; - }; - inline vector<ModFileMeasurementErrorCorrPrior *> - get_measurement_error_corr_prior() - { - return measurement_error_corr_prior_vector; - }; - - inline vector<ModFileOption *> - get_option() - { - return option_vector; - }; - inline vector<ModFileStructuralInnovationOption *> - get_structural_innovation_option() - { - return structural_innovation_option_vector; - }; - inline vector<ModFileMeasurementErrorOption *> - get_measurement_error_option() - { - return measurement_error_option_vector; - }; - inline vector<ModFileStructuralInnovationCorrOption *> - get_structural_innovation_corr_option() - { - return structural_innovation_corr_option_vector; - }; - inline vector<ModFileMeasurementErrorCorrOption *> - get_measurement_error_corr_option() - { - return measurement_error_corr_option_vector; - }; - - inline map<string, int > - get_exo_names() - { - return exo_names; - }; - inline map<string, int > - get_exo_det_names() - { - return exo_det_names; - }; - inline map<string, int > - get_endo_names() - { - return endo_names; - }; - inline map<string, int > - get_param_names() - { - return param_names; - }; - inline vector<double> - get_params() - { - return params; - }; - inline double * - get_params_data(void) - { - return params.data(); - }; - inline vector <aux_vars_t> - get_aux_vars() - { - return aux_vars; - }; - inline vector <int> - get_predetermined_variables() - { - return predetermined_variables; - }; - inline vector <int> - get_varobs() - { - return varobs; - }; - inline vector<int> - get_NNZDerivatives() - { - return NNZDerivatives; - }; - - inline int - get_endo_nbr(void) - { - return endo_nbr; - }; - inline int - get_exo_nbr(void) - { - return exo_nbr; - }; - inline int - get_exo_det_nbr(void) - { - return exo_det_nbr; - }; - inline int - get_param_nbr(void) - { - return param_nbr; - }; - inline vector<size_t> - get_zeta_back(void) - { - return zeta_back; - }; - inline vector<size_t> - get_zeta_fwrd(void) - { - return zeta_fwrd; - }; - inline vector<size_t> - get_zeta_mixed(void) - { - return zeta_mixed; - }; - inline vector<size_t> - get_zeta_static(void) - { - return zeta_static; - }; - - string get_exo_name_by_index(int index) throw (ValueNotSetException); - int get_exo_index_by_name(string name) throw (ValueNotSetException); - string get_exo_det_name_by_index(int index) throw (ValueNotSetException); - int get_exo_det_index_by_name(string name) throw (ValueNotSetException); - string get_endo_name_by_index(int index) throw (ValueNotSetException); - int get_endo_index_by_name(string name) throw (ValueNotSetException); - string get_param_name_by_index(int index) throw (ValueNotSetException); - int get_param_index_by_name(string name) throw (ValueNotSetException); - double get_param_value_by_index(int index) throw (ValueNotSetException); - -}; - -#endif // ! _DYNARE_CPP_DRIVER_HH diff --git a/others/cpp/dynare_driver.c b/others/cpp/dynare_driver.c deleted file mode 100644 index 2beec52600a7bfd0d8130e736aebc81fe61165f0..0000000000000000000000000000000000000000 --- a/others/cpp/dynare_driver.c +++ /dev/null @@ -1,414 +0,0 @@ -/* - * Copyright (C) 2011-2012 Houtan Bastani, Daniel Waggoner, Tao Zha - * - * This 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. - * - * This code 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. - * - * More information is available at <http://www.gnu.org/licenses/>. - */ - -#include <cstdlib> -#include <vector> -#include <string> -#include <iostream> -#include <assert.h> - -using namespace std; - -#include "dynare_cpp_driver.hh" - -DynareInfo::DynareInfo(map<string, int > exo_names_arg, - map<string, int > exo_det_names_arg, - map<string, int > endo_names_arg, - map<string, int > param_names_arg, - vector< double > params_arg, - vector<aux_vars_t> aux_vars_arg, - vector<int> predetermined_variables_arg, - vector<int> varobs_arg, - vector<int> NNZDerivatives_arg) : - NNZDerivatives(NNZDerivatives_arg) -{ - endo_nbr = endo_names.size(); - exo_nbr = exo_names.size(); - exo_det_nbr = exo_det_names.size(); - param_nbr = param_names.size(); - - exo_names = exo_names_arg; - exo_det_names = exo_det_names_arg; - endo_names = endo_names_arg; - param_names = param_names_arg; - params = params_arg; - std::cout << params_arg[0] << std::endl; - std::cout << params[0] << std::endl; - aux_vars = aux_vars_arg; - predetermined_variables = predetermined_variables_arg; -} - -DynareInfo::~DynareInfo() -{ - for (vector<MarkovSwitching *>::iterator it = markov_switching_vector.begin(); - it < markov_switching_vector.end(); it++) - delete *it; - - for (vector<ModFilePrior *>::iterator it = prior_vector.begin(); - it < prior_vector.end(); it++) - delete *it; - - for (vector<ModFileStructuralInnovationPrior *>::iterator it = structural_innovation_prior_vector.begin(); - it < structural_innovation_prior_vector.end(); it++) - delete *it; - - for (vector<ModFileMeasurementErrorPrior *>::iterator it = measurement_error_prior_vector.begin(); - it < measurement_error_prior_vector.end(); it++) - delete *it; - - for (vector<ModFileStructuralInnovationCorrPrior *>::iterator it = structural_innovation_corr_prior_vector.begin(); - it < structural_innovation_corr_prior_vector.end(); it++) - delete *it; - - for (vector<ModFileMeasurementErrorCorrPrior *>::iterator it = measurement_error_corr_prior_vector.begin(); - it < measurement_error_corr_prior_vector.end(); it++) - delete *it; - - markov_switching_vector.clear(); - prior_vector.clear(); - structural_innovation_prior_vector.clear(); - measurement_error_prior_vector.clear(); - structural_innovation_corr_prior_vector.clear(); - measurement_error_corr_prior_vector.clear(); - exo_names.clear(); - exo_det_names.clear(); - endo_names.clear(); - param_names.clear(); - params.clear(); - aux_vars.clear(); - predetermined_variables.clear(); - varobs.clear(); - NNZDerivatives.clear(); -} - -string -DynareInfo::get_exo_name_by_index(int index) throw (ValueNotSetException) -{ - for (map<string, int >::iterator it = exo_names.begin(); - it != exo_names.end(); it++) - if (it->second == index) - return it->first; - throw ValueNotSetException("get_exo_name_by_index" + index); -} - -int -DynareInfo::get_exo_index_by_name(string name) throw (ValueNotSetException) -{ - map<string, int >::iterator it = exo_names.find(name); - if (it != exo_names.end()) - return it->second; - throw ValueNotSetException("get_exo_name_by_name" + name); -} - -string -DynareInfo::get_exo_det_name_by_index(int index) throw (ValueNotSetException) -{ - for (map<string, int >::iterator it = exo_det_names.begin(); - it != exo_det_names.end(); it++) - if (it->second == index) - return it->first; - throw ValueNotSetException("get_exo_det_name_by_index" + index); -} - -int -DynareInfo::get_exo_det_index_by_name(string name) throw (ValueNotSetException) -{ - map<string, int >::iterator it = exo_det_names.find(name); - if (it != exo_det_names.end()) - return it->second; - throw ValueNotSetException("get_exo_det_name_by_name" + name); -} - -string -DynareInfo::get_endo_name_by_index(int index) throw (ValueNotSetException) -{ - for (map<string, int >::iterator it = endo_names.begin(); - it != endo_names.end(); it++) - if (it->second == index) - return it->first; - throw ValueNotSetException("get_endo_name_by_index" + index); -} - -int -DynareInfo::get_endo_index_by_name(string name) throw (ValueNotSetException) -{ - map<string, int >::iterator it = endo_names.find(name); - if (it != endo_names.end()) - return it->second; - throw ValueNotSetException("get_endo_name_by_name" + name); -} - -string -DynareInfo::get_param_name_by_index(int index) throw (ValueNotSetException) -{ - for (map<string, int >::iterator it = param_names.begin(); - it != param_names.end(); it++) - if (it->second == index) - return it->first; - throw ValueNotSetException("get_param_name_by_index" + index); -} - -int -DynareInfo::get_param_index_by_name(string name) throw (ValueNotSetException) -{ - map<string, int >::iterator it = param_names.find(name); - if (it != param_names.end()) - return it->second; - throw ValueNotSetException("get_param_name_by_name" + name); -} - -double -DynareInfo::get_param_value_by_index(int index) throw (ValueNotSetException) -{ - return params[index]; - // map<int, double >::iterator it = params.find(index); - // if (it != params.end()) - // return it->second; - // throw ValueNotSetException("get_param_value_by_index" + index); -} - -MarkovSwitching::MarkovSwitching(const int chain_arg, - const int number_of_regimes_arg, - const int number_of_lags_arg, - const bool number_of_lags_was_passed_arg, - const vector<int> parameters_arg, - const vector<double> duration_arg, - const restriction_map_t restriction_map_arg) : - chain(chain_arg), - number_of_regimes(number_of_regimes_arg), - number_of_lags(number_of_lags_arg), - number_of_lags_was_passed(number_of_lags_was_passed_arg), - parameters(parameters_arg), - duration(duration_arg), - restriction_map(restriction_map_arg) -{ - assert(chain >= 1); - assert(number_of_regimes > 0); - if (number_of_lags_was_passed) - assert(number_of_lags > 0); - assert(!parameters.empty()); - assert(!duration.empty()); -} - -int -MarkovSwitching::get_number_of_lags() throw (ValueNotSetException) -{ - if (number_of_lags_has_val()) - return number_of_lags; - throw ValueNotSetException("number_of_lags"); -} - -restriction_map_t -MarkovSwitching::get_restriction_map() throw (ValueNotSetException) -{ - if (restriction_map_has_val()) - return restriction_map; - throw ValueNotSetException("restriction_map"); -} - -BasicModFilePrior::BasicModFilePrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double mode_arg, - const double stdev_arg, - const double variance_arg, - const vector <double> domain_arg) : - index(index_arg), - shape(shape_arg), - mean(mean_arg), - mode(mode_arg), - stdev(stdev_arg), - variance(variance_arg), - domain(domain_arg) -{ - assert(index >= 0); - assert(!shape.empty()); - if (stdev_has_val()) - assert(stdev >= 0); - if (variance_has_val()) - assert(variance >= 0); - if (domain_has_val()) - assert(domain.size() == 2); -} - -double -BasicModFilePrior::get_mean() throw (ValueNotSetException) -{ - if (mean_has_val()) - return mean; - throw ValueNotSetException("mean"); -}; - -double -BasicModFilePrior::get_mode() throw (ValueNotSetException) -{ - if (mode_has_val()) - return mode; - throw ValueNotSetException("mode"); -}; - -double -BasicModFilePrior::get_stdev() throw (ValueNotSetException) -{ - if (stdev_has_val()) - return stdev; - throw ValueNotSetException("stdev"); -}; - -double -BasicModFilePrior::get_variance() throw (ValueNotSetException) -{ - if (variance_has_val()) - return variance; - throw ValueNotSetException("variance"); -}; - -vector<double> -BasicModFilePrior::get_domain() throw (ValueNotSetException) -{ - if (domain_has_val()) - return domain; - throw ValueNotSetException("domain"); -}; - -ModFilePrior::ModFilePrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double mode_arg, - const double stdev_arg, - const double variance_arg, - const vector <double> domain_arg) : - BasicModFilePrior(index_arg, - shape_arg, - mean_arg, - mode_arg, - stdev_arg, - variance_arg, - domain_arg) -{ -} - -ModFileStructuralInnovationPrior::ModFileStructuralInnovationPrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg) : - BasicModFilePrior(index_arg, - shape_arg, - mean_arg, - mode_arg, - stdev_arg, - variance_arg, - domain_arg) -{ -} - -ModFileMeasurementErrorPrior::ModFileMeasurementErrorPrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg) : - BasicModFilePrior(index_arg, - shape_arg, - mean_arg, - mode_arg, - stdev_arg, - variance_arg, - domain_arg) -{ -} - -ModFileStructuralInnovationCorrPrior::ModFileStructuralInnovationCorrPrior(const int index1_arg, - const int index2_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg) : - BasicModFilePrior(index1_arg, - shape_arg, - mean_arg, - mode_arg, - stdev_arg, - variance_arg, - domain_arg), - index2(index2_arg) -{ - assert(index2 >= 0); -} - -ModFileMeasurementErrorCorrPrior::ModFileMeasurementErrorCorrPrior(const int index1_arg, - const int index2_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg) : - BasicModFilePrior(index1_arg, - shape_arg, - mean_arg, - mode_arg, - stdev_arg, - variance_arg, - domain_arg), - index2(index2_arg) -{ - assert(index2 >= 0); -} - -BasicModFileOption::BasicModFileOption(const int index_arg, - const double init_arg) : - index(index_arg), - init(init_arg) -{ - assert(index >= 0); - assert(!isnan(init)); -} - -ModFileOption::ModFileOption(const int index_arg, const double init_arg) : - BasicModFileOption(index_arg, init_arg) -{ -} - -ModFileStructuralInnovationOption::ModFileStructuralInnovationOption(const int index_arg, const double init_arg) : - BasicModFileOption(index_arg, init_arg) -{ -} - -ModFileMeasurementErrorOption::ModFileMeasurementErrorOption(const int index_arg, const double init_arg) : - BasicModFileOption(index_arg, init_arg) -{ -} - -ModFileStructuralInnovationCorrOption::ModFileStructuralInnovationCorrOption(const int index1_arg, const int index2_arg, const double init_arg) : - BasicModFileOption(index1_arg, init_arg), - index2(index2_arg) -{ - assert(index2 >= 0); -} - -ModFileMeasurementErrorCorrOption::ModFileMeasurementErrorCorrOption(const int index1_arg, const int index2_arg, const double init_arg) : - BasicModFileOption(index1_arg, init_arg), - index2(index2_arg) -{ - assert(index2 >= 0); -} diff --git a/others/cpp/dynare_driver.h b/others/cpp/dynare_driver.h deleted file mode 100644 index 3dcb7acd9e0c94ff52943af5c8d24f9f79fd179f..0000000000000000000000000000000000000000 --- a/others/cpp/dynare_driver.h +++ /dev/null @@ -1,606 +0,0 @@ -/* - * Copyright (C) 2011-2012 Houtan Bastani, Daniel Waggoner, Tao Zha - * - * This 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. - * - * This code 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. - * - * More information is available at <http://www.gnu.org/licenses/>. - */ - -#ifndef _DYNARE_CPP_DRIVER_HH -#define _DYNARE_CPP_DRIVER_HH - -#include <cstdlib> -#include <vector> -#include <string> -#include <map> -#include <limits> - -using namespace std; - -struct aux_vars_t -{ - int endo_index, type, orig_index, orig_lead_lag; -}; - -typedef map<pair<int, int >, double> restriction_map_t; - -class ValueNotSetException -{ -public: - string name; - ValueNotSetException(const string &name_arg) : name(name_arg) - { - } -}; - -class MarkovSwitching -{ -private: - const int chain, number_of_regimes, number_of_lags; - const bool number_of_lags_was_passed; - const vector<int> parameters; - const vector<double> duration; - const restriction_map_t restriction_map; -public: - MarkovSwitching(const int chain_arg, - const int number_of_regimes_arg, - const int number_of_lags_arg, - const bool number_of_lags_was_passed_arg, - const vector<int> parameters_arg, - const vector<double> duration_arg, - const restriction_map_t restriction_map_arg); - - inline bool - number_of_lags_has_val() const - { - return number_of_lags_was_passed; - }; - inline bool - restriction_map_has_val() const - { - return !restriction_map.empty(); - }; - - inline int - get_chain() const - { - return chain; - }; - inline int - get_number_of_regimes() const - { - return number_of_regimes; - }; - int get_number_of_lags() throw (ValueNotSetException); - inline vector<int> - get_parameters() - { - return parameters; - }; - inline vector<double> - get_duration() - { - return duration; - }; - restriction_map_t get_restriction_map() throw (ValueNotSetException); -}; - -class BasicModFilePrior -{ -private: - inline bool - isnan(double x) const - { - return (x != x); - }; -protected: - const int index; - const string shape; - const double mean, mode, stdev, variance; - const vector <double> domain; - - BasicModFilePrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double mode_arg, - const double stdev_arg, - const double variance_arg, - const vector <double> domain_arg); -public: - inline bool - mean_has_val() const - { - return !isnan(mean); - }; - inline bool - mode_has_val() const - { - return !isnan(mode); - }; - inline bool - stdev_has_val() const - { - return !isnan(stdev); - }; - inline bool - variance_has_val() const - { - return !isnan(variance); - }; - inline bool - domain_has_val() const - { - return (domain.size() == 2); - }; - - inline int - get_index() const - { - return index; - }; - inline string - get_shape() const - { - return shape; - }; - double get_mean() throw (ValueNotSetException); - double get_mode() throw (ValueNotSetException); - double get_stdev() throw (ValueNotSetException); - double get_variance() throw (ValueNotSetException); - vector<double> get_domain() throw (ValueNotSetException); -}; - -class ModFilePrior : public BasicModFilePrior -{ -public: - ModFilePrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double mode_arg, - const double stdev_arg, - const double variance_arg, - const vector <double> domain_arg); -}; - -class ModFileStructuralInnovationPrior : public BasicModFilePrior -{ -public: - ModFileStructuralInnovationPrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double mode_arg, - const double stdev_arg, - const double variance_arg, - const vector <double> domain_arg); -}; - -class ModFileMeasurementErrorPrior : public BasicModFilePrior -{ -public: - ModFileMeasurementErrorPrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg); -}; - -class ModFileStructuralInnovationCorrPrior : public BasicModFilePrior -{ -private: - const int index2; -public: - ModFileStructuralInnovationCorrPrior(const int index1_arg, - const int index2_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg); -}; - -class ModFileMeasurementErrorCorrPrior : public BasicModFilePrior -{ -private: - const int index2; -public: - ModFileMeasurementErrorCorrPrior(const int index1_arg, - const int index2_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg); -}; - -class BasicModFileOption -{ -private: - inline bool - isnan(double x) const - { - return (x != x); - }; -protected: - const int index; - const double init; - - BasicModFileOption(const int index_arg, - const double init_arg); -public: - inline int - get_index() const - { - return index; - }; - inline double - get_init() const - { - return init; - }; -}; - -class ModFileOption : public BasicModFileOption -{ -public: - ModFileOption(const int index_arg, - const double init_arg); -}; - -class ModFileStructuralInnovationOption : public BasicModFileOption -{ -public: - ModFileStructuralInnovationOption(const int index_arg, - const double init_arg); -}; - -class ModFileMeasurementErrorOption : public BasicModFileOption -{ -public: - ModFileMeasurementErrorOption(const int index_arg, - const double init_arg); -}; - -class ModFileStructuralInnovationCorrOption : public BasicModFileOption -{ -private: - const int index2; -public: - ModFileStructuralInnovationCorrOption(const int index1_arg, - const int index2_arg, - const double init_arg); -}; - -class ModFileMeasurementErrorCorrOption : public BasicModFileOption -{ -private: - const int index2; -public: - ModFileMeasurementErrorCorrOption(const int index1_arg, - const int index2_arg, - const double init_arg); -}; - -class DynareInfo -{ -private: - vector<MarkovSwitching *> markov_switching_vector; - vector<ModFilePrior *> prior_vector; - vector<ModFileStructuralInnovationPrior *> structural_innovation_prior_vector; - vector<ModFileMeasurementErrorPrior *> measurement_error_prior_vector; - vector<ModFileStructuralInnovationCorrPrior *> structural_innovation_corr_prior_vector; - vector<ModFileMeasurementErrorCorrPrior *> measurement_error_corr_prior_vector; - vector<ModFileOption *> option_vector; - vector<ModFileStructuralInnovationOption *> structural_innovation_option_vector; - vector<ModFileMeasurementErrorOption *> measurement_error_option_vector; - vector<ModFileStructuralInnovationCorrOption *> structural_innovation_corr_option_vector; - vector<ModFileMeasurementErrorCorrOption *> measurement_error_corr_option_vector; - map<string, int > exo_names, exo_det_names, endo_names, param_names; - vector< double > params; - vector<aux_vars_t> aux_vars; - vector<int> predetermined_variables; - vector<int> varobs; - vector<size_t> zeta_fwrd, zeta_back, zeta_mixed, zeta_static; - vector<int> NNZDerivatives; - int endo_nbr, exo_nbr, exo_det_nbr, param_nbr, nstatic, nfwrd, nback, nmixed; -public: - DynareInfo(void); // this function is automatically written by the Dynare preprocessor - DynareInfo(map<string, int > exo_names_arg, - map<string, int > exo_det_names_arg, - map<string, int > endo_names_arg, - map<string, int > param_names_arg, - vector< double > params_arg, - vector<aux_vars_t> aux_vars_arg, - vector<int> predetermined_variables_arg, - vector<int> varobs_arg, - vector<int> NNZDerivatives_arg); - ~DynareInfo(); - - inline void - addMarkovSwitching(MarkovSwitching *ms) - { - markov_switching_vector.push_back(ms); - }; - - inline void - addPrior(ModFilePrior *p) - { - prior_vector.push_back(p); - }; - inline void - addStructuralInnovationPrior(ModFileStructuralInnovationPrior *sip) - { - structural_innovation_prior_vector.push_back(sip); - }; - inline void - addMeasurementErrorPrior(ModFileMeasurementErrorPrior *mep) - { - measurement_error_prior_vector.push_back(mep); - }; - inline void - addStructuralInnovationCorrPrior(ModFileStructuralInnovationCorrPrior *sicp) - { - structural_innovation_corr_prior_vector.push_back(sicp); - }; - inline void - addMeasurementErrorCorrPrior(ModFileMeasurementErrorCorrPrior *mecp) - { - measurement_error_corr_prior_vector.push_back(mecp); - }; - - inline void - addOption(ModFileOption *o) - { - option_vector.push_back(o); - }; - inline void - addStructuralInnovationOption(ModFileStructuralInnovationOption *sio) - { - structural_innovation_option_vector.push_back(sio); - }; - inline void - addMeasurementErrorOption(ModFileMeasurementErrorOption *meo) - { - measurement_error_option_vector.push_back(meo); - }; - inline void - addStructuralInnovationCorrOption(ModFileStructuralInnovationCorrOption *sico) - { - structural_innovation_corr_option_vector.push_back(sico); - }; - inline void - addMeasurementErrorCorrOption(ModFileMeasurementErrorCorrOption *meco) - { - measurement_error_corr_option_vector.push_back(meco); - }; - - inline bool - markov_switching_has_val() - { - return !markov_switching_vector.empty(); - }; - inline bool - prior_has_val() - { - return !prior_vector.empty(); - }; - inline bool - structural_innovation_prior_has_val() - { - return !structural_innovation_prior_vector.empty(); - }; - inline bool - measurement_error_prior_has_val() - { - return !measurement_error_prior_vector.empty(); - }; - inline bool - structural_innovation_corr_prior_has_val() - { - return !structural_innovation_corr_prior_vector.empty(); - }; - inline bool - measurement_error_corr_prior_has_val() - { - return !measurement_error_corr_prior_vector.empty(); - }; - - inline bool - option_has_val() - { - return !option_vector.empty(); - }; - inline bool - structural_innovation_option_has_val() - { - return !structural_innovation_option_vector.empty(); - }; - inline bool - measurement_error_option_has_val() - { - return !measurement_error_option_vector.empty(); - }; - inline bool - structural_innovation_corr_option_has_val() - { - return !structural_innovation_corr_option_vector.empty(); - }; - inline bool - measurement_error_corr_option_has_val() - { - return !measurement_error_corr_option_vector.empty(); - }; - - inline vector<MarkovSwitching *> - get_markov_switching() - { - return markov_switching_vector; - }; - inline vector<ModFilePrior *> - get_prior() - { - return prior_vector; - }; - inline vector<ModFileStructuralInnovationPrior *> - get_structural_innovation_prior() - { - return structural_innovation_prior_vector; - }; - inline vector<ModFileMeasurementErrorPrior *> - get_measurement_error_prior() - { - return measurement_error_prior_vector; - }; - inline vector<ModFileStructuralInnovationCorrPrior *> - get_structural_innovation_corr_prior() - { - return structural_innovation_corr_prior_vector; - }; - inline vector<ModFileMeasurementErrorCorrPrior *> - get_measurement_error_corr_prior() - { - return measurement_error_corr_prior_vector; - }; - - inline vector<ModFileOption *> - get_option() - { - return option_vector; - }; - inline vector<ModFileStructuralInnovationOption *> - get_structural_innovation_option() - { - return structural_innovation_option_vector; - }; - inline vector<ModFileMeasurementErrorOption *> - get_measurement_error_option() - { - return measurement_error_option_vector; - }; - inline vector<ModFileStructuralInnovationCorrOption *> - get_structural_innovation_corr_option() - { - return structural_innovation_corr_option_vector; - }; - inline vector<ModFileMeasurementErrorCorrOption *> - get_measurement_error_corr_option() - { - return measurement_error_corr_option_vector; - }; - - inline map<string, int > - get_exo_names() - { - return exo_names; - }; - inline map<string, int > - get_exo_det_names() - { - return exo_det_names; - }; - inline map<string, int > - get_endo_names() - { - return endo_names; - }; - inline map<string, int > - get_param_names() - { - return param_names; - }; - inline vector<double> - get_params() - { - return params; - }; - inline double * - get_params_data(void) - { - return params.data(); - }; - inline vector <aux_vars_t> - get_aux_vars() - { - return aux_vars; - }; - inline vector <int> - get_predetermined_variables() - { - return predetermined_variables; - }; - inline vector <int> - get_varobs() - { - return varobs; - }; - inline vector<int> - get_NNZDerivatives() - { - return NNZDerivatives; - }; - - inline int - get_endo_nbr(void) - { - return endo_nbr; - }; - inline int - get_exo_nbr(void) - { - return exo_nbr; - }; - inline int - get_exo_det_nbr(void) - { - return exo_det_nbr; - }; - inline int - get_param_nbr(void) - { - return param_nbr; - }; - inline vector<size_t> - get_zeta_back(void) - { - return zeta_back; - }; - inline vector<size_t> - get_zeta_fwrd(void) - { - return zeta_fwrd; - }; - inline vector<size_t> - get_zeta_mixed(void) - { - return zeta_mixed; - }; - inline vector<size_t> - get_zeta_static(void) - { - return zeta_static; - }; - - string get_exo_name_by_index(int index) throw (ValueNotSetException); - int get_exo_index_by_name(string name) throw (ValueNotSetException); - string get_exo_det_name_by_index(int index) throw (ValueNotSetException); - int get_exo_det_index_by_name(string name) throw (ValueNotSetException); - string get_endo_name_by_index(int index) throw (ValueNotSetException); - int get_endo_index_by_name(string name) throw (ValueNotSetException); - string get_param_name_by_index(int index) throw (ValueNotSetException); - int get_param_index_by_name(string name) throw (ValueNotSetException); - double get_param_value_by_index(int index) throw (ValueNotSetException); - -}; - -#endif // ! _DYNARE_CPP_DRIVER_HH diff --git a/others/cpp/ms_dsge_c_driver.cc b/others/cpp/ms_dsge_c_driver.cc deleted file mode 100644 index b1183a845505421ec184d2b588a8c574cbc82f0d..0000000000000000000000000000000000000000 --- a/others/cpp/ms_dsge_c_driver.cc +++ /dev/null @@ -1,418 +0,0 @@ -/* - * Copyright (C) 2011-2012 Houtan Bastani, Daniel Waggoner, Tao Zha - * - * This 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. - * - * This code 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. - * - * More information is available at <http://www.gnu.org/licenses/>. - */ - -#include <cstdlib> -#include <vector> -#include <string> -#include <iostream> -#include <assert.h> - -using namespace std; - -#include "ms_dsge_c_driver.hh" - -MsDsgeInfo::MsDsgeInfo(map<string, int > exo_names_arg, - map<string, int > exo_det_names_arg, - map<string, int > endo_names_arg, - map<string, int > param_names_arg, - map<int, double > params_arg, - vector<aux_vars_t> aux_vars_arg, - vector<int> predetermined_variables_arg, - vector<int> varobs_arg, - vector<vector<int > > lead_lag_incidence_arg, - vector<double> NNZDerivatives_arg) : - exo_names(exo_names_arg), - exo_det_names(exo_det_names_arg), - endo_names(endo_names_arg), - param_names(param_names_arg), - params(params_arg), - aux_vars(aux_vars_arg), - predetermined_variables(predetermined_variables_arg), - varobs(varobs_arg), - lead_lag_incidence(lead_lag_incidence_arg), - NNZDerivatives(NNZDerivatives_arg) -{ -} - -MsDsgeInfo::~MsDsgeInfo() -{ - for (vector<MarkovSwitching *>::iterator it = markov_switching_vector.begin(); - it < markov_switching_vector.end(); it++) - delete *it; - - for (vector<ModFilePrior *>::iterator it = prior_vector.begin(); - it < prior_vector.end(); it++) - delete *it; - - for (vector<ModFileStructuralInnovationPrior *>::iterator it = structural_innovation_prior_vector.begin(); - it < structural_innovation_prior_vector.end(); it++) - delete *it; - - for (vector<ModFileMeasurementErrorPrior *>::iterator it = measurement_error_prior_vector.begin(); - it < measurement_error_prior_vector.end(); it++) - delete *it; - - for (vector<ModFileStructuralInnovationCorrPrior *>::iterator it = structural_innovation_corr_prior_vector.begin(); - it < structural_innovation_corr_prior_vector.end(); it++) - delete *it; - - for (vector<ModFileMeasurementErrorCorrPrior *>::iterator it = measurement_error_corr_prior_vector.begin(); - it < measurement_error_corr_prior_vector.end(); it++) - delete *it; - - markov_switching_vector.clear(); - prior_vector.clear(); - structural_innovation_prior_vector.clear(); - measurement_error_prior_vector.clear(); - structural_innovation_corr_prior_vector.clear(); - measurement_error_corr_prior_vector.clear(); - exo_names.clear(); - exo_det_names.clear(); - endo_names.clear(); - param_names.clear(); - params.clear(); - aux_vars.clear(); - predetermined_variables.clear(); - varobs.clear(); - lead_lag_incidence.clear(); - NNZDerivatives.clear(); -} - -string -MsDsgeInfo::get_exo_name_by_index(int index) throw (ValueNotSetException) -{ - for (map<string, int >::iterator it = exo_names.begin(); - it != exo_names.end(); it++) - if (it->second == index) - return it->first; - throw ValueNotSetException("get_exo_name_by_index" + index); -} - -int -MsDsgeInfo::get_exo_index_by_name(string name) throw (ValueNotSetException) -{ - map<string, int >::iterator it = exo_names.find(name); - if (it != exo_names.end()) - return it->second; - throw ValueNotSetException("get_exo_name_by_name" + name); -} - -string -MsDsgeInfo::get_exo_det_name_by_index(int index) throw (ValueNotSetException) -{ - for (map<string, int >::iterator it = exo_det_names.begin(); - it != exo_det_names.end(); it++) - if (it->second == index) - return it->first; - throw ValueNotSetException("get_exo_det_name_by_index" + index); -} - -int -MsDsgeInfo::get_exo_det_index_by_name(string name) throw (ValueNotSetException) -{ - map<string, int >::iterator it = exo_det_names.find(name); - if (it != exo_det_names.end()) - return it->second; - throw ValueNotSetException("get_exo_det_name_by_name" + name); -} - -string -MsDsgeInfo::get_endo_name_by_index(int index) throw (ValueNotSetException) -{ - for (map<string, int >::iterator it = endo_names.begin(); - it != endo_names.end(); it++) - if (it->second == index) - return it->first; - throw ValueNotSetException("get_endo_name_by_index" + index); -} - -int -MsDsgeInfo::get_endo_index_by_name(string name) throw (ValueNotSetException) -{ - map<string, int >::iterator it = endo_names.find(name); - if (it != endo_names.end()) - return it->second; - throw ValueNotSetException("get_endo_name_by_name" + name); -} - -string -MsDsgeInfo::get_param_name_by_index(int index) throw (ValueNotSetException) -{ - for (map<string, int >::iterator it = param_names.begin(); - it != param_names.end(); it++) - if (it->second == index) - return it->first; - throw ValueNotSetException("get_param_name_by_index" + index); -} - -int -MsDsgeInfo::get_param_index_by_name(string name) throw (ValueNotSetException) -{ - map<string, int >::iterator it = param_names.find(name); - if (it != param_names.end()) - return it->second; - throw ValueNotSetException("get_param_name_by_name" + name); -} - -double -MsDsgeInfo::get_param_value_by_index(int index) throw (ValueNotSetException) -{ - map<int, double >::iterator it = params.find(index); - if (it != params.end()) - return it->second; - throw ValueNotSetException("get_param_value_by_index" + index); -} - -vector<int > -MsDsgeInfo::get_lead_lag_incidence_for_endo_var_by_index(int index) throw (ValueNotSetException) -{ - if (index < lead_lag_incidence.size()) - return lead_lag_incidence.at(index); - throw ValueNotSetException("get_lead_lag_incidence_for_endo_var_by_index" + index); -} - -MarkovSwitching::MarkovSwitching(const int chain_arg, - const int number_of_regimes_arg, - const int number_of_lags_arg, - const bool number_of_lags_was_passed_arg, - const vector<int> parameters_arg, - const vector<double> duration_arg, - const restriction_map_t restriction_map_arg) : - chain(chain_arg), - number_of_regimes(number_of_regimes_arg), - number_of_lags(number_of_lags_arg), - number_of_lags_was_passed(number_of_lags_was_passed_arg), - parameters(parameters_arg), - duration(duration_arg), - restriction_map(restriction_map_arg) -{ - assert(chain >= 1); - assert(number_of_regimes > 0); - if (number_of_lags_was_passed) - assert(number_of_lags > 0); - assert(!parameters.empty()); - assert(!duration.empty()); -} - -int -MarkovSwitching::get_number_of_lags() throw (ValueNotSetException) -{ - if (number_of_lags_has_val()) - return number_of_lags; - throw ValueNotSetException("number_of_lags"); -} - -restriction_map_t -MarkovSwitching::get_restriction_map() throw (ValueNotSetException) -{ - if (restriction_map_has_val()) - return restriction_map; - throw ValueNotSetException("restriction_map"); -} - -BasicModFilePrior::BasicModFilePrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double mode_arg, - const double stdev_arg, - const double variance_arg, - const vector <double> domain_arg) : - index(index_arg), - shape(shape_arg), - mean(mean_arg), - mode(mode_arg), - stdev(stdev_arg), - variance(variance_arg), - domain(domain_arg) -{ - assert(index >= 0); - assert(!shape.empty()); - if (stdev_has_val()) - assert(stdev >= 0); - if (variance_has_val()) - assert(variance >= 0); - if (domain_has_val()) - assert(domain.size() == 2); -} - -double -BasicModFilePrior::get_mean() throw (ValueNotSetException) -{ - if (mean_has_val()) - return mean; - throw ValueNotSetException("mean"); -}; - -double -BasicModFilePrior::get_mode() throw (ValueNotSetException) -{ - if (mode_has_val()) - return mode; - throw ValueNotSetException("mode"); -}; - -double -BasicModFilePrior::get_stdev() throw (ValueNotSetException) -{ - if (stdev_has_val()) - return stdev; - throw ValueNotSetException("stdev"); -}; - -double -BasicModFilePrior::get_variance() throw (ValueNotSetException) -{ - if (variance_has_val()) - return variance; - throw ValueNotSetException("variance"); -}; - -vector<double> -BasicModFilePrior::get_domain() throw (ValueNotSetException) -{ - if (domain_has_val()) - return domain; - throw ValueNotSetException("domain"); -}; - -ModFilePrior::ModFilePrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double mode_arg, - const double stdev_arg, - const double variance_arg, - const vector <double> domain_arg) : - BasicModFilePrior(index_arg, - shape_arg, - mean_arg, - mode_arg, - stdev_arg, - variance_arg, - domain_arg) -{ -} - -ModFileStructuralInnovationPrior::ModFileStructuralInnovationPrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg) : - BasicModFilePrior(index_arg, - shape_arg, - mean_arg, - mode_arg, - stdev_arg, - variance_arg, - domain_arg) -{ -} - -ModFileMeasurementErrorPrior::ModFileMeasurementErrorPrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg) : - BasicModFilePrior(index_arg, - shape_arg, - mean_arg, - mode_arg, - stdev_arg, - variance_arg, - domain_arg) -{ -} - -ModFileStructuralInnovationCorrPrior::ModFileStructuralInnovationCorrPrior(const int index1_arg, - const int index2_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg) : - BasicModFilePrior(index1_arg, - shape_arg, - mean_arg, - mode_arg, - stdev_arg, - variance_arg, - domain_arg), - index2(index2_arg) -{ - assert(index2 >= 0); -} - -ModFileMeasurementErrorCorrPrior::ModFileMeasurementErrorCorrPrior(const int index1_arg, - const int index2_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg) : - BasicModFilePrior(index1_arg, - shape_arg, - mean_arg, - mode_arg, - stdev_arg, - variance_arg, - domain_arg), - index2(index2_arg) -{ - assert(index2 >= 0); -} - -BasicModFileOption::BasicModFileOption(const int index_arg, - const double init_arg) : - index(index_arg), - init(init_arg) -{ - assert(index >= 0); - assert(!isnan(init)); -} - -ModFileOption::ModFileOption(const int index_arg, const double init_arg) : - BasicModFileOption(index_arg, init_arg) -{ -} - -ModFileStructuralInnovationOption::ModFileStructuralInnovationOption(const int index_arg, const double init_arg) : - BasicModFileOption(index_arg, init_arg) -{ -} - -ModFileMeasurementErrorOption::ModFileMeasurementErrorOption(const int index_arg, const double init_arg) : - BasicModFileOption(index_arg, init_arg) -{ -} - -ModFileStructuralInnovationCorrOption::ModFileStructuralInnovationCorrOption(const int index1_arg, const int index2_arg, const double init_arg) : - BasicModFileOption(index1_arg, init_arg), - index2(index2_arg) -{ - assert(index2 >= 0); -} - -ModFileMeasurementErrorCorrOption::ModFileMeasurementErrorCorrOption(const int index1_arg, const int index2_arg, const double init_arg) : - BasicModFileOption(index1_arg, init_arg), - index2(index2_arg) -{ - assert(index2 >= 0); -} diff --git a/others/cpp/ms_dsge_c_driver.hh b/others/cpp/ms_dsge_c_driver.hh deleted file mode 100644 index 194cfa94dd446a55aefcd5fdcd43b2de83c2df8a..0000000000000000000000000000000000000000 --- a/others/cpp/ms_dsge_c_driver.hh +++ /dev/null @@ -1,564 +0,0 @@ -/* - * Copyright (C) 2011-2012 Houtan Bastani, Daniel Waggoner, Tao Zha - * - * This 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. - * - * This code 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. - * - * More information is available at <http://www.gnu.org/licenses/>. - */ - -#ifndef _DYNARE_CPP_DRIVER_HH -#define _DYNARE_CPP_DRIVER_HH - -#include <cstdlib> -#include <vector> -#include <string> -#include <map> -#include <limits> - -using namespace std; - -struct aux_vars_t -{ - int endo_index, type, orig_index, orig_lead_lag; -}; - -typedef map<pair<int, int >, double> restriction_map_t; - -class ValueNotSetException -{ -public: - string name; - ValueNotSetException(const string &name_arg) : name(name_arg) - { - } -}; - -class MarkovSwitching -{ -private: - const int chain, number_of_regimes, number_of_lags; - const bool number_of_lags_was_passed; - const vector<int> parameters; - const vector<double> duration; - const restriction_map_t restriction_map; -public: - MarkovSwitching(const int chain_arg, - const int number_of_regimes_arg, - const int number_of_lags_arg, - const bool number_of_lags_was_passed_arg, - const vector<int> parameters_arg, - const vector<double> duration_arg, - const restriction_map_t restriction_map_arg); - - inline bool - number_of_lags_has_val() const - { - return number_of_lags_was_passed; - }; - inline bool - restriction_map_has_val() const - { - return !restriction_map.empty(); - }; - - inline int - get_chain() const - { - return chain; - }; - inline int - get_number_of_regimes() const - { - return number_of_regimes; - }; - int get_number_of_lags() throw (ValueNotSetException); - inline vector<int> - get_parameters() - { - return parameters; - }; - inline vector<double> - get_duration() - { - return duration; - }; - restriction_map_t get_restriction_map() throw (ValueNotSetException); -}; - -class BasicModFilePrior -{ -private: - inline bool - isnan(double x) const - { - return (x != x); - }; -protected: - const int index; - const string shape; - const double mean, mode, stdev, variance; - const vector <double> domain; - - BasicModFilePrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double mode_arg, - const double stdev_arg, - const double variance_arg, - const vector <double> domain_arg); -public: - inline bool - mean_has_val() const - { - return !isnan(mean); - }; - inline bool - mode_has_val() const - { - return !isnan(mode); - }; - inline bool - stdev_has_val() const - { - return !isnan(stdev); - }; - inline bool - variance_has_val() const - { - return !isnan(variance); - }; - inline bool - domain_has_val() const - { - return (domain.size() == 2); - }; - - inline int - get_index() const - { - return index; - }; - inline string - get_shape() const - { - return shape; - }; - double get_mean() throw (ValueNotSetException); - double get_mode() throw (ValueNotSetException); - double get_stdev() throw (ValueNotSetException); - double get_variance() throw (ValueNotSetException); - vector<double> get_domain() throw (ValueNotSetException); -}; - -class ModFilePrior : public BasicModFilePrior -{ -public: - ModFilePrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double mode_arg, - const double stdev_arg, - const double variance_arg, - const vector <double> domain_arg); -}; - -class ModFileStructuralInnovationPrior : public BasicModFilePrior -{ -public: - ModFileStructuralInnovationPrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double mode_arg, - const double stdev_arg, - const double variance_arg, - const vector <double> domain_arg); -}; - -class ModFileMeasurementErrorPrior : public BasicModFilePrior -{ -public: - ModFileMeasurementErrorPrior(const int index_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg); -}; - -class ModFileStructuralInnovationCorrPrior : public BasicModFilePrior -{ -private: - const int index2; -public: - ModFileStructuralInnovationCorrPrior(const int index1_arg, - const int index2_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg); -}; - -class ModFileMeasurementErrorCorrPrior : public BasicModFilePrior -{ -private: - const int index2; -public: - ModFileMeasurementErrorCorrPrior(const int index1_arg, - const int index2_arg, - const string shape_arg, - const double mean_arg, - const double stdev_arg, - const double variance_arg, - const double mode_arg, - const vector <double> domain_arg); -}; - -class BasicModFileOption -{ -private: - inline bool - isnan(double x) const - { - return (x != x); - }; -protected: - const int index; - const double init; - - BasicModFileOption(const int index_arg, - const double init_arg); -public: - inline int - get_index() const - { - return index; - }; - inline double - get_init() const - { - return init; - }; -}; - -class ModFileOption : public BasicModFileOption -{ -public: - ModFileOption(const int index_arg, - const double init_arg); -}; - -class ModFileStructuralInnovationOption : public BasicModFileOption -{ -public: - ModFileStructuralInnovationOption(const int index_arg, - const double init_arg); -}; - -class ModFileMeasurementErrorOption : public BasicModFileOption -{ -public: - ModFileMeasurementErrorOption(const int index_arg, - const double init_arg); -}; - -class ModFileStructuralInnovationCorrOption : public BasicModFileOption -{ -private: - const int index2; -public: - ModFileStructuralInnovationCorrOption(const int index1_arg, - const int index2_arg, - const double init_arg); -}; - -class ModFileMeasurementErrorCorrOption : public BasicModFileOption -{ -private: - const int index2; -public: - ModFileMeasurementErrorCorrOption(const int index1_arg, - const int index2_arg, - const double init_arg); -}; - -class DynareInfo -{ -private: - vector<MarkovSwitching *> markov_switching_vector; - vector<ModFilePrior *> prior_vector; - vector<ModFileStructuralInnovationPrior *> structural_innovation_prior_vector; - vector<ModFileMeasurementErrorPrior *> measurement_error_prior_vector; - vector<ModFileStructuralInnovationCorrPrior *> structural_innovation_corr_prior_vector; - vector<ModFileMeasurementErrorCorrPrior *> measurement_error_corr_prior_vector; - vector<ModFileOption *> option_vector; - vector<ModFileStructuralInnovationOption *> structural_innovation_option_vector; - vector<ModFileMeasurementErrorOption *> measurement_error_option_vector; - vector<ModFileStructuralInnovationCorrOption *> structural_innovation_corr_option_vector; - vector<ModFileMeasurementErrorCorrOption *> measurement_error_corr_option_vector; - map<string, int > exo_names, exo_det_names, endo_names, param_names; - map<int, double > params; - vector<aux_vars_t> aux_vars; - vector<int> predetermined_variables; - vector<int> varobs; - vector<vector<int > > lead_lag_incidence; - vector<double> NNZDerivatives; -public: - DynareInfo(map<string, int > exo_names_arg, - map<string, int > exo_det_names_arg, - map<string, int > endo_names_arg, - map<string, int > param_names_arg, - map<int, double > params_arg, - vector<aux_vars_t> aux_vars_arg, - vector<int> predetermined_variables_arg, - vector<int> varobs_arg, - vector<vector<int > > lead_lag_incidence_arg, - vector<double> NNZDerivatives_arg); - ~DynareInfo(); - - inline void - addMarkovSwitching(MarkovSwitching *ms) - { - markov_switching_vector.push_back(ms); - }; - - inline void - addPrior(ModFilePrior *p) - { - prior_vector.push_back(p); - }; - inline void - addStructuralInnovationPrior(ModFileStructuralInnovationPrior *sip) - { - structural_innovation_prior_vector.push_back(sip); - }; - inline void - addMeasurementErrorPrior(ModFileMeasurementErrorPrior *mep) - { - measurement_error_prior_vector.push_back(mep); - }; - inline void - addStructuralInnovationCorrPrior(ModFileStructuralInnovationCorrPrior *sicp) - { - structural_innovation_corr_prior_vector.push_back(sicp); - }; - inline void - addMeasurementErrorCorrPrior(ModFileMeasurementErrorCorrPrior *mecp) - { - measurement_error_corr_prior_vector.push_back(mecp); - }; - - inline void - addOption(ModFileOption *o) - { - option_vector.push_back(o); - }; - inline void - addStructuralInnovationOption(ModFileStructuralInnovationOption *sio) - { - structural_innovation_option_vector.push_back(sio); - }; - inline void - addMeasurementErrorOption(ModFileMeasurementErrorOption *meo) - { - measurement_error_option_vector.push_back(meo); - }; - inline void - addStructuralInnovationCorrOption(ModFileStructuralInnovationCorrOption *sico) - { - structural_innovation_corr_option_vector.push_back(sico); - }; - inline void - addMeasurementErrorCorrOption(ModFileMeasurementErrorCorrOption *meco) - { - measurement_error_corr_option_vector.push_back(meco); - }; - - inline bool - markov_switching_has_val() - { - return !markov_switching_vector.empty(); - }; - inline bool - prior_has_val() - { - return !prior_vector.empty(); - }; - inline bool - structural_innovation_prior_has_val() - { - return !structural_innovation_prior_vector.empty(); - }; - inline bool - measurement_error_prior_has_val() - { - return !measurement_error_prior_vector.empty(); - }; - inline bool - structural_innovation_corr_prior_has_val() - { - return !structural_innovation_corr_prior_vector.empty(); - }; - inline bool - measurement_error_corr_prior_has_val() - { - return !measurement_error_corr_prior_vector.empty(); - }; - - inline bool - option_has_val() - { - return !option_vector.empty(); - }; - inline bool - structural_innovation_option_has_val() - { - return !structural_innovation_option_vector.empty(); - }; - inline bool - measurement_error_option_has_val() - { - return !measurement_error_option_vector.empty(); - }; - inline bool - structural_innovation_corr_option_has_val() - { - return !structural_innovation_corr_option_vector.empty(); - }; - inline bool - measurement_error_corr_option_has_val() - { - return !measurement_error_corr_option_vector.empty(); - }; - - inline vector<MarkovSwitching *> - get_markov_switching() - { - return markov_switching_vector; - }; - inline vector<ModFilePrior *> - get_prior() - { - return prior_vector; - }; - inline vector<ModFileStructuralInnovationPrior *> - get_structural_innovation_prior() - { - return structural_innovation_prior_vector; - }; - inline vector<ModFileMeasurementErrorPrior *> - get_measurement_error_prior() - { - return measurement_error_prior_vector; - }; - inline vector<ModFileStructuralInnovationCorrPrior *> - get_structural_innovation_corr_prior() - { - return structural_innovation_corr_prior_vector; - }; - inline vector<ModFileMeasurementErrorCorrPrior *> - get_measurement_error_corr_prior() - { - return measurement_error_corr_prior_vector; - }; - - inline vector<ModFileOption *> - get_option() - { - return option_vector; - }; - inline vector<ModFileStructuralInnovationOption *> - get_structural_innovation_option() - { - return structural_innovation_option_vector; - }; - inline vector<ModFileMeasurementErrorOption *> - get_measurement_error_option() - { - return measurement_error_option_vector; - }; - inline vector<ModFileStructuralInnovationCorrOption *> - get_structural_innovation_corr_option() - { - return structural_innovation_corr_option_vector; - }; - inline vector<ModFileMeasurementErrorCorrOption *> - get_measurement_error_corr_option() - { - return measurement_error_corr_option_vector; - }; - - inline map<string, int > - get_exo_names() - { - return exo_names; - }; - inline map<string, int > - get_exo_det_names() - { - return exo_det_names; - }; - inline map<string, int > - get_endo_names() - { - return endo_names; - }; - inline map<string, int > - get_param_names() - { - return param_names; - }; - inline map<int, double > - get_params() - { - return params; - }; - inline vector <aux_vars_t> - get_aux_vars() - { - return aux_vars; - }; - inline vector <int> - get_predetermined_variables() - { - return predetermined_variables; - }; - inline vector <int> - get_varobs() - { - return varobs; - }; - inline vector<vector<int > > - get_lead_lag_incidence() - { - return lead_lag_incidence; - }; - inline vector<double> - get_NNZDerivatives() - { - return NNZDerivatives; - }; - - string get_exo_name_by_index(int index) throw (ValueNotSetException); - int get_exo_index_by_name(string name) throw (ValueNotSetException); - string get_exo_det_name_by_index(int index) throw (ValueNotSetException); - int get_exo_det_index_by_name(string name) throw (ValueNotSetException); - string get_endo_name_by_index(int index) throw (ValueNotSetException); - int get_endo_index_by_name(string name) throw (ValueNotSetException); - string get_param_name_by_index(int index) throw (ValueNotSetException); - int get_param_index_by_name(string name) throw (ValueNotSetException); - double get_param_value_by_index(int index) throw (ValueNotSetException); - vector<int > get_lead_lag_incidence_for_endo_var_by_index(int index) throw (ValueNotSetException); -}; - -#endif // ! _DYNARE_CPP_DRIVER_HH diff --git a/others/cpp/tests/.gitignore b/others/cpp/tests/.gitignore deleted file mode 100644 index 3d4fa420d1fa563153aaf12d54ce14ebe6f64936..0000000000000000000000000000000000000000 --- a/others/cpp/tests/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -*.c -*.cc -*.m - -!test1.cc diff --git a/others/cpp/tests/Makefile b/others/cpp/tests/Makefile deleted file mode 100644 index e33f0d86b2d1fd7ff2ae477fdd8da17381ff18b5..0000000000000000000000000000000000000000 --- a/others/cpp/tests/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -DYNARE=../../../matlab/dynare_m -am_test_dr_OBJECTS = test_dr-Matrix.$(OBJEXT) test_dr-Vector.$(OBJEXT) \ - test_dr-QRDecomposition.$(OBJEXT) \ - test_dr-GeneralizedSchurDecomposition.$(OBJEXT) \ - test_dr-LUSolver.$(OBJEXT) test_dr-DecisionRules.$(OBJEXT) \ - test_dr-test-dr.$(OBJEXT) - -all: test1 -Matrix.o : ../../../mex/sources/estimation/libmat/Matrix.cc - gcc -g -c ../../../mex/sources/estimation/libmat/Matrix.cc -I.. -I../../../mex/sources -I../../../mex/sources/estimation -I../../../mex/sources/estimation/libmat -Vector.o : ../../../mex/sources/estimation/libmat/Vector.cc - gcc -g -c ../../../mex/sources/estimation/libmat/Vector.cc -I.. -I../../../mex/sources -I../../../mex/sources/estimation -I../../../mex/sources/estimation/libmat -QRDecomposition.o : ../../../mex/sources/estimation/libmat/QRDecomposition.cc - gcc -g -c ../../../mex/sources/estimation/libmat/QRDecomposition.cc -I.. -I../../../mex/sources -I../../../mex/sources/estimation -I../../../mex/sources/estimation/libmat -GeneralizedSchurDecomposition.o : ../../../mex/sources/estimation/libmat/GeneralizedSchurDecomposition.cc - gcc -g -c ../../../mex/sources/estimation/libmat/GeneralizedSchurDecomposition.cc -I.. -I../../../mex/sources -I../../../mex/sources/estimation -I../../../mex/sources/estimation/libmat -LUSolver.o : ../../../mex/sources/estimation/libmat/LUSolver.cc - gcc -g -c ../../../mex/sources/estimation/libmat/LUSolver.cc -I.. -I../../../mex/sources -I../../../mex/sources/estimation -I../../../mex/sources/estimation/libmat -DecisionRules.o : ../../../mex/sources/estimation/DecisionRules.cc - gcc -g -c ../../../mex/sources/estimation/DecisionRules.cc -I../../../mex/sources -I../../../mex/sources/estimation -I../../../mex/sources/estimation/libmat - -test1.o : test1.cc ../dynare_cpp_driver.hh ../dynare_cpp_driver.cc - gcc -g -c test1.cc -I.. -I../../../mex/sources -I../../../mex/sources/estimation -I../../../mex/sources/estimation/libmat -dynare_cpp_driver.o: ../dynare_cpp_driver.cc ../dynare_cpp_driver.hh - gcc -g -c ../dynare_cpp_driver.cc -I.. -example1.cc example1_steadystate.cc: example1.mod - $(DYNARE) example1.mod output=first language=C++ -example1.o: example1.cc - gcc -g -c example1.cc -I.. -example1_steadystate.o: example1_steadystate.c - gcc -g -c example1_steadystate.c -example1_first_derivatives.o: example1_first_derivatives.c - gcc -g -c example1_first_derivatives.c - -test1 : test1.o example1.o example1_steadystate.o example1_first_derivatives.o dynare_cpp_driver.o Matrix.o Vector.o QRDecomposition.o GeneralizedSchurDecomposition.o LUSolver.o DecisionRules.o - gcc -g -o test1 test1.o example1.o example1_steadystate.o example1_first_derivatives.o dynare_cpp_driver.o Matrix.o Vector.o QRDecomposition.o GeneralizedSchurDecomposition.o LUSolver.o DecisionRules.o -llapack -lblas -lm -lstdc++ - -.cc.o: - gcc -g -c -o $@ $< -I.. -I../../../mex/sources -I../../../mex/sources/estimation -I../../../mex/sources/estimation/libmat diff --git a/others/cpp/tests/Makefile_petsc b/others/cpp/tests/Makefile_petsc deleted file mode 100644 index 87b829ce5ee0c327490615f186cf43950b352aba..0000000000000000000000000000000000000000 --- a/others/cpp/tests/Makefile_petsc +++ /dev/null @@ -1,25 +0,0 @@ -include ${PETSC_DIR}/lib/petsc/conf/variables -include ${PETSC_DIR}/lib/petsc/conf/rules - -CFLAGS = ${PETSC_CC_INCLUDES} -I. -I.. -CPPFLAGS = ${PETSC_CC_INCLUDES} -I. -I.. - -all: main_tao_1 - -main_tao_1: main_tao_1.o pf_jacobian.o example1.o example1_steadystate.o example1_first_derivatives.o example1_residuals.o - ${CLINKER} -o main_tao_1 main_tao_1.o example1.o example1_steadystate.o example1_residuals.o example1_first_derivatives.o ${PETSC_LIB} -lstdc++ -lm - -snes_1: snes_1.o example1.o example1_steadystate.o example1_first_derivatives.o example1_residuals.o - ${CLINKER} -o snes_1 snes_1.o example1.o example1_steadystate.o example1_residuals.o example1_first_derivatives.o ${PETSC_LIB} -lstdc++ -lm - -main_tao_1.o: main_tao_1.cc main_tao.h ../dynare_cpp_driver.hh -snes_1.o: snes_1.cc main_tao.h ../dynare_cpp_driver.hh -pf_jacobian.o: pf_jacobian.cc main_tao.h -example1.o: example1.cc ../dynare_cpp_driver.hh -example1_steadystate.o: example1_steadystate.cc -example1_residuals.o: example1_residuals.c -example1_first_derivatives.o: example1_first_derivatives.c -example1.cc: example1.mod - /home/michel/dynare/git/master/matlab/preprocessor64/dynare_m example1.mod output=first language=C++ -example1_residuals.c: example1.mod - /home/michel/dynare/git/master/matlab/preprocessor64/dynare_m example1.mod output=first language=C++ diff --git a/others/cpp/tests/example1.mod b/others/cpp/tests/example1.mod deleted file mode 100644 index ec43f08718f5b1971a15af3a13cc7688e128a942..0000000000000000000000000000000000000000 --- a/others/cpp/tests/example1.mod +++ /dev/null @@ -1,45 +0,0 @@ -// Example 1 from Collard's guide to Dynare -var h, c, y, k, a, b; -varexo e, u; - -parameters beta, rho, alpha, delta, theta, psi, tau; - -alpha = 0.36; -rho = 0.95; -tau = 0.025; -beta = 0.99; -delta = 0.025; -psi = 0; -theta = 2.95; - -phi = 0.1; - -model; -c*theta*exp(h)^(1+psi)=(1-alpha)*y; -exp(k) = beta*(((exp(b)*c)/(exp(b(+1))*c(+1))) - *(exp(b(+1))*alpha*y(+1)+(1-delta)*exp(k))); -y = exp(a)*(exp(k(-1))^alpha)*(exp(h)^(1-alpha)); -exp(k) = exp(b)*(y-c)+(1-delta)*exp(k(-1)); -a = rho*a(-1)+tau*b(-1) + e; -b = tau*a(-1)+rho*b(-1) + u; -end; - -steady_state_model; -a = 0; -b = 0; -k_h = ((1-beta*(1-delta))/(beta*alpha))^(1/(alpha-1)); -y_h = k_h^alpha; -c_h = y_h - delta*k_h; -h = log((y_h*(1-alpha)/(c_h*theta))^(1/(1+psi))); -k = log(k_h*exp(h)); -c = c_h*exp(h); -y = y_h*exp(h); -end; - -shocks; -var e; stderr 0.009; -var u; stderr 0.009; -var e, u = phi*0.009*0.009; -end; - -stoch_simul; diff --git a/others/cpp/tests/snes_1.cc b/others/cpp/tests/snes_1.cc deleted file mode 100644 index 1f03026e099b6d15b7c70baeeba8554617995bfd..0000000000000000000000000000000000000000 --- a/others/cpp/tests/snes_1.cc +++ /dev/null @@ -1,721 +0,0 @@ -#include <iostream> -#include "../dynare_cpp_driver.hh" -#include <petscdm.h> -#include <petscdmda.h> -#include <petscsnes.h> -#include "main_tao.h" - -DynareInfo *preprocessorOutput(void); -PetscErrorCode FormFunction(SNES snes, Vec y, Vec f, void *ctx); -PetscErrorCode FormJacobian(SNES snes, Vec y, Mat J, Mat B, void *ctx); -PetscErrorCode Monitor(SNES, PetscInt, PetscReal, void *); -PetscErrorCode PreCheck(SNESLineSearch, Vec, Vec, PetscBool *, void *); -PetscErrorCode PostCheck(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *, void *); -PetscErrorCode PostSetSubKSP(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *, void *); -PetscErrorCode MatrixFreePreconditioner(PC, Vec, Vec); - -static char help[] = "Testing"; - -/* - User-defined context for monitoring -*/ -typedef struct -{ - PetscViewer viewer; -} MonitorCtx; - -/* - User-defined context for checking candidate iterates that are - determined by line search methods -*/ -typedef struct -{ - Vec last_step; /* previous iterate */ - PetscReal tolerance; /* tolerance for changes between successive iterates */ - AppCtx *user; -} StepCheckCtx; - -typedef struct -{ - PetscInt its0; /* num of prevous outer KSP iterations */ -} SetSubKSPCtx; - -#undef __FUNCT__ -#define __FUNCT__ "main" -int -main(int argc, char **argv) -{ - DynareInfo model_info; - - int endo_nbr = model_info.get_endo_nbr(); - int exo_nbr = model_info.get_exo_nbr(); - double *params = model_info.get_params_data(); - // Steady state - double *steady_state = new double[endo_nbr]; - int info; - steadystate(NULL, params, steady_state, &info); - vector<int> NNZDerivatives = model_info.get_NNZDerivatives(); - AppCtx user; /* user-defined work context */ - user.exogenous = new double[exo_nbr]; - user.params = params; - user.steady_state = steady_state; - user.periods = 4000; - user.first_col = endo_nbr; - user.endo_nbr = endo_nbr; - user.exo_nbr = exo_nbr; - user.row_ptr = new int[endo_nbr+1]; - user.nnz = NNZDerivatives[0]; - user.col_ptr = new int[NNZDerivatives[0]]; - user.val_ptr = new double[NNZDerivatives[0]]; - user.initial_values = new double[user.endo_nbr]; - user.terminal_values = new double[user.endo_nbr]; - for (int i = 0; i < user.endo_nbr; ++i) - { - user.initial_values[i] = user.steady_state[i]; - user.terminal_values[i] = user.steady_state[i]; - } - /* Initialize PETSc */ - PetscInitialize(&argc, &argv, (char *) 0, help); - PetscErrorCode ierr; - /* Get number of processors */ - PetscInt size; - ierr = MPI_Comm_size(PETSC_COMM_WORLD, &size); CHKERRQ(ierr); - /* Set periods a multiple of processor nbr */ - user.periods = size*ceil((double) user.periods/size); - user.nb_row_x = user.periods + 1; - user.X = new double[user.nb_row_x*user.exo_nbr]; - for (double *px = user.X; px < user.X+user.nb_row_x*user.exo_nbr; px++) - *px = 0.0; - user.X[1] = 0.01; - user.X[1+user.nb_row_x] = 0.01; - std::cout << size << " " << user.periods << " " << std::endl; - PetscInt N = user.periods*user.endo_nbr; - /* Create DMA */ - DMDACreate1d(PETSC_COMM_WORLD, DM_BOUNDARY_GHOSTED, N, 1, user.endo_nbr, NULL, &user.da); - - /* Allocate vector and Jacobian matrix */ \ - Vec Y, R; - DMCreateGlobalVector(user.da, &Y); - VecDuplicate(Y, &R); - - Mat J; - ierr = MatCreate(PETSC_COMM_WORLD, &J); CHKERRQ(ierr); - ierr = MatSetSizes(J, PETSC_DECIDE, PETSC_DECIDE, N, N); CHKERRQ(ierr); - ierr = MatSetFromOptions(J); CHKERRQ(ierr); - ierr = MatSetUp(J); CHKERRQ(ierr); - - /* - Get local grid boundaries (for 1-dimensional DMDA): - xs, xm - starting grid index, width of local grid (no ghost points) - */ - PetscInt xs, xm, xsg, xmg; - DMDAGetCorners(user.da, &xs, NULL, NULL, &xm, NULL, NULL); - std::cout << xs << " " << xm << std::endl; - DMDAGetGhostCorners(user.da, &xsg, NULL, NULL, &xmg, NULL, NULL); - std::cout << "ghost " << xsg << " " << xmg << std::endl; - /* - Get pointers to vector data - */ - PetscScalar *YY; - DMDAVecGetArray(user.da, Y, &YY); - - /* - Compute local vector entries - */ - for (int i = xs; i < xs+xm; i += user.endo_nbr) - for (int j = 0; j < user.endo_nbr; j++) - YY[i+j] = steady_state[j]; - /* - Restore vectors - */ - DMDAVecRestoreArray(user.da, Y, &YY); - - SNES snes; - ierr = SNESCreate(PETSC_COMM_WORLD, &snes); CHKERRQ(ierr); - - // SNES snes; - SNESLineSearch linesearch; /* SNESLineSearch context */ - MonitorCtx monP; /* monitoring context */ - StepCheckCtx checkP; /* step-checking context */ - SetSubKSPCtx checkP1; - PetscBool pre_check, post_check, post_setsubksp; /* flag indicating whether we're checking candidate iterates */ - PetscReal abstol, rtol, stol, norm; - PetscInt its, maxit, maxf; - PetscBool flg; - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Create nonlinear solver context - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - ierr = SNESCreate(PETSC_COMM_WORLD, &snes); CHKERRQ(ierr); - - /* - Set function evaluation routine and vector. Whenever the nonlinear - solver needs to compute the nonlinear function, it will call this - routine. - - Note that the final routine argument is the user-defined - context that provides application-specific data for the - function evaluation routine. - */ - ierr = SNESSetFunction(snes, R, FormFunction, &user); CHKERRQ(ierr); - - /* - Set Jacobian matrix data structure and default Jacobian evaluation - routine. Whenever the nonlinear solver needs to compute the - Jacobian matrix, it will call this routine. - - Note that the final routine argument is the user-defined - context that provides application-specific data for the - Jacobian evaluation routine. - */ - ierr = SNESSetJacobian(snes, J, J, FormJacobian, &user); CHKERRQ(ierr); - - /* - Optional allow user provided preconditioner - */ - ierr = PetscOptionsHasName(NULL, NULL, "-user_precond", &flg); CHKERRQ(ierr); - if (flg) - { - KSP ksp; - PC pc; - ierr = SNESGetKSP(snes, &ksp); CHKERRQ(ierr); - ierr = KSPGetPC(ksp, &pc); CHKERRQ(ierr); - ierr = PCSetType(pc, PCSHELL); CHKERRQ(ierr); - ierr = PCShellSetApply(pc, MatrixFreePreconditioner); CHKERRQ(ierr); - } - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Customize nonlinear solver; set runtime options - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - /* - Set an optional user-defined monitoring routine - */ - ierr = PetscViewerDrawOpen(PETSC_COMM_WORLD, 0, 0, 0, 0, 400, 400, &monP.viewer); CHKERRQ(ierr); - ierr = SNESMonitorSet(snes, Monitor, &monP, 0); CHKERRQ(ierr); - - /* - Set names for some vectors to facilitate monitoring (optional) - */ - ierr = PetscObjectSetName((PetscObject) Y, "Approximate Solution"); CHKERRQ(ierr); - // ierr = PetscObjectSetName((PetscObject)U,"Exact Solution");CHKERRQ(ierr); - - /* - Set SNES/KSP/KSP/PC runtime options, e.g., - -snes_view -snes_monitor -ksp_type <ksp> -pc_type <pc> - */ - KSP ksp; - PC pc; - ierr = SNESGetKSP(snes, &ksp); CHKERRQ(ierr); - ierr = KSPGetPC(ksp, &pc); CHKERRQ(ierr); - ierr = PCSetType(pc, PCLU); CHKERRQ(ierr); - // PetscOptionsSetValue(NULL,"-pc_type","lu"); - ierr = SNESSetFromOptions(snes); CHKERRQ(ierr); - - /* - Set an optional user-defined routine to check the validity of candidate - iterates that are determined by line search methods - */ - ierr = SNESGetLineSearch(snes, &linesearch); CHKERRQ(ierr); - ierr = PetscOptionsHasName(NULL, NULL, "-post_check_iterates", &post_check); CHKERRQ(ierr); - - if (post_check) - { - ierr = PetscPrintf(PETSC_COMM_WORLD, "Activating post step checking routine\n"); CHKERRQ(ierr); - ierr = SNESLineSearchSetPostCheck(linesearch, PostCheck, &checkP); CHKERRQ(ierr); - ierr = VecDuplicate(Y, &(checkP.last_step)); CHKERRQ(ierr); - - checkP.tolerance = 1.0; - checkP.user = &user; - - ierr = PetscOptionsGetReal(NULL, NULL, "-check_tol", &checkP.tolerance, NULL); CHKERRQ(ierr); - } - - ierr = PetscOptionsHasName(NULL, NULL, "-post_setsubksp", &post_setsubksp); CHKERRQ(ierr); - if (post_setsubksp) - { - ierr = PetscPrintf(PETSC_COMM_WORLD, "Activating post setsubksp\n"); CHKERRQ(ierr); - ierr = SNESLineSearchSetPostCheck(linesearch, PostSetSubKSP, &checkP1); CHKERRQ(ierr); - } - - ierr = PetscOptionsHasName(NULL, NULL, "-pre_check_iterates", &pre_check); CHKERRQ(ierr); - if (pre_check) - { - ierr = PetscPrintf(PETSC_COMM_WORLD, "Activating pre step checking routine\n"); CHKERRQ(ierr); - ierr = SNESLineSearchSetPreCheck(linesearch, PreCheck, &checkP); CHKERRQ(ierr); - } - - /* - Print parameters used for convergence testing (optional) ... just - to demonstrate this routine; this information is also printed with - the option -snes_view - */ - ierr = SNESGetTolerances(snes, &abstol, &rtol, &stol, &maxit, &maxf); CHKERRQ(ierr); - ierr = PetscPrintf(PETSC_COMM_WORLD, "atol=%g, rtol=%g, stol=%g, maxit=%D, maxf=%D\n", (double) abstol, (double) rtol, (double) stol, maxit, maxf); CHKERRQ(ierr); - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Evaluate initial guess; then solve nonlinear system - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - /* - Note: The user should initialize the vector, x, with the initial guess - for the nonlinear solver prior to calling SNESSolve(). In particular, - to employ an initial guess of zero, the user should explicitly set - this vector to zero by calling VecSet(). - */ - ierr = SNESSolve(snes, NULL, Y); CHKERRQ(ierr); - ierr = SNESGetIterationNumber(snes, &its); CHKERRQ(ierr); - ierr = PetscPrintf(PETSC_COMM_WORLD, "Number of SNES iterations = %D\n", its); CHKERRQ(ierr); - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Check solution and clean up - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - /* - Free work space. All PETSc objects should be destroyed when they - are no longer needed. - */ - ierr = PetscViewerDestroy(&monP.viewer); CHKERRQ(ierr); - if (post_check) - { - ierr = VecDestroy(&checkP.last_step); CHKERRQ(ierr); - } - ierr = SNESDestroy(&snes); CHKERRQ(ierr); - ierr = DMDestroy(&user.da); CHKERRQ(ierr); - - ierr = MatDestroy(&J); CHKERRQ(ierr); - ierr = VecDestroy(&Y); CHKERRQ(ierr); - ierr = VecDestroy(&R); CHKERRQ(ierr); - ierr = PetscFinalize(); CHKERRQ(ierr); - - PetscFunctionReturn(0); -} - -PetscErrorCode -FormFunction(SNES snes, Vec y, Vec f, void *ctx) -{ - AppCtx *user = (AppCtx *) ctx; - DM da = user->da; - PetscScalar *yy, *ff; - PetscInt M, ys, ym; - Vec ylocal; - - DMGetLocalVector(da, &ylocal); - /* - Scatter ghost points to local vector, using the 2-step process - DMGlobalToLocalBegin(), DMGlobalToLocalEnd(). - By placing code between these two statements, computations can - be done while messages are in transition. - */ - DMGlobalToLocalBegin(da, y, INSERT_VALUES, ylocal); - DMGlobalToLocalEnd(da, y, INSERT_VALUES, ylocal); - - /* - Get pointers to vector data. - - The vector xlocal includes ghost point; the vectors x and f do - NOT include ghost points. - - Using DMDAVecGetArray() allows accessing the values using global ordering - */ - DMDAVecGetArray(da, ylocal, &yy); - DMDAVecGetArray(da, f, &ff); - - /* - Get local grid boundaries (for 1-dimensional DMDA): - ys, ym - starting grid index, width of local grid (no ghost points) - */ - DMDAGetCorners(da, &ys, NULL, NULL, &ym, NULL, NULL); - DMDAGetInfo(da, NULL, &M, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - - /* - Set function values for boundary points; define local interior grid point range: - xsi - starting interior grid index - xei - ending interior grid index - */ - if (ys == 0) /* left boundary */ - { - PetscReal *y1 = new PetscReal[3*user->endo_nbr]; - for (int i = 0; i < user->endo_nbr; ++i) - y1[i] = user->initial_values[i]; - for (int i = 0; i < 2*user->endo_nbr; ++i) - y1[i+user->endo_nbr] = yy[i]; - Residuals(y1, user->X, user->nb_row_x, user->params, user->steady_state, 1, ff); - ys += user->endo_nbr; - ym -= user->endo_nbr; - } - - /* - Compute function over locally owned part of the grid (interior points only) - */ - while ((ym >= user->endo_nbr) && (ys + 2*user->endo_nbr <= M)) - { - int it = ys/user->endo_nbr + 2; - Residuals(yy+ys-user->endo_nbr, user->X, user->nb_row_x, user->params, user->steady_state, it, ff+ys); - ys += user->endo_nbr; - ym -= user->endo_nbr; - } - - if ((ym >= user->endo_nbr) && (ys + 2*user->endo_nbr >= M)) - { - int it = ys/user->endo_nbr + 1; - PetscReal *y1 = new PetscReal[3*user->endo_nbr]; - for (int i = 0; i < 2*user->endo_nbr; ++i) - y1[i] = yy[ys+i-user->endo_nbr]; - for (int i = 0; i < user->endo_nbr; ++i) - y1[i+2*user->endo_nbr] = user->terminal_values[i]; - Residuals(y1, user->X, user->nb_row_x, user->params, user->steady_state, it, ff+ys); - } - - /* - Restore vectors - */ - DMDAVecRestoreArray(da, ylocal, &yy); - DMDAVecRestoreArray(da, f, &ff); - DMRestoreLocalVector(da, &ylocal); - return (0); -} - -PetscErrorCode -FormJacobian(SNES snes, Vec y, Mat J, Mat B, void *ctx) -{ - AppCtx *user = (AppCtx *) ctx; - DM da = user->da; - PetscScalar *yy; - PetscInt M, ys, ym, ierr; - Vec ylocal; - - DMGetLocalVector(da, &ylocal); - /* - Scatter ghost points to local vector, using the 2-step process - DMGlobalToLocalBegin(), DMGlobalToLocalEnd(). - By placing code between these two statements, computations can - be done while messages are in transition. - */ - DMGlobalToLocalBegin(da, y, INSERT_VALUES, ylocal); - DMGlobalToLocalEnd(da, y, INSERT_VALUES, ylocal); - - /* - Get pointers to vector data. - - The vector xlocal includes ghost point; the vectors x and f do - NOT include ghost points. - - Using DMDAVecGetArray() allows accessing the values using global ordering - */ - DMDAVecGetArray(da, ylocal, &yy); - - /* - Get local grid boundaries (for 1-dimensional DMDA): - ys, ym - starting grid index, width of local grid (no ghost points) - */ - DMDAGetCorners(da, &ys, NULL, NULL, &ym, NULL, NULL); - DMDAGetInfo(da, NULL, &M, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - - /* - Set function values for boundary points; define local interior grid point range: - xsi - starting interior grid index - xei - ending interior grid index - */ - int row = ys; - if (ys == 0) /* left boundary */ - { - PetscReal *y1 = new PetscReal[3*user->endo_nbr]; - for (int i = 0; i < user->endo_nbr; ++i) - y1[i] = user->initial_values[i]; - for (int i = 0; i < 2*user->endo_nbr; ++i) - y1[i+user->endo_nbr] = yy[i]; - FirstDerivatives(y1, user->X, user->nb_row_x, user->params, user->steady_state, 1, NULL, user->row_ptr, user->col_ptr, user->val_ptr); - for (int *r = user->row_ptr; r < user->row_ptr+user->endo_nbr; r++) - { - int first_col = 0; - int ncol = 0; - int *pc = user->col_ptr + *r; - while (*(pc) < user->endo_nbr) - { - ++first_col; - ++pc; - } - while (pc < ((user->col_ptr)+*(r+1))) - { - if (*pc < 3*(user->endo_nbr)) - { - ++ncol; - *pc -= user->endo_nbr; - } - ++pc; - } - ierr = MatSetValues(J, 1, &row, ncol, user->col_ptr + *r + first_col, user->val_ptr + *r + first_col, INSERT_VALUES); - CHKERRQ(ierr); - ++row; - } - ys += user->endo_nbr; - ym -= user->endo_nbr; - } - - /* - Compute function over locally owned part of the grid (interior points only) - */ - while ((ym >= user->endo_nbr) && (ys + 2*user->endo_nbr <= M)) - { - int it = ys/user->endo_nbr + 2; - FirstDerivatives(yy+ys-user->endo_nbr, user->X, user->nb_row_x, user->params, user->steady_state, it, NULL, user->row_ptr, user->col_ptr, user->val_ptr); - for (int *r = user->row_ptr; r < user->row_ptr+user->endo_nbr; r++) - { - int ncol = 0; - for (int *pc = user->col_ptr + *r; pc < user->col_ptr + *(r+1); ++pc) - if (*pc < 3*user->endo_nbr) - { - *pc += ys - user->endo_nbr; - ++ncol; - } - ierr = MatSetValues(J, 1, &row, ncol, user->col_ptr + *r, user->val_ptr + *r, INSERT_VALUES); - CHKERRQ(ierr); - ++row; - } - ys += user->endo_nbr; - ym -= user->endo_nbr; - } - - if ((ym >= user->endo_nbr) && (ys + 2*user->endo_nbr >= M)) - { - int it = ys/user->endo_nbr + 1; - PetscReal *y1 = new PetscReal[3*user->endo_nbr]; - for (int i = 0; i < 2*user->endo_nbr; ++i) - y1[i] = yy[ys+i-user->endo_nbr]; - for (int i = 0; i < user->endo_nbr; ++i) - y1[i+2*user->endo_nbr] = user->terminal_values[i]; - FirstDerivatives(y1, user->X, user->nb_row_x, user->params, user->steady_state, it, NULL, user->row_ptr, user->col_ptr, user->val_ptr); - for (int *r = user->row_ptr; r < user->row_ptr+user->endo_nbr; r++) - { - int *pc = user->col_ptr + *r; - int ncol = 0; - while ((*pc < 2*user->endo_nbr) && (pc < user->col_ptr + *(r+1))) - { - ++ncol; - *pc += ys - user->endo_nbr; - ++pc; - } - ierr = MatSetValues(J, 1, &row, ncol, user->col_ptr + *r, user->val_ptr + *r, INSERT_VALUES); - CHKERRQ(ierr); - ++row; - } - } - - /* - Restore vectors - */ - ierr = MatAssemblyBegin(J, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); - DMDAVecRestoreArray(da, ylocal, &yy); - DMRestoreLocalVector(da, &ylocal); - ierr = MatAssemblyEnd(J, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); - return (0); -} - -#undef __FUNCT__ -#define __FUNCT__ "Monitor" -/* - Monitor - Optional user-defined monitoring routine that views the - current iterate with an x-window plot. Set by SNESMonitorSet(). - - Input Parameters: - snes - the SNES context - its - iteration number - norm - 2-norm function value (may be estimated) - ctx - optional user-defined context for private data for the - monitor routine, as set by SNESMonitorSet() - - Note: - See the manpage for PetscViewerDrawOpen() for useful runtime options, - such as -nox to deactivate all x-window output. -*/ -PetscErrorCode -Monitor(SNES snes, PetscInt its, PetscReal fnorm, void *ctx) -{ - PetscErrorCode ierr; - MonitorCtx *monP = (MonitorCtx *) ctx; - Vec x; - - PetscFunctionBeginUser; - ierr = PetscPrintf(PETSC_COMM_WORLD, "iter = %D,SNES Function norm %g\n", its, (double) fnorm); CHKERRQ(ierr); - ierr = SNESGetSolution(snes, &x); CHKERRQ(ierr); - ierr = VecView(x, monP->viewer); CHKERRQ(ierr); - PetscFunctionReturn(0); -} - -/* ------------------------------------------------------------------- */ -#undef __FUNCT__ -#define __FUNCT__ "PreCheck" -/* - PreCheck - Optional user-defined routine that checks the validity of - candidate steps of a line search method. Set by SNESLineSearchSetPreCheck(). - - Input Parameters: - snes - the SNES context - xcurrent - current solution - y - search direction and length - - Output Parameters: - y - proposed step (search direction and length) (possibly changed) - changed_y - tells if the step has changed or not -*/ -PetscErrorCode -PreCheck(SNESLineSearch linesearch, Vec xcurrent, Vec y, PetscBool *changed_y, void *ctx) -{ - PetscFunctionBeginUser; - *changed_y = PETSC_FALSE; - PetscFunctionReturn(0); -} - -/* ------------------------------------------------------------------- */ -#undef __FUNCT__ -#define __FUNCT__ "PostCheck" -/* - PostCheck - Optional user-defined routine that checks the validity of - candidate steps of a line search method. Set by SNESLineSearchSetPostCheck(). - - Input Parameters: - snes - the SNES context - ctx - optional user-defined context for private data for the - monitor routine, as set by SNESLineSearchSetPostCheck() - xcurrent - current solution - y - search direction and length - x - the new candidate iterate - - Output Parameters: - y - proposed step (search direction and length) (possibly changed) - x - current iterate (possibly modified) - -*/ -PetscErrorCode -PostCheck(SNESLineSearch linesearch, Vec xcurrent, Vec y, Vec x, PetscBool *changed_y, PetscBool *changed_x, void *ctx) -{ - PetscErrorCode ierr; - PetscInt i, iter, xs, xm; - StepCheckCtx *check; - AppCtx *user; - PetscScalar *xa, *xa_last, tmp; - PetscReal rdiff; - DM da; - SNES snes; - - PetscFunctionBeginUser; - *changed_x = PETSC_FALSE; - *changed_y = PETSC_FALSE; - - ierr = SNESLineSearchGetSNES(linesearch, &snes); CHKERRQ(ierr); - check = (StepCheckCtx *) ctx; - user = check->user; - ierr = SNESGetIterationNumber(snes, &iter); CHKERRQ(ierr); - ierr = SNESLineSearchGetPreCheck(linesearch, NULL, (void **) &check); CHKERRQ(ierr); - - /* iteration 1 indicates we are working on the second iteration */ - if (iter > 0) - { - da = user->da; - ierr = PetscPrintf(PETSC_COMM_WORLD, "Checking candidate step at iteration %D with tolerance %g\n", iter, (double) check->tolerance); CHKERRQ(ierr); - - /* Access local array data */ - ierr = DMDAVecGetArray(da, check->last_step, &xa_last); CHKERRQ(ierr); - ierr = DMDAVecGetArray(da, x, &xa); CHKERRQ(ierr); - ierr = DMDAGetCorners(da, &xs, NULL, NULL, &xm, NULL, NULL); CHKERRQ(ierr); - - /* - If we fail the user-defined check for validity of the candidate iterate, - then modify the iterate as we like. (Note that the particular modification - below is intended simply to demonstrate how to manipulate this data, not - as a meaningful or appropriate choice.) - */ - for (i = xs; i < xs+xm; i++) - { - if (!PetscAbsScalar(xa[i])) - rdiff = 2*check->tolerance; - else - rdiff = PetscAbsScalar((xa[i] - xa_last[i])/xa[i]); - if (rdiff > check->tolerance) - { - tmp = xa[i]; - xa[i] = .5*(xa[i] + xa_last[i]); - *changed_x = PETSC_TRUE; - ierr = PetscPrintf(PETSC_COMM_WORLD, " Altering entry %D: x=%g, x_last=%g, diff=%g, x_new=%g\n", - i, (double) PetscAbsScalar(tmp), (double) PetscAbsScalar(xa_last[i]), (double) rdiff, (double) PetscAbsScalar(xa[i])); CHKERRQ(ierr); - } - } - ierr = DMDAVecRestoreArray(da, check->last_step, &xa_last); CHKERRQ(ierr); - ierr = DMDAVecRestoreArray(da, x, &xa); CHKERRQ(ierr); - } - ierr = VecCopy(x, check->last_step); CHKERRQ(ierr); - PetscFunctionReturn(0); -} - -/* ------------------------------------------------------------------- */ -#undef __FUNCT__ -#define __FUNCT__ "PostSetSubKSP" -/* - PostSetSubKSP - Optional user-defined routine that reset SubKSP options when hierarchical bjacobi PC is used - e.g, - mpiexec -n 8 ./ex3 -nox -n 10000 -ksp_type fgmres -pc_type bjacobi -pc_bjacobi_blocks 4 -sub_ksp_type gmres -sub_ksp_max_it 3 -post_setsubksp -sub_ksp_rtol 1.e-16 - Set by SNESLineSearchSetPostCheck(). - - Input Parameters: - linesearch - the LineSearch context - xcurrent - current solution - y - search direction and length - x - the new candidate iterate - - Output Parameters: - y - proposed step (search direction and length) (possibly changed) - x - current iterate (possibly modified) - -*/ -PetscErrorCode -PostSetSubKSP(SNESLineSearch linesearch, Vec xcurrent, Vec y, Vec x, PetscBool *changed_y, PetscBool *changed_x, void *ctx) -{ - PetscErrorCode ierr; - SetSubKSPCtx *check; - PetscInt iter, its, sub_its, maxit; - KSP ksp, sub_ksp, *sub_ksps; - PC pc; - PetscReal ksp_ratio; - SNES snes; - - PetscFunctionBeginUser; - ierr = SNESLineSearchGetSNES(linesearch, &snes); CHKERRQ(ierr); - check = (SetSubKSPCtx *) ctx; - ierr = SNESGetIterationNumber(snes, &iter); CHKERRQ(ierr); - ierr = SNESGetKSP(snes, &ksp); CHKERRQ(ierr); - ierr = KSPGetPC(ksp, &pc); CHKERRQ(ierr); - ierr = PCBJacobiGetSubKSP(pc, NULL, NULL, &sub_ksps); CHKERRQ(ierr); - sub_ksp = sub_ksps[0]; - ierr = KSPGetIterationNumber(ksp, &its); CHKERRQ(ierr); /* outer KSP iteration number */ - ierr = KSPGetIterationNumber(sub_ksp, &sub_its); CHKERRQ(ierr); /* inner KSP iteration number */ - - if (iter) - { - ierr = PetscPrintf(PETSC_COMM_WORLD, " ...PostCheck snes iteration %D, ksp_it %d %d, subksp_it %d\n", iter, check->its0, its, sub_its); CHKERRQ(ierr); - ksp_ratio = ((PetscReal) (its))/check->its0; - maxit = (PetscInt) (ksp_ratio*sub_its + 0.5); - if (maxit < 2) - maxit = 2; - ierr = KSPSetTolerances(sub_ksp, PETSC_DEFAULT, PETSC_DEFAULT, PETSC_DEFAULT, maxit); CHKERRQ(ierr); - ierr = PetscPrintf(PETSC_COMM_WORLD, " ...ksp_ratio %g, new maxit %d\n\n", ksp_ratio, maxit); CHKERRQ(ierr); - } - check->its0 = its; /* save current outer KSP iteration number */ - PetscFunctionReturn(0); -} - -/* ------------------------------------------------------------------- */ -/* - MatrixFreePreconditioner - This routine demonstrates the use of a - user-provided preconditioner. This code implements just the null - preconditioner, which of course is not recommended for general use. - - Input Parameters: - + pc - preconditioner - - x - input vector - - Output Parameter: - . y - preconditioned vector -*/ -PetscErrorCode -MatrixFreePreconditioner(PC pc, Vec x, Vec y) -{ - PetscErrorCode ierr; - ierr = VecCopy(x, y); CHKERRQ(ierr); - return 0; -} diff --git a/others/cpp/tests/test1.cc b/others/cpp/tests/test1.cc deleted file mode 100644 index b5d773ac2063744ef393486fb7ceae20590072aa..0000000000000000000000000000000000000000 --- a/others/cpp/tests/test1.cc +++ /dev/null @@ -1,81 +0,0 @@ -#include <iostream> -#include "dynare_cpp_driver.hh" -#include "DecisionRules.hh" - -DynareInfo *preprocessorOutput(void); -extern "C" { - void steadystate(double const *, double const *, double *, int *); - void FirstDerivatives(const double *y, double *x, int nb_row_x, double *params, double *steady_state, int it_, double *residual, double *g1, double *v2, double *v3); -} -main(int argc, char **argv) -{ - DynareInfo model_info; - - int endo_nbr = model_info.get_endo_nbr(); - int exo_nbr = model_info.get_exo_nbr(); - double *params = model_info.get_params_data(); - // Steady state - double *steady_state = new double[endo_nbr]; - int info; - steadystate(NULL, params, steady_state, &info); - for (int i = 0; i < endo_nbr; ++i) - std::cout << model_info.get_endo_name_by_index(i) << " " << steady_state[i] << "\n"; - - // 1st order approximation - double qz_criterium = 1.000001; - - vector<size_t> zeta_back = model_info.get_zeta_back(); - vector<size_t> zeta_fwrd = model_info.get_zeta_fwrd(); - vector<size_t> zeta_mixed = model_info.get_zeta_mixed(); - vector<size_t> zeta_static = model_info.get_zeta_static(); - int nfwrd = zeta_fwrd.size(); - int nback = zeta_back.size(); - int nmixed = zeta_mixed.size(); - int nstatic = zeta_static.size(); - int sdyn = nfwrd + nback + 2*nmixed; - - int jacob_cols = sdyn + endo_nbr + exo_nbr; - - double *exo_steady_state = new double[exo_nbr]; - double *jacob_data = new double[endo_nbr*jacob_cols]; - - std::cout << endo_nbr << " " << jacob_cols << endl; - - FirstDerivatives(steady_state, exo_steady_state, 0, params, steady_state, 1, NULL, jacob_data, NULL, NULL); - - std::cout << "g1[44] = " << jacob_data[44] << endl; - - DecisionRules dr(endo_nbr, exo_nbr, zeta_fwrd, zeta_back, zeta_mixed, - zeta_static, qz_criterium); - - std::cout << "g1[44] = " << jacob_data[44] << endl; - - int jacobian_col_nbr = sdyn + endo_nbr + exo_nbr; - std::cout << "g1[44] = " << jacob_data[44] << endl; - MatrixView jacob_tmp(jacob_data, endo_nbr, jacobian_col_nbr, endo_nbr); - std::cout << "g1[44] = " << jacob_data[44] << endl; - std::cout << "jacob_tmp(2,7) = "<< jacob_tmp(2, 7) << endl; - - Matrix jacobian(endo_nbr, jacobian_col_nbr), g_y(endo_nbr, nback+nmixed), g_u(endo_nbr, exo_nbr); - jacobian = jacob_tmp; - - try - { - dr.compute(jacobian, g_y, g_u); - } - catch (GeneralizedSchurDecomposition::GSDException &e) - { - std::cerr << e << std::endl; - } - catch (DecisionRules::BlanchardKahnException &e) - { - std::cerr << e << std::endl; - } - - Vector eig_real(sdyn), eig_cmplx(sdyn); - dr.getGeneralizedEigenvalues(eig_real, eig_cmplx); - std::cout << "Eigenvalues (real part): " << eig_real - << "Eigenvalues (complex part): " << eig_cmplx << std::endl - << "g_y = " << std::endl << g_y << std::endl - << "g_u = " << std::endl << g_u; -}