Skip to content

Commit 57a66c9

Browse files
committed
call hyper cpp functions in R
1 parent 2256561 commit 57a66c9

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ rsconnect/
5959
docs
6060
/doc/
6161
/Meta/
62+
63+
.vscode/

R/specify.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ specify_prior_bsvarSIGN = R6::R6Class(
429429
}
430430

431431
hyper = matrix(self$hyper[, ncol(self$hyper)])
432-
init = narrow_hyper(model, hyper)
432+
init = .Call(`_bsvarSIGNs_narrow_hyper`, model, hyper)
433433
prior = self$get_prior()
434434

435435
prior$B = t(prior$A)
@@ -440,15 +440,16 @@ specify_prior_bsvarSIGN = R6::R6Class(
440440

441441
result = stats::optim(
442442
init,
443-
\(x) -log_posterior_hyper(extend_hyper(hyper, model, matrix(x)),
444-
model, t(self$Y), t(self$X), prior),
443+
\(x) -.Call(`_bsvarSIGNs_log_posterior_hyper`,
444+
.Call(`_bsvarSIGNs_extend_hyper`, hyper, model, matrix(x)),
445+
model, t(self$Y), t(self$X), prior),
445446
method = 'L-BFGS-B',
446447
lower = rep(0, length(init)),
447448
upper = init * 100,
448449
hessian = TRUE
449450
)
450451

451-
mode = extend_hyper(hyper, model, matrix(result$par))
452+
mode = .Call(`_bsvarSIGNs_extend_hyper`, hyper, model, matrix(result$par))
452453
variance = result$hessian
453454

454455
if (length(init) == 1){
@@ -458,8 +459,8 @@ specify_prior_bsvarSIGN = R6::R6Class(
458459
variance = e$vectors %*% diag(as.vector(1 / abs(e$values))) %*% t(e$vectors)
459460
}
460461

461-
self$hyper = sample_hyper(S, burn_in, mode, model,
462-
t(self$Y), t(self$X), variance, prior)
462+
self$hyper = .Call(`_bsvarSIGNs_sample_hyper`, S, burn_in, mode, model,
463+
t(self$Y), t(self$X), variance, prior)
463464
self$hyper = self$hyper[, -(1:burn_in)]
464465
} # END estimate_hyper
465466

src/sample_hyper.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ double log_ml_dummy(
175175

176176

177177
// log posterior of hyper-parameters (up to a constant)
178-
// [[Rcpp::interfaces(cpp)]]
178+
// [[Rcpp::interfaces(r, cpp)]]
179179
// [[Rcpp::export]]
180180
double log_posterior_hyper(
181181
const arma::vec& hyper,
@@ -197,7 +197,7 @@ double log_posterior_hyper(
197197
}
198198

199199

200-
// [[Rcpp::interfaces(cpp)]]
200+
// [[Rcpp::interfaces(r, cpp)]]
201201
// [[Rcpp::export]]
202202
arma::mat extend_hyper(
203203
const arma::vec& init,
@@ -232,7 +232,7 @@ arma::mat extend_hyper(
232232
}
233233

234234

235-
// [[Rcpp::interfaces(cpp)]]
235+
// [[Rcpp::interfaces(r, cpp)]]
236236
// [[Rcpp::export]]
237237
arma::mat narrow_hyper(
238238
const arma::vec& model,
@@ -264,7 +264,7 @@ arma::mat narrow_hyper(
264264

265265

266266
// sample hyper-parameters
267-
// [[Rcpp::interfaces(cpp)]]
267+
// [[Rcpp::interfaces(r, cpp)]]
268268
// [[Rcpp::export]]
269269
arma::mat sample_hyper(
270270
const int& S,

0 commit comments

Comments
 (0)