Skip to content

Commit eed53f7

Browse files
committed
Merge branch 'feature/omp-memory-error-withci' into develop
2 parents 04ea3f9 + 7fe977e commit eed53f7

23 files changed

+3053
-3106
lines changed

.github/workflows/R-CMD-check.yaml

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ jobs:
2121
- {os: macOS-latest, r: 'release'}
2222

2323
- {os: windows-latest, r: 'release'}
24-
- {os: windows-latest, r: 'oldrel-3'} # change to oldrel-3 in Spring 2025
24+
# rtools40's older compiler: R-4.0.0 to to R-4.1.3
25+
- {os: windows-latest, r: '4.1'}
2526

2627
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
2728
- {os: ubuntu-latest, r: 'release'}
@@ -38,10 +39,6 @@ jobs:
3839
steps:
3940
- uses: actions/checkout@v4
4041

41-
- name: Memory issue in R
42-
if: ${{ (matrix.config.os == 'ubuntu-latest' && matrix.config.r == 'devel') || (matrix.config.os == 'windows-latest' && matrix.config.r == 'oldrel-3') }}
43-
run: echo "MAKEFLAGS=-j1" >> $GITHUB_ENV
44-
4542
- uses: r-lib/actions/setup-pandoc@v2
4643

4744
- uses: r-lib/actions/setup-r@v2

R/RcppExports.R

+283-283
Large diffs are not rendered by default.

inst/doxygen/Doxyfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ PROJECT_BRIEF = "C++ headers by bvhar package"
6161
# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
6262
# the logo to the output directory.
6363

64-
PROJECT_LOGO = pkgdown/favicon/apple-touch-icon-120x120.png
64+
PROJECT_LOGO = pkgdown/favicon/apple-touch-icon.png
6565

6666
# With the PROJECT_ICON tag one can specify an icon that is included in the tabs
6767
# when the HTML document is shown. Doxygen will copy the logo to the output

inst/include/bvhar/bayesfit

-10
This file was deleted.

inst/include/bvhar/mniw

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef BVHAR_MNIW_H
2+
#define BVHAR_MNIW_H
3+
4+
#include "src/core/interrupt.h"
5+
6+
#include "src/bayes/mniw/minnesota.h"
7+
#include "src/bayes/mniw/forecaster.h"
8+
#include "src/bayes/mniw/spillover.h"
9+
10+
#endif // BVHAR_MNIW_H

inst/include/bvhar/src/bayes/triangular/config.h

-37
Original file line numberDiff line numberDiff line change
@@ -738,13 +738,6 @@ struct RegRecords {
738738
*/
739739
virtual void subsetStable(int num_alpha, double threshold, Eigen::Ref<const Eigen::MatrixXd> har_trans) = 0;
740740

741-
/**
742-
* @copydoc subsetStable(int, double)
743-
*
744-
* @param har_trans Sprase VHAR transformation matrix
745-
*/
746-
virtual void subsetStable(int num_alpha, double threshold, Eigen::Ref<const Eigen::SparseMatrix<double>> har_trans) = 0;
747-
748741
/**
749742
* @brief Get sparse draw using credible interval
750743
*
@@ -919,20 +912,6 @@ struct LdltRecords : public RegRecords {
919912
contem_coef_record = std::move(contem_coef_record(stable_id, Eigen::all));
920913
fac_record = std::move(fac_record(stable_id, Eigen::all));
921914
}
922-
923-
void subsetStable(int num_alpha, double threshold, Eigen::Ref<const Eigen::SparseMatrix<double>> har_trans) override {
924-
int dim = fac_record.cols();
925-
int nrow_coef = num_alpha / dim;
926-
std::vector<int> stable_id;
927-
for (int i = 0; i < coef_record.rows(); ++i) {
928-
if (is_stable(har_trans.transpose() * coef_record.row(i).head(num_alpha).reshaped(nrow_coef, dim), threshold)) {
929-
stable_id.push_back(i);
930-
}
931-
}
932-
coef_record = std::move(coef_record(stable_id, Eigen::all));
933-
contem_coef_record = std::move(contem_coef_record(stable_id, Eigen::all));
934-
fac_record = std::move(fac_record(stable_id, Eigen::all));
935-
}
936915
};
937916

938917
struct SvRecords : public RegRecords {
@@ -1053,22 +1032,6 @@ struct SvRecords : public RegRecords {
10531032
lvol_sig_record = std::move(lvol_sig_record(stable_id, Eigen::all));
10541033
lvol_init_record = std::move(lvol_init_record(stable_id, Eigen::all));
10551034
}
1056-
1057-
void subsetStable(int num_alpha, double threshold, Eigen::Ref<const Eigen::SparseMatrix<double>> har_trans) override {
1058-
int dim = lvol_sig_record.cols();
1059-
int nrow_coef = num_alpha / dim;
1060-
std::vector<int> stable_id;
1061-
for (int i = 0; i < coef_record.rows(); ++i) {
1062-
if (is_stable(har_trans.transpose() * coef_record.row(i).head(num_alpha).reshaped(nrow_coef, dim), threshold)) {
1063-
stable_id.push_back(i);
1064-
}
1065-
}
1066-
coef_record = std::move(coef_record(stable_id, Eigen::all));
1067-
contem_coef_record = std::move(contem_coef_record(stable_id, Eigen::all));
1068-
lvol_record = std::move(lvol_record(stable_id, Eigen::all));
1069-
lvol_sig_record = std::move(lvol_sig_record(stable_id, Eigen::all));
1070-
lvol_init_record = std::move(lvol_init_record(stable_id, Eigen::all));
1071-
}
10721035
};
10731036

10741037
/**

inst/include/bvhar/src/bayes/triangular/forecaster.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ class McmcVharForecaster : public BaseForecaster {
314314
const typename std::conditional<std::is_same<BaseForecaster, RegForecaster>::value, LdltRecords, SvRecords>::type& records,
315315
int step, const Eigen::MatrixXd& response_mat, const Eigen::MatrixXd& har_trans, int month, bool include_mean, bool filter_stable, unsigned int seed, bool sv = true
316316
)
317-
: BaseForecaster(records, step, response_mat, month, include_mean, filter_stable, seed, sv), har_trans(har_trans.sparseView()) {
317+
: BaseForecaster(records, step, response_mat, month, include_mean, filter_stable, seed, sv), har_trans(har_trans) {
318318
if (stable_filter) {
319-
reg_record->subsetStable(num_alpha, 1, har_trans.topLeftCorner(3 * dim, month * dim).sparseView());
319+
reg_record->subsetStable(num_alpha, 1, har_trans.topLeftCorner(3 * dim, month * dim));
320320
num_sim = reg_record->coef_record.rows();
321321
if (num_sim == 0) {
322322
STOP("No stable MCMC draws");
@@ -334,7 +334,7 @@ class McmcVharForecaster : public BaseForecaster {
334334
using BaseForecaster::post_mean;
335335
using BaseForecaster::coef_mat;
336336
using BaseForecaster::last_pvec;
337-
Eigen::SparseMatrix<double> har_trans;
337+
Eigen::MatrixXd har_trans;
338338
void computeMean() override {
339339
post_mean = coef_mat.transpose() * har_trans * last_pvec;
340340
}

inst/include/bvhar/src/bayes/triangular/triangular.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef BVHAR_BAYES_TRIANGULAR_TRIANGULAR_H
77
#define BVHAR_BAYES_TRIANGULAR_TRIANGULAR_H
88

9-
#include "config.h"
9+
#include "./config.h"
1010
#include "../../core/progress.h"
1111
#include "../../core/interrupt.h"
1212
#include <type_traits>

inst/include/bvhar/src/math/design.h

-20
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,6 @@ inline Eigen::MatrixXd build_vhar(int dim, int week, int month, bool include_mea
5757
return HARtrans.block(0, 0, 3 * dim, month * dim);
5858
}
5959

60-
inline Eigen::SparseMatrix<double> build_vhar_sparse(int dim, int week, int month, bool include_mean) {
61-
Eigen::MatrixXd HAR = Eigen::MatrixXd::Zero(3, month);
62-
Eigen::MatrixXd HARtrans = Eigen::MatrixXd::Zero(3 * dim + 1, month * dim + 1); // 3m x (month * m)
63-
Eigen::MatrixXd Im = Eigen::MatrixXd::Identity(dim, dim);
64-
HAR(0, 0) = 1.0;
65-
for (int i = 0; i < week; i++) {
66-
HAR(1, i) = 1.0 / week;
67-
}
68-
for (int i = 0; i < month; i++) {
69-
HAR(2, i) = 1.0 / month;
70-
}
71-
HARtrans.block(0, 0, 3 * dim, month * dim) = Eigen::kroneckerProduct(HAR, Im).eval();
72-
HARtrans(3 * dim, month * dim) = 1.0;
73-
Eigen::SparseMatrix<double> sparse_har = HARtrans.sparseView();
74-
if (include_mean) {
75-
return sparse_har;
76-
}
77-
return sparse_har.block(0, 0, 3 * dim, month * dim);
78-
}
79-
8060
inline Eigen::MatrixXd build_ydummy(int p, const Eigen::VectorXd& sigma, double lambda,
8161
const Eigen::VectorXd& daily, const Eigen::VectorXd& weekly, const Eigen::VectorXd& monthly,
8262
bool include_mean) {

inst/include/bvhar/triangular

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef BVHAR_TRIANGULAR_H
2+
#define BVHAR_TRIANGULAR_H
3+
4+
#include "src/bayes/triangular/triangular.h"
5+
#include "src/bayes/triangular/forecaster.h"
6+
#include "src/bayes/triangular/spillover.h"
7+
8+
#endif // BVHAR_TRIANGULAR_H

python/src/bvhar/_src/_bayes.cpp

-39
This file was deleted.

python/src/bvhar/_src/_forecast.cpp renamed to python/src/bvhar/_src/_cta.cpp

+68-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,42 @@
1-
#include <bvhar/forecast>
1+
#include <bvhar/triangular>
22

3-
PYBIND11_MODULE(_forecast, m) {
3+
PYBIND11_MODULE(_cta, m) {
4+
py::class_<bvhar::McmcRun<bvhar::McmcReg>>(m, "McmcLdlt")
5+
.def(
6+
py::init<int, int, int, int, const Eigen::MatrixXd&, const Eigen::MatrixXd&,
7+
py::dict&, py::dict&, py::dict&,
8+
std::vector<py::dict>&, int, const Eigen::VectorXi&, const Eigen::VectorXi&, const Eigen::VectorXi&,
9+
const Eigen::MatrixXi&, bool, const Eigen::VectorXi&, bool, int>()
10+
)
11+
.def("returnRecords", &bvhar::McmcRun<bvhar::McmcReg>::returnRecords);
12+
13+
py::class_<bvhar::McmcRun<bvhar::McmcReg, false>>(m, "McmcLdltGrp")
14+
.def(
15+
py::init<int, int, int, int, const Eigen::MatrixXd&, const Eigen::MatrixXd&,
16+
py::dict&, py::dict&, py::dict&,
17+
std::vector<py::dict>&, int, const Eigen::VectorXi&, const Eigen::VectorXi&, const Eigen::VectorXi&,
18+
const Eigen::MatrixXi&, bool, const Eigen::VectorXi&, bool, int>()
19+
)
20+
.def("returnRecords", &bvhar::McmcRun<bvhar::McmcReg, false>::returnRecords);
21+
22+
py::class_<bvhar::McmcRun<bvhar::McmcSv>>(m, "SvMcmc")
23+
.def(
24+
py::init<int, int, int, int, const Eigen::MatrixXd&, const Eigen::MatrixXd&,
25+
py::dict&, py::dict&, py::dict&,
26+
std::vector<py::dict>&, int, const Eigen::VectorXi&, const Eigen::VectorXi&, const Eigen::VectorXi&,
27+
const Eigen::MatrixXi&, bool, const Eigen::VectorXi&, bool, int>()
28+
)
29+
.def("returnRecords", &bvhar::McmcRun<bvhar::McmcSv>::returnRecords);
30+
31+
py::class_<bvhar::McmcRun<bvhar::McmcSv, false>>(m, "SvGrpMcmc")
32+
.def(
33+
py::init<int, int, int, int, const Eigen::MatrixXd&, const Eigen::MatrixXd&,
34+
py::dict&, py::dict&, py::dict&,
35+
std::vector<py::dict>&, int, const Eigen::VectorXi&, const Eigen::VectorXi&, const Eigen::VectorXi&,
36+
const Eigen::MatrixXi&, bool, const Eigen::VectorXi&, bool, int>()
37+
)
38+
.def("returnRecords", &bvhar::McmcRun<bvhar::McmcSv, false>::returnRecords);
39+
440
py::class_<bvhar::McmcForecastRun<bvhar::RegForecaster>>(m, "LdltForecast")
541
.def(py::init<int, int, int, const Eigen::MatrixXd&, bool, double, py::dict&, const Eigen::VectorXi&, bool, bool, int, bool>())
642
.def(py::init<int, int, int, int, const Eigen::MatrixXd&, bool, double, py::dict&, const Eigen::VectorXi&, bool, bool, int, bool>())
@@ -170,4 +206,34 @@ PYBIND11_MODULE(_forecast, m) {
170206
const Eigen::MatrixXi&, const Eigen::VectorXi&, bool, int, bool>()
171207
)
172208
.def("returnForecast", &bvhar::McmcVharforecastRun<bvhar::McmcExpandforecastRun, bvhar::SvForecaster, false>::returnForecast);
209+
210+
py::class_<bvhar::McmcSpilloverRun<bvhar::LdltRecords>>(m, "LdltSpillover")
211+
.def(py::init<int, int, py::dict&, bool>())
212+
.def(py::init<int, int, int, py::dict&, bool>())
213+
.def("returnSpillover", &bvhar::McmcSpilloverRun<bvhar::LdltRecords>::returnSpillover);
214+
215+
py::class_<bvhar::DynamicLdltSpillover>(m, "LdltDynamicSpillover")
216+
.def(
217+
py::init<const Eigen::MatrixXd&, int, int, int, int, int, int, int, bool,
218+
py::dict&, py::dict&, py::dict&, std::vector<py::dict>&, int, bool,
219+
const Eigen::VectorXi&, const Eigen::VectorXi&, const Eigen::VectorXi&, const Eigen::MatrixXi&,
220+
bool, const Eigen::MatrixXi&, int>()
221+
)
222+
.def(
223+
py::init<const Eigen::MatrixXd&, int, int, int, int, int, int, int, int, bool,
224+
py::dict&, py::dict&, py::dict&, std::vector<py::dict>&, int, bool,
225+
const Eigen::VectorXi&, const Eigen::VectorXi&, const Eigen::VectorXi&, const Eigen::MatrixXi&,
226+
bool, const Eigen::MatrixXi&, int>()
227+
)
228+
.def("returnSpillover", &bvhar::DynamicLdltSpillover::returnSpillover);
229+
230+
py::class_<bvhar::McmcSpilloverRun<bvhar::SvRecords>>(m, "SvSpillover")
231+
.def(py::init<int, int, py::dict&, bool>())
232+
.def(py::init<int, int, int, py::dict&, bool>())
233+
.def("returnSpillover", &bvhar::McmcSpilloverRun<bvhar::SvRecords>::returnSpillover);
234+
235+
py::class_<bvhar::DynamicSvSpillover>(m, "SvDynamicSpillover")
236+
.def(py::init<int, int, int, py::dict&, bool, bool, int>())
237+
.def(py::init<int, int, int, int, py::dict&, bool, bool, int>())
238+
.def("returnSpillover", &bvhar::DynamicSvSpillover::returnSpillover);
173239
}

python/src/bvhar/_src/_spillover.cpp

-33
This file was deleted.

python/src/bvhar/model/_bayes.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from ..utils._misc import make_fortran_array, check_np, build_grpmat, process_record, concat_chain, concat_params, process_dens_forecast, process_dens_spillover, process_dens_vector_spillover, process_dens_list_spillover
22
from ..utils.checkomp import get_maxomp
33
from ..utils._utils import build_response, build_design
4-
from .._src._bayes import McmcLdlt, McmcLdltGrp
5-
from .._src._forecast import LdltForecast, LdltVarRoll, LdltVharRoll, LdltVarExpand, LdltVharExpand, LdltGrpVarRoll, LdltGrpVharRoll, LdltGrpVarExpand, LdltGrpVharExpand
6-
from .._src._spillover import LdltSpillover, LdltDynamicSpillover
7-
from .._src._bayes import SvMcmc, SvGrpMcmc
8-
from .._src._forecast import SvForecast, SvVarRoll, SvVharRoll, SvVarExpand, SvVharExpand, SvGrpVarRoll, SvGrpVharRoll, SvGrpVarExpand, SvGrpVharExpand
9-
from .._src._spillover import SvSpillover, SvDynamicSpillover
4+
from .._src._cta import McmcLdlt, McmcLdltGrp
5+
from .._src._cta import LdltForecast, LdltVarRoll, LdltVharRoll, LdltVarExpand, LdltVharExpand, LdltGrpVarRoll, LdltGrpVharRoll, LdltGrpVarExpand, LdltGrpVharExpand
6+
from .._src._cta import LdltSpillover, LdltDynamicSpillover
7+
from .._src._cta import SvMcmc, SvGrpMcmc
8+
from .._src._cta import SvForecast, SvVarRoll, SvVharRoll, SvVarExpand, SvVharExpand, SvGrpVarRoll, SvGrpVharRoll, SvGrpVarExpand, SvGrpVharExpand
9+
from .._src._cta import SvSpillover, SvDynamicSpillover
1010
from ._spec import LdltConfig, SvConfig, InterceptConfig
1111
from ._spec import _BayesConfig, SsvsConfig, HorseshoeConfig, MinnesotaConfig, DlConfig, NgConfig, GdpConfig
1212
import numpy as np

0 commit comments

Comments
 (0)