diff --git a/src/bsvars_sign.cpp b/src/bsvars_sign.cpp index d1eed42..5d6b0fd 100644 --- a/src/bsvars_sign.cpp +++ b/src/bsvars_sign.cpp @@ -46,8 +46,8 @@ Rcpp::List bsvar_sign_cpp( vec prog_rep_points = arma::round(arma::linspace(0, S / num_threads, 50)); if (show_progress) { Rcout << "**************************************************|" << endl; - Rcout << " bsvarSIGNs: Bayesian Structural VAR with zero, |" << endl; - Rcout << " sign and narrative restrictions |" << endl; + Rcout << " bsvarSIGNs: Bayesian Structural VAR with sign, |" << endl; + Rcout << " zero and narrative restrictions |" << endl; Rcout << "**************************************************|" << endl; // Rcout << " Gibbs sampler for the SVAR model |" << endl; // Rcout << "**************************************************|" << endl; @@ -96,32 +96,35 @@ Rcpp::List bsvar_sign_cpp( // #pragma omp parallel for private(hyper, mu, delta, lambda, psi, prior_V, prior_S, Ystar, Xstar, Yplus, Xplus, result, post_B, post_V, post_S, Sigma, chol_Sigma, B, h_invp, Q, shocks, w) for (int s = 0; s < S; s++) { - w = 0; + hyper = hypers.col(randi(distr_param(0, S_hyper))); + mu = hyper(0); + delta = hyper(1); + lambda = hyper(2); + psi = hyper.rows(3, N + 2); + + // update Minnesota prior + prior_V = diagmat(prior_v % join_vert(lambda * lambda * repmat(1 / psi, p, 1), + ones(K - N * p))); + prior_S = diagmat(psi); + + // update dummy observation prior + Ystar = join_vert(Ysoc / mu, Ysur / delta); + Xstar = join_vert(Xsoc / mu, Xsur / delta); + Yplus = join_vert(Ystar, Y); + Xplus = join_vert(Xstar, X); + + // posterior parameters + result = niw_cpp(Yplus, Xplus, prior_B, prior_V, prior_S, prior_nu); + post_B = result(0); + post_V = result(1); + post_S = result(2); + post_nu = as_scalar(result(3)); + + w = 0; + while (w == 0) { - hyper = hypers.col(randi(distr_param(0, S_hyper))); - mu = hyper(0); - delta = hyper(1); - lambda = hyper(2); - psi = hyper.rows(3, N + 2); - - // update Minnesota prior - prior_V = diagmat(prior_v % - join_vert(lambda * lambda * repmat(1 / psi, p, 1), - ones(K - N * p))); - prior_S = diagmat(psi); - // update dummy observation prior - Ystar = join_vert(Ysoc / mu, Ysur / delta); - Xstar = join_vert(Xsoc / mu, Xsur / delta); - Yplus = join_vert(Ystar, Y); - Xplus = join_vert(Xstar, X); - - // posterior parameters - result = niw_cpp(Yplus, Xplus, prior_B, prior_V, prior_S, prior_nu); - post_B = result(0); - post_V = result(1); - post_S = result(2); - post_nu = as_scalar(result(3)); + checkUserInterrupt(); // sample reduced-form parameters Sigma = iwishrnd(post_S, post_nu); @@ -145,9 +148,6 @@ Rcpp::List bsvar_sign_cpp( posterior_Theta0.slice(s) = chol_Sigma * Q; posterior_shocks.slice(s) = shocks; - // Check for user interrupts - if (s % 1 == 0) checkUserInterrupt(); - // Increment progress bar if (any(prog_rep_points == s)) bar.increment(); diff --git a/src/restrictions_narrative.cpp b/src/restrictions_narrative.cpp index ea4a57a..2090de1 100644 --- a/src/restrictions_narrative.cpp +++ b/src/restrictions_narrative.cpp @@ -81,7 +81,7 @@ double weight_narrative( const int M = 1e+3; // number of draws to approximate normal distribution - double n_success = 1.0e-6; + double n_success = 1e-6; cube Z(irf.n_rows, sign_narrative.col(5).max() + 1, M, fill::randn); // cube Z(irf.n_rows, T, M, fill::randn);