Skip to content

Commit

Permalink
Merge branch 'release/v1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ygeunkim committed Jan 9, 2024
2 parents bc1d36a + 65c9c40 commit 016cb16
Show file tree
Hide file tree
Showing 19 changed files with 187 additions and 81 deletions.
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 1.2.0
Date: 2024-01-09 00:49:39 UTC
SHA: 1e9ab0f499b8b7417460b491bdf635dda84fcce8
7 changes: 3 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Package: bvhar
Type: Package
Title: Bayesian Vector Heterogeneous Autoregressive Modeling
Version: 1.1.0
Version: 1.2.0
Authors@R:
c(person(given = "Young Geun",
family = "Kim",
email = "dudrms33@g.skku.edu",
email = "ygeunkimstat@gmail.com",
role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0001-8651-1167")),
person(given = "Changryong",
Expand Down Expand Up @@ -43,8 +43,7 @@ Imports:
doRNG
LinkingTo:
Rcpp,
RcppEigen,
RcppProgress
RcppEigen
VignetteBuilder: knitr
Depends:
R (>= 3.6.0)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# bvhar 1.2.0

* Replace progress bar of `RcppProgress` package with custom header (`bvharprogress.h`).

* Replace checking user interruption in the same package with custom header (`bvharinterrupt.h`).

* Fix triangular algorithm. Found missing update of some variables (`bvar_sv()` and `bvhar_sv()`).

# bvhar 1.1.0

* For new research, add new features for shrinkage priors.
Expand Down
18 changes: 10 additions & 8 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ install.packages("bvhar")
You can install the development version from this repository.

```{r devinst, eval=FALSE}
# install.packages("pak")
pak::pak("ygeunkim/bvhar")
# install.packages("remotes")
remotes::install_github("ygeunkim/bvhar")
```

## Models
Expand All @@ -63,12 +63,14 @@ library(dplyr)

Repeatedly, `bvhar` is a research tool to analyze multivariate time series model above

| Model | function | class |
|:-----:|:--------:|:--:|
| VAR | `var_lm()` | `varlse` |
| VHAR | `vhar_lm()` | `vharlse` |
| BVAR | `bvar_minnesota()` | `bvarmn` |
| BVHAR | `bvhar_minnesota()` | `bvharmn` |
| Model | function | prior |
|:-----:|:--------:|:-----:|
| VAR | `var_lm()` | |
| VHAR | `vhar_lm()` | |
| BVAR | `bvar_minnesota()` | Minnesota |
| BVHAR | `bvhar_minnesota()` | Minnesota |
| BVAR-SV | `bvar_sv()` | SSVS, Horseshoe |
| BVHAR-SV | `bvhar_sv()` | SSVS, Horseshoe |

This readme document shows forecasting procedure briefly.
Details about each function are in vignettes and help documents.
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ install.packages("bvhar")
You can install the development version from this repository.

``` r
# install.packages("pak")
pak::pak("ygeunkim/bvhar")
# install.packages("remotes")
remotes::install_github("ygeunkim/bvhar")
```

## Models
Expand All @@ -53,12 +53,14 @@ library(dplyr)
Repeatedly, `bvhar` is a research tool to analyze multivariate time
series model above

| Model | function | class |
|:-----:|:-------------------:|:---------:|
| VAR | `var_lm()` | `varlse` |
| VHAR | `vhar_lm()` | `vharlse` |
| BVAR | `bvar_minnesota()` | `bvarmn` |
| BVHAR | `bvhar_minnesota()` | `bvharmn` |
| Model | function | prior |
|:--------:|:-------------------:|:---------------:|
| VAR | `var_lm()` | |
| VHAR | `vhar_lm()` | |
| BVAR | `bvar_minnesota()` | Minnesota |
| BVHAR | `bvhar_minnesota()` | Minnesota |
| BVAR-SV | `bvar_sv()` | SSVS, Horseshoe |
| BVHAR-SV | `bvhar_sv()` | SSVS, Horseshoe |

This readme document shows forecasting procedure briefly. Details about
each function are in vignettes and help documents.
Expand Down Expand Up @@ -277,7 +279,7 @@ Please cite this package with following BibTeX:
title = {{bvhar}: Bayesian Vector Heterogeneous Autoregressive Modeling},
author = {Young Geun Kim and Changryong Baek},
year = {2023},
note = {R package version 1.1.0},
note = {R package version 1.2.0},
url = {https://cran.r-project.org/package=bvhar},
}

Expand Down
10 changes: 6 additions & 4 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,11 @@ news:
href: https://github.com/ygeunkim/bvhar/releases/tag/v0.12.0
- text: "Version 1.0.0"
href: https://github.com/ygeunkim/bvhar/releases/tag/v1.0.0
- text: "Version 1.0.1"
href: https://github.com/ygeunkim/bvhar/releases/tag/v1.0.1
- text: "Version 1.0.2"
href: https://github.com/ygeunkim/bvhar/releases/tag/v1.0.2
# - text: "Version 1.0.1"
# href: https://github.com/ygeunkim/bvhar/releases/tag/v1.0.1
# - text: "Version 1.0.2"
# href: https://github.com/ygeunkim/bvhar/releases/tag/v1.0.2
- text: "Version 1.1.0"
href: https://github.com/ygeunkim/bvhar/releases/tag/v1.1.0
- text: "Version 1.2.0"
href: https://github.com/ygeunkim/bvhar/releases/tag/v1.2.0
4 changes: 4 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

0 errors | 0 warnings | 1 note

* Changed the maintainer email address (gmail). The domain of previous one (skku.edu) will be invalid near future because it is the institution email.

* HTML validation: It seems inevitable NOTE in local machine (x86_64-apple-darwin20) check. I got the same one last time but had no problem in CRAN check.

* Reduced the MCMC iteration numbers in Vignettes against building that takes a long time (over 110s) in Debian.

## revdepcheck results

We checked 0 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package.
Expand Down
2 changes: 1 addition & 1 deletion man/bvhar-package.Rd

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

Binary file modified man/figures/README-predfig-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 16 additions & 26 deletions revdep/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
# Platform

|field |value |
|:--------|:-------------------------------------------|
|version |R version 4.3.2 (2023-10-31) |
|os |macOS Ventura 13.6.3 |
|system |aarch64, darwin20 |
|ui |RStudio |
|language |(EN) |
|collate |en_US.UTF-8 |
|ctype |en_US.UTF-8 |
|tz |Asia/Seoul |
|date |2023-12-18 |
|rstudio |2023.06.0+421 Mountain Hydrangea (desktop) |
|pandoc |3.1.11 @ /opt/homebrew/bin/ (via rmarkdown) |
|field |value |
|:--------|:------------------------------------------|
|version |R version 4.3.2 (2023-10-31) |
|os |macOS Sonoma 14.2.1 |
|system |x86_64, darwin20 |
|ui |RStudio |
|language |(EN) |
|collate |en_US.UTF-8 |
|ctype |en_US.UTF-8 |
|tz |Asia/Seoul |
|date |2024-01-08 |
|rstudio |2023.12.0+369 Ocean Storm (desktop) |
|pandoc |3.1.11.1 @ /usr/local/bin/ (via rmarkdown) |

# Dependencies

|package |old |new |Δ |
|:-----------|:-----|:--------|:--|
|bvhar |1.0.2 |1.1.0 |* |
|checkmate |NA |2.3.1 |* |
|cli |NA |3.6.2 |* |
|cpp11 |NA |0.4.7 |* |
|fansi |NA |1.0.6 |* |
|ggridges |NA |0.5.5 |* |
|matrixStats |NA |1.2.0 |* |
|scales |NA |1.3.0 |* |
|stringi |NA |1.8.3 |* |
|tensorA |NA |0.36.2.1 |* |
|vctrs |NA |0.6.5 |* |
|package |old |new |Δ |
|:-------|:-----|:-----|:--|
|bvhar |1.1.0 |1.2.0 |* |

# Revdeps

17 changes: 17 additions & 0 deletions src/bvharinterrupt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "bvharinterrupt.h"

std::atomic<bool> bvharinterrupt::_interrupted(false);

bvharinterrupt::bvharinterrupt() {
std::signal(SIGINT, bvharinterrupt::handle_signal);
}

bool bvharinterrupt::is_interrupted() {
return _interrupted.load();
}

void bvharinterrupt::handle_signal(int signal) {
if (signal == SIGINT) {
_interrupted.store(true);
}
}
17 changes: 17 additions & 0 deletions src/bvharinterrupt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef BVHARINTERRUPT_H
#define BVHARINTERRUPT_H

#include <csignal>
#include <atomic>

class bvharinterrupt {
private:
static std::atomic<bool> _interrupted;
static void handle_signal(int signal);
public:
bvharinterrupt();
virtual ~bvharinterrupt() = default;
static bool is_interrupted();
};

#endif
27 changes: 27 additions & 0 deletions src/bvharprogress.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "bvharprogress.h"

bvharprogress::bvharprogress(int total, bool verbose) : _current(0), _total(total), _width(50), _verbose(verbose) {}

void bvharprogress::increment() {
_current++;
}

void bvharprogress::update() {
if (!_verbose) {
return; // not display when verbose is false
}
int percent = _current * 100 / _total;
Rcpp::Rcout << "\r";
for (int i = 0; i < _width; i++) {
if (i < (percent * _width / 100)) {
Rcpp::Rcout << "#";
} else {
Rcpp::Rcout << " ";
}
}
Rcpp::Rcout << " " << percent << "%";
Rcpp::Rcout.flush();
if (_current >= _total) {
Rcpp::Rcout << "\n";
}
}
22 changes: 22 additions & 0 deletions src/bvharprogress.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef BVHARPROGRESS_H
#define BVHARPROGRESS_H

#include <Rcpp.h>
#include <atomic>

class bvharprogress {
private:
std::atomic<int> _current;
int _total;
int _width;
bool _verbose;
public:
bvharprogress(int total, bool verbose);
virtual ~bvharprogress() = default;
void update();
void increment();
bool is_interrupted() const;
void set_interrupt(bool flag);
};

#endif
14 changes: 9 additions & 5 deletions src/estimate-hierarchical.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <RcppEigen.h>
#include "bvharmisc.h"
#include "randsim.h"
#include <progress.hpp>
#include <progress_bar.hpp>
#include "bvharprogress.h"
#include "bvharinterrupt.h"

//' Log of Joint Posterior Density of Hyperparameters
//'
Expand Down Expand Up @@ -97,13 +97,14 @@ Rcpp::List estimate_hierachical_niw(int num_iter, int num_burn, Eigen::MatrixXd
);
double numerator = 0;
double denom = 0;
Progress p(num_iter, display_progress);
bvharprogress bar(num_iter, display_progress);
bvharinterrupt();
// Start Metropolis---------------------------------------------
typedef Eigen::Matrix<bool, Eigen::Dynamic, 1> VectorXb;
VectorXb is_accept(num_iter + 1);
is_accept[0] = true;
for (int i = 1; i < num_iter + 1; i ++) {
if (Progress::check_abort()) {
if (bvharinterrupt::is_interrupted()) {
return Rcpp::List::create(
Rcpp::Named("lambda_record") = lam_record,
Rcpp::Named("psi_record") = psi_record,
Expand All @@ -112,7 +113,10 @@ Rcpp::List estimate_hierachical_niw(int num_iter, int num_burn, Eigen::MatrixXd
Rcpp::Named("acceptance") = is_accept
);
}
p.increment();
bar.increment();
if (display_progress) {
bar.update();
}
// Candidate ~ N(previous, scaled hessian)
candprior = Eigen::Map<Eigen::VectorXd>(sim_mgaussian_chol(1, prevprior, gaussian_variance).data(), 1 + dim);
// log of acceptance rate = numerator - denom
Expand Down
17 changes: 9 additions & 8 deletions src/estimate-horseshoe.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#include <RcppEigen.h>
#include "bvhardraw.h"
#include <progress.hpp>
#include <progress_bar.hpp>

// [[Rcpp::depends(RcppEigen)]]
// [[Rcpp::depends(RcppProgress)]]
#include "bvharprogress.h"
#include "bvharinterrupt.h"

//' Gibbs Sampler for Horseshoe BVAR SUR Parameterization
//'
Expand Down Expand Up @@ -62,9 +59,10 @@ Rcpp::List estimate_sur_horseshoe(int num_iter, int num_burn,
Eigen::VectorXd response_vec = vectorize_eigen(y);
Eigen::MatrixXd lambda_mat = Eigen::MatrixXd::Zero(num_coef, num_coef);
// Start Gibbs sampling-----------------------------------
Progress p(num_iter - 1, display_progress);
bvharprogress bar(num_iter, display_progress);
bvharinterrupt();
for (int i = 1; i < num_iter + 1; i++) {
if (Progress::check_abort()) {
if (bvharinterrupt::is_interrupted()) {
return Rcpp::List::create(
Rcpp::Named("alpha_record") = coef_record,
Rcpp::Named("lambda_record") = local_record,
Expand All @@ -73,7 +71,10 @@ Rcpp::List estimate_sur_horseshoe(int num_iter, int num_burn,
Rcpp::Named("kappa_record") = shrink_record
);
}
p.increment();
bar.increment();
if (display_progress) {
bar.update();
}
// 1. alpha (coefficient)
for (int j = 0; j < num_grp; j++) {
global_shrinkage_mat = (
Expand Down
Loading

0 comments on commit 016cb16

Please sign in to comment.