Skip to content

Commit

Permalink
move max_tries outside with default Inf
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwang15 committed Jul 19, 2024
1 parent 9e20fa9 commit 72a8f0e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions R/estimate.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ estimate.BSVARSIGN = function(specification, S, thin = 1, show_progress = TRUE)
prior = specification$prior$get_prior()
identification = specification$identification$get_identification()
max_tries = identification$max_tries
max_tries = ifelse(max_tries == Inf, 0, max_tries)
data_matrices = specification$data_matrices$get_data_matrices()
p = specification$p

Expand Down
10 changes: 5 additions & 5 deletions R/specify.R
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ specify_identification_bsvarSIGN = R6::R6Class(
sign_relation = matrix(),
#' @field max_tries a positive integer with the maximum number of iterations
#' for finding a rotation matrix \eqn{Q} that would satisfy sign restrictions.
max_tries = 1,
max_tries = Inf,

#' @description
#' Create new identifying restrictions IdentificationBSVARSIGN.
Expand All @@ -505,7 +505,7 @@ specify_identification_bsvarSIGN = R6::R6Class(
#' @param max_tries a positive integer with the maximum number of iterations
#' for finding a rotation matrix \eqn{Q} that would satisfy sign restrictions.
#' @return Identifying restrictions IdentificationBSVARSIGN.
initialize = function(N, sign_irf, sign_narrative, sign_relation, max_tries = 1) {
initialize = function(N, sign_irf, sign_narrative, sign_relation, max_tries = Inf) {

missing_all = TRUE
if (missing(sign_irf)) {
Expand Down Expand Up @@ -570,7 +570,7 @@ specify_identification_bsvarSIGN = R6::R6Class(
#' contemporaneous relations \code{B} between reduced-form errors \code{E} and
#' structural shocks \code{U} where \code{BE=U}.
#' @param max_tries a positive integer with the maximum number of iterations
#' for finding a rotation matrix \eqn{Q} that would satisfy sign restrictions.
#' for finding a rotation matrix \eqn{Q} that would satisfy sign restrictions
set_identification = function(N, sign_irf, sign_narrative, sign_relation) {
B = matrix(FALSE, N, N)
B[lower.tri(B, diag = TRUE)] = TRUE
Expand Down Expand Up @@ -663,7 +663,7 @@ specify_bsvarSIGN = R6::R6Class(
#' contemporaneous relations \code{B} between reduced-form errors \code{E} and
#' structural shocks \code{U} where \code{BE=U}.
#' @param max_tries a positive integer with the maximum number of iterations
#' for finding a rotation matrix \eqn{Q} that would satisfy sign restrictions.
#' for finding a rotation matrix \eqn{Q} that would satisfy sign restrictions
#' @param exogenous a \code{(T+p)xd} matrix of exogenous variables.
#' @param stationary an \code{N} logical vector - its element set to \code{FALSE} sets
#' the prior mean for the autoregressive parameters of the \code{N}th equation to the white noise process,
Expand All @@ -675,7 +675,7 @@ specify_bsvarSIGN = R6::R6Class(
sign_irf,
sign_narrative,
sign_relation,
max_tries = 1,
max_tries = Inf,
exogenous = NULL,
stationary = rep(FALSE, ncol(data))
) {
Expand Down
4 changes: 2 additions & 2 deletions man/specify_bsvarSIGN.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/specify_identification_bsvarSIGN.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/bsvars_sign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Rcpp::List bsvar_sign_cpp(
int S_hyper = hypers.n_cols - 1;
int prior_nu = as<int>(prior["nu"]);
int post_nu = prior_nu + T;
int n_tries;

double w, mu, delta, lambda;

Expand Down Expand Up @@ -122,8 +123,9 @@ Rcpp::List bsvar_sign_cpp(
post_nu = as_scalar(result(3));

w = 0;
n_tries = 0;

while (w == 0) {
while (w == 0 and (n_tries < max_tries or max_tries == 0)) {

checkUserInterrupt();

Expand All @@ -134,7 +136,7 @@ Rcpp::List bsvar_sign_cpp(
h_invp = inv(trimatl(chol_Sigma)); // lower tri, h(Sigma) is upper tri

result = sample_Q(p, Y, X, B, h_invp, chol_Sigma, prior,
sign_irf, sign_narrative, sign_B, Z, max_tries);
sign_irf, sign_narrative, sign_B, Z, 1);
Q = result(0);
shocks = result(1);
w = as_scalar(result(2));
Expand Down

0 comments on commit 72a8f0e

Please sign in to comment.