diff --git a/.gitignore b/.gitignore index 3a73f63..2b050fe 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,4 @@ rsconnect/ .Rdata .DS_Store .quarto +*.so diff --git a/DESCRIPTION b/DESCRIPTION index db25e45..9eec348 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,7 +14,7 @@ Imports: Rcpp (>= 1.0.12), RcppArmadillo, RcppProgress -LinkingTo: Rcpp, RcppArmadillo, RcppProgress +LinkingTo: bsvars, Rcpp, RcppArmadillo, RcppProgress RoxygenNote: 7.3.0 Depends: R (>= 2.10) diff --git a/inst/include/bsvarSIGNs_RcppExports.h b/inst/include/bsvarSIGNs_RcppExports.h index 335108c..ebfdcc3 100644 --- a/inst/include/bsvarSIGNs_RcppExports.h +++ b/inst/include/bsvarSIGNs_RcppExports.h @@ -25,108 +25,6 @@ namespace bsvarSIGNs { } } - inline arma::mat orthogonal_complement_matrix_TW(const arma::mat& x) { - typedef SEXP(*Ptr_orthogonal_complement_matrix_TW)(SEXP); - static Ptr_orthogonal_complement_matrix_TW p_orthogonal_complement_matrix_TW = NULL; - if (p_orthogonal_complement_matrix_TW == NULL) { - validateSignature("arma::mat(*orthogonal_complement_matrix_TW)(const arma::mat&)"); - p_orthogonal_complement_matrix_TW = (Ptr_orthogonal_complement_matrix_TW)R_GetCCallable("bsvarSIGNs", "_bsvarSIGNs_orthogonal_complement_matrix_TW"); - } - RObject rcpp_result_gen; - { - RNGScope RCPP_rngScope_gen; - rcpp_result_gen = p_orthogonal_complement_matrix_TW(Shield(Rcpp::wrap(x))); - } - if (rcpp_result_gen.inherits("interrupted-error")) - throw Rcpp::internal::InterruptedException(); - if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) - throw Rcpp::LongjumpException(rcpp_result_gen); - if (rcpp_result_gen.inherits("try-error")) - throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); - return Rcpp::as(rcpp_result_gen); - } - - inline std::string ordinal(int n) { - typedef SEXP(*Ptr_ordinal)(SEXP); - static Ptr_ordinal p_ordinal = NULL; - if (p_ordinal == NULL) { - validateSignature("std::string(*ordinal)(int)"); - p_ordinal = (Ptr_ordinal)R_GetCCallable("bsvarSIGNs", "_bsvarSIGNs_ordinal"); - } - RObject rcpp_result_gen; - { - RNGScope RCPP_rngScope_gen; - rcpp_result_gen = p_ordinal(Shield(Rcpp::wrap(n))); - } - if (rcpp_result_gen.inherits("interrupted-error")) - throw Rcpp::internal::InterruptedException(); - if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) - throw Rcpp::LongjumpException(rcpp_result_gen); - if (rcpp_result_gen.inherits("try-error")) - throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); - return Rcpp::as(rcpp_result_gen); - } - - inline void sample_hyperparameters(arma::mat& aux_hyper, const arma::mat& aux_B, const arma::mat& aux_A, const arma::field& VB, const Rcpp::List& prior) { - typedef SEXP(*Ptr_sample_hyperparameters)(SEXP,SEXP,SEXP,SEXP,SEXP); - static Ptr_sample_hyperparameters p_sample_hyperparameters = NULL; - if (p_sample_hyperparameters == NULL) { - validateSignature("void(*sample_hyperparameters)(arma::mat&,const arma::mat&,const arma::mat&,const arma::field&,const Rcpp::List&)"); - p_sample_hyperparameters = (Ptr_sample_hyperparameters)R_GetCCallable("bsvarSIGNs", "_bsvarSIGNs_sample_hyperparameters"); - } - RObject rcpp_result_gen; - { - RNGScope RCPP_rngScope_gen; - rcpp_result_gen = p_sample_hyperparameters(Shield(Rcpp::wrap(aux_hyper)), Shield(Rcpp::wrap(aux_B)), Shield(Rcpp::wrap(aux_A)), Shield(Rcpp::wrap(VB)), Shield(Rcpp::wrap(prior))); - } - if (rcpp_result_gen.inherits("interrupted-error")) - throw Rcpp::internal::InterruptedException(); - if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) - throw Rcpp::LongjumpException(rcpp_result_gen); - if (rcpp_result_gen.inherits("try-error")) - throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); - } - - inline void sample_A_homosk1(arma::mat& aux_A, const arma::mat& aux_B, const arma::mat& aux_hyper, const arma::mat& Y, const arma::mat& X, const Rcpp::List& prior) { - typedef SEXP(*Ptr_sample_A_homosk1)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP); - static Ptr_sample_A_homosk1 p_sample_A_homosk1 = NULL; - if (p_sample_A_homosk1 == NULL) { - validateSignature("void(*sample_A_homosk1)(arma::mat&,const arma::mat&,const arma::mat&,const arma::mat&,const arma::mat&,const Rcpp::List&)"); - p_sample_A_homosk1 = (Ptr_sample_A_homosk1)R_GetCCallable("bsvarSIGNs", "_bsvarSIGNs_sample_A_homosk1"); - } - RObject rcpp_result_gen; - { - RNGScope RCPP_rngScope_gen; - rcpp_result_gen = p_sample_A_homosk1(Shield(Rcpp::wrap(aux_A)), Shield(Rcpp::wrap(aux_B)), Shield(Rcpp::wrap(aux_hyper)), Shield(Rcpp::wrap(Y)), Shield(Rcpp::wrap(X)), Shield(Rcpp::wrap(prior))); - } - if (rcpp_result_gen.inherits("interrupted-error")) - throw Rcpp::internal::InterruptedException(); - if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) - throw Rcpp::LongjumpException(rcpp_result_gen); - if (rcpp_result_gen.inherits("try-error")) - throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); - } - - inline void sample_B_homosk1(arma::mat& aux_B, const arma::mat& aux_A, const arma::mat& aux_hyper, const arma::mat& Y, const arma::mat& X, const Rcpp::List& prior, const arma::field& VB) { - typedef SEXP(*Ptr_sample_B_homosk1)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP); - static Ptr_sample_B_homosk1 p_sample_B_homosk1 = NULL; - if (p_sample_B_homosk1 == NULL) { - validateSignature("void(*sample_B_homosk1)(arma::mat&,const arma::mat&,const arma::mat&,const arma::mat&,const arma::mat&,const Rcpp::List&,const arma::field&)"); - p_sample_B_homosk1 = (Ptr_sample_B_homosk1)R_GetCCallable("bsvarSIGNs", "_bsvarSIGNs_sample_B_homosk1"); - } - RObject rcpp_result_gen; - { - RNGScope RCPP_rngScope_gen; - rcpp_result_gen = p_sample_B_homosk1(Shield(Rcpp::wrap(aux_B)), Shield(Rcpp::wrap(aux_A)), Shield(Rcpp::wrap(aux_hyper)), Shield(Rcpp::wrap(Y)), Shield(Rcpp::wrap(X)), Shield(Rcpp::wrap(prior)), Shield(Rcpp::wrap(VB))); - } - if (rcpp_result_gen.inherits("interrupted-error")) - throw Rcpp::internal::InterruptedException(); - if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) - throw Rcpp::LongjumpException(rcpp_result_gen); - if (rcpp_result_gen.inherits("try-error")) - throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); - } - inline Rcpp::List bsvar_sign_cpp(const int& S, const arma::mat& Y, const arma::mat& X, const arma::field& VB, const Rcpp::List& prior, const Rcpp::List& starting_values, const int thin = 100, const bool show_progress = true) { typedef SEXP(*Ptr_bsvar_sign_cpp)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP); static Ptr_bsvar_sign_cpp p_bsvar_sign_cpp = NULL; diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index c367e7e..8866417 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -14,188 +14,6 @@ Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); #endif -// orthogonal_complement_matrix_TW -arma::mat orthogonal_complement_matrix_TW(const arma::mat& x); -static SEXP _bsvarSIGNs_orthogonal_complement_matrix_TW_try(SEXP xSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::traits::input_parameter< const arma::mat& >::type x(xSEXP); - rcpp_result_gen = Rcpp::wrap(orthogonal_complement_matrix_TW(x)); - return rcpp_result_gen; -END_RCPP_RETURN_ERROR -} -RcppExport SEXP _bsvarSIGNs_orthogonal_complement_matrix_TW(SEXP xSEXP) { - SEXP rcpp_result_gen; - { - Rcpp::RNGScope rcpp_rngScope_gen; - rcpp_result_gen = PROTECT(_bsvarSIGNs_orthogonal_complement_matrix_TW_try(xSEXP)); - } - Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); - if (rcpp_isInterrupt_gen) { - UNPROTECT(1); - Rf_onintr(); - } - bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); - if (rcpp_isLongjump_gen) { - Rcpp::internal::resumeJump(rcpp_result_gen); - } - Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); - if (rcpp_isError_gen) { - SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); - UNPROTECT(1); - Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); - } - UNPROTECT(1); - return rcpp_result_gen; -} -// ordinal -std::string ordinal(int n); -static SEXP _bsvarSIGNs_ordinal_try(SEXP nSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::traits::input_parameter< int >::type n(nSEXP); - rcpp_result_gen = Rcpp::wrap(ordinal(n)); - return rcpp_result_gen; -END_RCPP_RETURN_ERROR -} -RcppExport SEXP _bsvarSIGNs_ordinal(SEXP nSEXP) { - SEXP rcpp_result_gen; - { - Rcpp::RNGScope rcpp_rngScope_gen; - rcpp_result_gen = PROTECT(_bsvarSIGNs_ordinal_try(nSEXP)); - } - Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); - if (rcpp_isInterrupt_gen) { - UNPROTECT(1); - Rf_onintr(); - } - bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); - if (rcpp_isLongjump_gen) { - Rcpp::internal::resumeJump(rcpp_result_gen); - } - Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); - if (rcpp_isError_gen) { - SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); - UNPROTECT(1); - Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); - } - UNPROTECT(1); - return rcpp_result_gen; -} -// sample_hyperparameters -void sample_hyperparameters(arma::mat& aux_hyper, const arma::mat& aux_B, const arma::mat& aux_A, const arma::field& VB, const Rcpp::List& prior); -static SEXP _bsvarSIGNs_sample_hyperparameters_try(SEXP aux_hyperSEXP, SEXP aux_BSEXP, SEXP aux_ASEXP, SEXP VBSEXP, SEXP priorSEXP) { -BEGIN_RCPP - Rcpp::traits::input_parameter< arma::mat& >::type aux_hyper(aux_hyperSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type aux_B(aux_BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type aux_A(aux_ASEXP); - Rcpp::traits::input_parameter< const arma::field& >::type VB(VBSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type prior(priorSEXP); - sample_hyperparameters(aux_hyper, aux_B, aux_A, VB, prior); - return R_NilValue; -END_RCPP_RETURN_ERROR -} -RcppExport SEXP _bsvarSIGNs_sample_hyperparameters(SEXP aux_hyperSEXP, SEXP aux_BSEXP, SEXP aux_ASEXP, SEXP VBSEXP, SEXP priorSEXP) { - SEXP rcpp_result_gen; - { - Rcpp::RNGScope rcpp_rngScope_gen; - rcpp_result_gen = PROTECT(_bsvarSIGNs_sample_hyperparameters_try(aux_hyperSEXP, aux_BSEXP, aux_ASEXP, VBSEXP, priorSEXP)); - } - Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); - if (rcpp_isInterrupt_gen) { - UNPROTECT(1); - Rf_onintr(); - } - bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); - if (rcpp_isLongjump_gen) { - Rcpp::internal::resumeJump(rcpp_result_gen); - } - Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); - if (rcpp_isError_gen) { - SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); - UNPROTECT(1); - Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); - } - UNPROTECT(1); - return rcpp_result_gen; -} -// sample_A_homosk1 -void sample_A_homosk1(arma::mat& aux_A, const arma::mat& aux_B, const arma::mat& aux_hyper, const arma::mat& Y, const arma::mat& X, const Rcpp::List& prior); -static SEXP _bsvarSIGNs_sample_A_homosk1_try(SEXP aux_ASEXP, SEXP aux_BSEXP, SEXP aux_hyperSEXP, SEXP YSEXP, SEXP XSEXP, SEXP priorSEXP) { -BEGIN_RCPP - Rcpp::traits::input_parameter< arma::mat& >::type aux_A(aux_ASEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type aux_B(aux_BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type aux_hyper(aux_hyperSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type Y(YSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type prior(priorSEXP); - sample_A_homosk1(aux_A, aux_B, aux_hyper, Y, X, prior); - return R_NilValue; -END_RCPP_RETURN_ERROR -} -RcppExport SEXP _bsvarSIGNs_sample_A_homosk1(SEXP aux_ASEXP, SEXP aux_BSEXP, SEXP aux_hyperSEXP, SEXP YSEXP, SEXP XSEXP, SEXP priorSEXP) { - SEXP rcpp_result_gen; - { - Rcpp::RNGScope rcpp_rngScope_gen; - rcpp_result_gen = PROTECT(_bsvarSIGNs_sample_A_homosk1_try(aux_ASEXP, aux_BSEXP, aux_hyperSEXP, YSEXP, XSEXP, priorSEXP)); - } - Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); - if (rcpp_isInterrupt_gen) { - UNPROTECT(1); - Rf_onintr(); - } - bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); - if (rcpp_isLongjump_gen) { - Rcpp::internal::resumeJump(rcpp_result_gen); - } - Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); - if (rcpp_isError_gen) { - SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); - UNPROTECT(1); - Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); - } - UNPROTECT(1); - return rcpp_result_gen; -} -// sample_B_homosk1 -void sample_B_homosk1(arma::mat& aux_B, const arma::mat& aux_A, const arma::mat& aux_hyper, const arma::mat& Y, const arma::mat& X, const Rcpp::List& prior, const arma::field& VB); -static SEXP _bsvarSIGNs_sample_B_homosk1_try(SEXP aux_BSEXP, SEXP aux_ASEXP, SEXP aux_hyperSEXP, SEXP YSEXP, SEXP XSEXP, SEXP priorSEXP, SEXP VBSEXP) { -BEGIN_RCPP - Rcpp::traits::input_parameter< arma::mat& >::type aux_B(aux_BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type aux_A(aux_ASEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type aux_hyper(aux_hyperSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type Y(YSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type prior(priorSEXP); - Rcpp::traits::input_parameter< const arma::field& >::type VB(VBSEXP); - sample_B_homosk1(aux_B, aux_A, aux_hyper, Y, X, prior, VB); - return R_NilValue; -END_RCPP_RETURN_ERROR -} -RcppExport SEXP _bsvarSIGNs_sample_B_homosk1(SEXP aux_BSEXP, SEXP aux_ASEXP, SEXP aux_hyperSEXP, SEXP YSEXP, SEXP XSEXP, SEXP priorSEXP, SEXP VBSEXP) { - SEXP rcpp_result_gen; - { - Rcpp::RNGScope rcpp_rngScope_gen; - rcpp_result_gen = PROTECT(_bsvarSIGNs_sample_B_homosk1_try(aux_BSEXP, aux_ASEXP, aux_hyperSEXP, YSEXP, XSEXP, priorSEXP, VBSEXP)); - } - Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); - if (rcpp_isInterrupt_gen) { - UNPROTECT(1); - Rf_onintr(); - } - bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); - if (rcpp_isLongjump_gen) { - Rcpp::internal::resumeJump(rcpp_result_gen); - } - Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); - if (rcpp_isError_gen) { - SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); - UNPROTECT(1); - Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); - } - UNPROTECT(1); - return rcpp_result_gen; -} // bsvar_sign_cpp Rcpp::List bsvar_sign_cpp(const int& S, const arma::mat& Y, const arma::mat& X, const arma::field& VB, const Rcpp::List& prior, const Rcpp::List& starting_values, const int thin, const bool show_progress); static SEXP _bsvarSIGNs_bsvar_sign_cpp_try(SEXP SSEXP, SEXP YSEXP, SEXP XSEXP, SEXP VBSEXP, SEXP priorSEXP, SEXP starting_valuesSEXP, SEXP thinSEXP, SEXP show_progressSEXP) { @@ -255,11 +73,6 @@ END_RCPP static int _bsvarSIGNs_RcppExport_validate(const char* sig) { static std::set signatures; if (signatures.empty()) { - signatures.insert("arma::mat(*orthogonal_complement_matrix_TW)(const arma::mat&)"); - signatures.insert("std::string(*ordinal)(int)"); - signatures.insert("void(*sample_hyperparameters)(arma::mat&,const arma::mat&,const arma::mat&,const arma::field&,const Rcpp::List&)"); - signatures.insert("void(*sample_A_homosk1)(arma::mat&,const arma::mat&,const arma::mat&,const arma::mat&,const arma::mat&,const Rcpp::List&)"); - signatures.insert("void(*sample_B_homosk1)(arma::mat&,const arma::mat&,const arma::mat&,const arma::mat&,const arma::mat&,const Rcpp::List&,const arma::field&)"); signatures.insert("Rcpp::List(*bsvar_sign_cpp)(const int&,const arma::mat&,const arma::mat&,const arma::field&,const Rcpp::List&,const Rcpp::List&,const int,const bool)"); } return signatures.find(sig) != signatures.end(); @@ -267,22 +80,12 @@ static int _bsvarSIGNs_RcppExport_validate(const char* sig) { // registerCCallable (register entry points for exported C++ functions) RcppExport SEXP _bsvarSIGNs_RcppExport_registerCCallable() { - R_RegisterCCallable("bsvarSIGNs", "_bsvarSIGNs_orthogonal_complement_matrix_TW", (DL_FUNC)_bsvarSIGNs_orthogonal_complement_matrix_TW_try); - R_RegisterCCallable("bsvarSIGNs", "_bsvarSIGNs_ordinal", (DL_FUNC)_bsvarSIGNs_ordinal_try); - R_RegisterCCallable("bsvarSIGNs", "_bsvarSIGNs_sample_hyperparameters", (DL_FUNC)_bsvarSIGNs_sample_hyperparameters_try); - R_RegisterCCallable("bsvarSIGNs", "_bsvarSIGNs_sample_A_homosk1", (DL_FUNC)_bsvarSIGNs_sample_A_homosk1_try); - R_RegisterCCallable("bsvarSIGNs", "_bsvarSIGNs_sample_B_homosk1", (DL_FUNC)_bsvarSIGNs_sample_B_homosk1_try); R_RegisterCCallable("bsvarSIGNs", "_bsvarSIGNs_bsvar_sign_cpp", (DL_FUNC)_bsvarSIGNs_bsvar_sign_cpp_try); R_RegisterCCallable("bsvarSIGNs", "_bsvarSIGNs_RcppExport_validate", (DL_FUNC)_bsvarSIGNs_RcppExport_validate); return R_NilValue; } static const R_CallMethodDef CallEntries[] = { - {"_bsvarSIGNs_orthogonal_complement_matrix_TW", (DL_FUNC) &_bsvarSIGNs_orthogonal_complement_matrix_TW, 1}, - {"_bsvarSIGNs_ordinal", (DL_FUNC) &_bsvarSIGNs_ordinal, 1}, - {"_bsvarSIGNs_sample_hyperparameters", (DL_FUNC) &_bsvarSIGNs_sample_hyperparameters, 5}, - {"_bsvarSIGNs_sample_A_homosk1", (DL_FUNC) &_bsvarSIGNs_sample_A_homosk1, 6}, - {"_bsvarSIGNs_sample_B_homosk1", (DL_FUNC) &_bsvarSIGNs_sample_B_homosk1, 7}, {"_bsvarSIGNs_bsvar_sign_cpp", (DL_FUNC) &_bsvarSIGNs_bsvar_sign_cpp, 8}, {"_bsvarSIGNs_matnrnd_cpp", (DL_FUNC) &_bsvarSIGNs_matnrnd_cpp, 3}, {"_bsvarSIGNs_RcppExport_registerCCallable", (DL_FUNC) &_bsvarSIGNs_RcppExport_registerCCallable, 0}, diff --git a/src/bsvarSIGNs.so b/src/bsvarSIGNs.so index c489d31..7c8edff 100755 Binary files a/src/bsvarSIGNs.so and b/src/bsvarSIGNs.so differ diff --git a/src/bsvars_in_sign.cpp b/src/bsvars_in_sign.cpp deleted file mode 100644 index cd429de..0000000 --- a/src/bsvars_in_sign.cpp +++ /dev/null @@ -1,285 +0,0 @@ - -#include -#include "progress.hpp" -#include "Rcpp/Rmath.h" - -using namespace Rcpp; -using namespace arma; - - -// [[Rcpp::interfaces(cpp)]] -// [[Rcpp::export]] -arma::mat orthogonal_complement_matrix_TW (const arma::mat& x) { - // # x is a mxn matrix and m>n - // # the function returns a mx(m-n) matrix, out, that is an orthogonal complement of x, i.e.: - // # t(x)%*%out = 0 and det(cbind(x,out))!=0 - int n_nrow = x.n_rows; - int n_ncol = x.n_cols; - mat Q; - mat R; - qr(Q, R, x); - mat ocm = Q.tail_cols(n_nrow-n_ncol); - return ocm; -} // END orthogonal_complement_matrix_TW - - -// [[Rcpp::interfaces(cpp)]] -// [[Rcpp::export]] -std::string ordinal( - int n -) { - std::string suffix; - if (n % 10 == 1 && n % 100 != 11) { - suffix = "st"; - } else if (n % 10 == 2 && n % 100 != 12) { - suffix = "nd"; - } else if (n % 10 == 3 && n % 100 != 13) { - suffix = "rd"; - } else { - suffix = "th"; - } - return std::to_string(n) + suffix; -} // END ordinal - - -// [[Rcpp::interfaces(cpp)]] -// [[Rcpp::export]] -void sample_hyperparameters ( - arma::mat& aux_hyper, // (2*N+1) x 2 :: col 0 for B, col 1 for A - const arma::mat& aux_B, // NxN - const arma::mat& aux_A, - const arma::field& VB, - const Rcpp::List& prior -) { - // the function returns aux_hyper by reference (filling it with a new draw) - - const int N = aux_B.n_rows; - const int K = aux_A.n_cols; - - double prior_hyper_nu_B = as(prior["hyper_nu_B"]); - double prior_hyper_a_B = as(prior["hyper_a_B"]); - double prior_hyper_s_BB = as(prior["hyper_s_BB"]); - double prior_hyper_nu_BB = as(prior["hyper_nu_BB"]); - - double prior_hyper_nu_A = as(prior["hyper_nu_A"]); - double prior_hyper_a_A = as(prior["hyper_a_A"]); - double prior_hyper_s_AA = as(prior["hyper_s_AA"]); - double prior_hyper_nu_AA = as(prior["hyper_nu_AA"]); - - mat prior_A = as(prior["A"]); - mat prior_A_V_inv = as(prior["A_V_inv"]); - mat prior_B_V_inv = as(prior["B_V_inv"]); - - // aux_B - related hyper-parameters - vec ss_tmp = aux_hyper.submat(N, 0, 2 * N - 1, 0); - double scale_tmp = prior_hyper_s_BB + 2 * sum(ss_tmp); - double shape_tmp = prior_hyper_nu_BB + 2 * N * prior_hyper_a_B; - aux_hyper(2 * N, 0) = scale_tmp / R::rchisq(shape_tmp); - - // aux_A - related hyper-parameters - ss_tmp = aux_hyper.submat(N, 1, 2 * N - 1, 1); - scale_tmp = prior_hyper_s_AA + 2 * sum(ss_tmp); - shape_tmp = prior_hyper_nu_AA + 2 * N * prior_hyper_a_A; - aux_hyper(2 * N, 1) = scale_tmp / R::rchisq(shape_tmp); - - for (int n=0; n(prior["A"]); - mat prior_A_Vinv = as(prior["A_V_inv"]); - rowvec zerosA(K); - - for (int n=0; n& VB // restrictions on B0 -) { - // the function changes the value of aux_B by reference - const int N = aux_B.n_rows; - const int T = Y.n_cols; - - const int posterior_nu = T + as(prior["B_nu"]); - mat prior_SS_inv = as(prior["B_V_inv"]); - mat shocks = Y - aux_A * X; - mat posterior_SS_inv = shocks * shocks.t(); - - for (int n=0; n1){ - vec nn(rn-1, fill::randn); - nn *= pow(posterior_nu, -0.5); - alpha.rows(1,rn-1) = nn; - } - rowvec b0n = alpha.t() * Wn * Un; - aux_B.row(n) = b0n * VB(n); - } // END n loop -} // END sample_B_homosk1 - - -// [[Rcpp::interfaces(cpp)]] -// [[Rcpp::export]] -Rcpp::List bsvar_sign_cpp( - const int& S, // number of draws from the posterior - const arma::mat& Y, // NxT dependent variables - const arma::mat& X, // KxT dependent variables - const arma::field& VB, // N-list - const Rcpp::List& prior, // a list of priors - const Rcpp::List& starting_values, // a list of starting values - const int thin = 100, // introduce thinning - const bool show_progress = true -) { - - std::string oo = ""; - if ( thin != 1 ) { - oo = ordinal(thin) + " "; - } - - // Progress bar setup - vec prog_rep_points = arma::round(arma::linspace(0, S, 50)); - if (show_progress) { - Rcout << "**************************************************|" << endl; - Rcout << "bsvars: Bayesian Structural Vector Autoregressions|" << endl; - Rcout << "**************************************************|" << endl; - Rcout << " Gibbs sampler for the SVAR model |" << endl; - Rcout << "**************************************************|" << endl; - Rcout << " Progress of the MCMC simulation for " << S << " draws" << endl; - Rcout << " Every " << oo << "draw is saved via MCMC thinning" << endl; - Rcout << " Press Esc to interrupt the computations" << endl; - Rcout << "**************************************************|" << endl; - } - Progress p(50, show_progress); - - const int N = Y.n_rows; - const int K = X.n_rows; - - mat aux_B = as(starting_values["B"]); - mat aux_A = as(starting_values["A"]); - mat aux_hyper = as(starting_values["hyper"]); - - const int SS = floor(S / thin); - - cube posterior_B(N, N, SS); - cube posterior_A(N, K, SS); - cube posterior_hyper(2 * N + 1, 2, SS); - - int ss = 0; - - for (int s=0; s - - -arma::mat orthogonal_complement_matrix_TW (const arma::mat& x); - -std::string ordinal(int n); - -void sample_hyperparameters ( - arma::mat& aux_hyper, // (2*N+1) x 2 :: col 0 for B, col 1 for A - const arma::mat& aux_B, // NxN - const arma::mat& aux_A, - const arma::field& VB, - const Rcpp::List& prior -); - - -void sample_A_homosk1 ( - arma::mat& aux_A, // NxK - const arma::mat& aux_B, // NxN - const arma::mat& aux_hyper, // (2*N+1) x 2 :: col 0 for B, col 1 for A - const arma::mat& Y, // NxT dependent variables - const arma::mat& X, // KxT dependent variables - const Rcpp::List& prior // a list of priors - original dimensions -); - - -void sample_B_homosk1 ( - arma::mat& aux_B, // NxN - const arma::mat& aux_A, // NxK - const arma::mat& aux_hyper, // (2*N+1) x 2 :: col 0 for B, col 1 for A - const arma::mat& Y, // NxT dependent variables - const arma::mat& X, // KxT dependent variables - const Rcpp::List& prior, // a list of priors - original dimensions - const arma::field& VB // restrictions on B0 -); - - -Rcpp::List bsvar_cpp( - const int& S, // number of draws from the posterior - const arma::mat& Y, // NxT dependent variables - const arma::mat& X, // KxT dependent variables - const arma::field& VB, // N-list - const Rcpp::List& prior, // a list of priors - const Rcpp::List& starting_values, // a list of starting values - const int thin = 100, // introduce thinning - const bool show_progress = true -); - -#endif // _BSVARS_IN_SIGN_H_ \ No newline at end of file diff --git a/src/bsvars_sign.cpp b/src/bsvars_sign.cpp new file mode 100644 index 0000000..a3a70d1 --- /dev/null +++ b/src/bsvars_sign.cpp @@ -0,0 +1,91 @@ + +#include +#include "progress.hpp" +#include "Rcpp/Rmath.h" + +#include + +using namespace Rcpp; +using namespace arma; + + +// [[Rcpp::interfaces(cpp)]] +// [[Rcpp::export]] +Rcpp::List bsvar_sign_cpp( + const int& S, // number of draws from the posterior + const arma::mat& Y, // NxT dependent variables + const arma::mat& X, // KxT dependent variables + const arma::field& VB, // N-list + const Rcpp::List& prior, // a list of priors + const Rcpp::List& starting_values, // a list of starting values + const int thin = 100, // introduce thinning + const bool show_progress = true +) { + + std::string oo = ""; + if ( thin != 1 ) { + oo = bsvars::ordinal(thin) + " "; + } + + // Progress bar setup + vec prog_rep_points = arma::round(arma::linspace(0, S, 50)); + if (show_progress) { + Rcout << "**************************************************|" << endl; + Rcout << "bsvars: Bayesian Structural Vector Autoregressions|" << endl; + Rcout << "**************************************************|" << endl; + Rcout << " Gibbs sampler for the SVAR model |" << endl; + Rcout << "**************************************************|" << endl; + Rcout << " Progress of the MCMC simulation for " << S << " draws" << endl; + Rcout << " Every " << oo << "draw is saved via MCMC thinning" << endl; + Rcout << " Press Esc to interrupt the computations" << endl; + Rcout << "**************************************************|" << endl; + } + Progress p(50, show_progress); + + const int N = Y.n_rows; + const int K = X.n_rows; + + mat aux_B = as(starting_values["B"]); + mat aux_A = as(starting_values["A"]); + mat aux_hyper = as(starting_values["hyper"]); + + const int SS = floor(S / thin); + + cube posterior_B(N, N, SS); + cube posterior_A(N, K, SS); + cube posterior_hyper(2 * N + 1, 2, SS); + + int ss = 0; + + for (int s=0; s + + +Rcpp::List bsvar_cpp( + const int& S, // number of draws from the posterior + const arma::mat& Y, // NxT dependent variables + const arma::mat& X, // KxT dependent variables + const arma::field& VB, // N-list + const Rcpp::List& prior, // a list of priors + const Rcpp::List& starting_values, // a list of starting values + const int thin = 100, // introduce thinning + const bool show_progress = true +); + +#endif // _BSVARS_SIGN_H_ \ No newline at end of file