From 72c9f68e7bc1e393f9d1ade6eab1fb8820e9c696 Mon Sep 17 00:00:00 2001 From: Young Geun Kim Date: Mon, 16 Dec 2024 20:23:11 +0900 Subject: [PATCH 1/9] add doxygen comment in bvharconfig --- inst/include/bvharconfig.h | 301 +++++++++++++++++++++++++++++++++++++ 1 file changed, 301 insertions(+) diff --git a/inst/include/bvharconfig.h b/inst/include/bvharconfig.h index fa83520e..e4eee601 100644 --- a/inst/include/bvharconfig.h +++ b/inst/include/bvharconfig.h @@ -43,6 +43,10 @@ struct GlobalLocalRecords; struct HorseshoeRecords; struct NgRecords; +/** + * @brief Hyperparameters for `McmcReg` + * + */ struct RegParams { int _iter; Eigen::MatrixXd _x, _y; @@ -72,6 +76,10 @@ struct RegParams { } }; +/** + * @brief Hyperparameters for `McmcSv` + * + */ struct SvParams : public RegParams { Eigen::VectorXd _init_mean; Eigen::MatrixXd _init_prec; @@ -88,6 +96,11 @@ struct SvParams : public RegParams { _init_prec(CAST(spec["initial_prec"])) {} }; +/** + * @brief Hyperparameters for Minnesota prior `McmcMinn` + * + * @tparam BaseRegParams `RegParams` or `SvParams` + */ template struct MinnParams : public BaseRegParams { Eigen::MatrixXd _prec_diag; @@ -130,6 +143,11 @@ struct MinnParams : public BaseRegParams { } }; +/** + * @brief Hyperparameters for Hierarchical Minnesota prior `McmcHierminn` + * + * @tparam BaseRegParams `RegParams` or `SvParams` + */ template struct HierminnParams : public BaseRegParams { double shape; @@ -187,6 +205,11 @@ struct HierminnParams : public BaseRegParams { } }; +/** + * @brief Hyperparameters for SSVS prior `McmcSsvs` + * + * @tparam BaseRegParams `RegParams` or `SvParams` + */ template struct SsvsParams : public BaseRegParams { Eigen::VectorXi _grp_id; @@ -215,6 +238,11 @@ struct SsvsParams : public BaseRegParams { _coef_grid(CAST_INT(ssvs_spec["coef_grid"])), _contem_grid(CAST_INT(ssvs_spec["chol_grid"])) {} }; +/** + * @brief Hyperparameters for Horseshoe prior `McmcHorseshoe` + * + * @tparam BaseRegParams `RegParams` or `SvParams` + */ template struct HorseshoeParams : public BaseRegParams { Eigen::VectorXi _grp_id; @@ -230,6 +258,11 @@ struct HorseshoeParams : public BaseRegParams { : BaseRegParams(num_iter, x, y, reg_spec, own_id, cross_id, intercept, include_mean), _grp_id(grp_id), _grp_mat(grp_mat) {} }; +/** + * @brief Hyperparameters for Normal-gamma prior `McmcNg` + * + * @tparam BaseRegParams `RegParams` or `SvParams` + */ template struct NgParams : public BaseRegParams { Eigen::VectorXi _grp_id; @@ -257,6 +290,11 @@ struct NgParams : public BaseRegParams { _contem_global_shape(CAST_DOUBLE(ng_spec["contem_global_shape"])), _contem_global_scl(CAST_DOUBLE(ng_spec["contem_global_scale"])) {} }; +/** + * @brief Hyperparameters for Dirichlet-Laplace prior `McmcDl` + * + * @tparam BaseRegParams `RegParams` or `SvParams` + */ template struct DlParams : public BaseRegParams { Eigen::VectorXi _grp_id; @@ -278,6 +316,11 @@ struct DlParams : public BaseRegParams { _grid_size(CAST_INT(dl_spec["grid_size"])), _shape(CAST_DOUBLE(dl_spec["shape"])), _scl(CAST_DOUBLE(dl_spec["scale"])) {} }; +/** + * @brief Hyperparameters for GDP prior `McmcGdp` + * + * @tparam BaseRegParams `RegParams` or `SvParams` + */ template struct GdpParams : public BaseRegParams { Eigen::VectorXi _grp_id; @@ -298,6 +341,11 @@ struct GdpParams : public BaseRegParams { _grid_shape(CAST_INT(gdp_spec["grid_shape"])), _grid_rate(CAST_INT(gdp_spec["grid_rate"])) {} }; + +/** + * @brief MCMC initial values for `McmcTriangular` + * + */ struct RegInits { Eigen::MatrixXd _coef; Eigen::VectorXd _contem; @@ -314,6 +362,10 @@ struct RegInits { _contem(CAST(init["init_contem"])) {} }; +/** + * @brief MCMC initial values for `McmcReg` + * + */ struct LdltInits : public RegInits { Eigen::VectorXd _diag; @@ -326,6 +378,10 @@ struct LdltInits : public RegInits { _diag(CAST(init["init_diag"])) {} }; +/** + * @brief MCMC initial values for `McmcSv` + * + */ struct SvInits : public RegInits { Eigen::VectorXd _lvol_init; Eigen::MatrixXd _lvol; @@ -353,6 +409,11 @@ struct SvInits : public RegInits { _lvol_sig(CAST(init["lvol_sig"])) {} }; +/** + * @brief MCMC initial values for `McmcHierminn` + * + * @tparam BaseRegInits + */ template struct HierminnInits : public BaseRegInits { double _own_lambda; @@ -368,6 +429,11 @@ struct HierminnInits : public BaseRegInits { _own_lambda(CAST_DOUBLE(init["own_lambda"])), _cross_lambda(CAST_DOUBLE(init["cross_lambda"])), _contem_lambda(CAST_DOUBLE(init["contem_lambda"])) {} }; +/** + * @brief MCMC initial values for `McmcSsvs` + * + * @tparam BaseRegInits `LdltInits` or `SvInits` + */ template struct SsvsInits : public BaseRegInits { Eigen::VectorXd _coef_dummy; @@ -398,6 +464,12 @@ struct SsvsInits : public BaseRegInits { _contem_spike_scl(CAST_DOUBLE(init["chol_spike_scl"])) {} }; +/** + * @brief MCMC initial values for global-local shrinkage prior. + * `McmcDl` takes this. + * + * @tparam BaseRegInits `LdldInits` or `SvInits` + */ template struct GlInits : public BaseRegInits { Eigen::VectorXd _init_local; @@ -420,6 +492,11 @@ struct GlInits : public BaseRegInits { _init_conetm_global(CAST(init["contem_global_sparsity"])) {} }; +/** + * @brief MCMC initial values for `McmcHorseshoe` + * + * @tparam BaseRegInits `LdltInits` or `SvInits` + */ template struct HsInits : public GlInits { Eigen::VectorXd _init_group; @@ -433,6 +510,11 @@ struct HsInits : public GlInits { _init_group(CAST(init["group_sparsity"])) {} }; +/** + * @brief MCMC initial values for `McmcNg` + * + * @tparam BaseRegInits `LdltInits` or `SvInits` + */ template struct NgInits : public HsInits { Eigen::VectorXd _init_local_shape; @@ -449,6 +531,11 @@ struct NgInits : public HsInits { _init_contem_shape(CAST_DOUBLE(init["contem_shape"])) {} }; +/** + * @brief MCMC initial values for `McmcGdp` + * + * @tparam BaseRegInits `LdltInits` or `SvInits` + */ template struct GdpInits : public BaseRegInits { Eigen::VectorXd _init_local; @@ -476,6 +563,10 @@ struct GdpInits : public BaseRegInits { _init_contem_gamma_shape(CAST_DOUBLE(init["contem_gamma_shape"])), _init_contem_gamma_rate(CAST_DOUBLE(init["contem_gamma_rate"])) {} }; +/** + * @brief MCMC records for `McmcTriangular` + * + */ struct RegRecords { Eigen::MatrixXd coef_record; // alpha in VAR Eigen::MatrixXd contem_coef_record; // a = a21, a31, a32, ..., ak1, ..., ak(k-1) @@ -491,22 +582,49 @@ struct RegRecords { virtual ~RegRecords() = default; + /** + * @brief Assign MCMC draw to the draw matrix + * + * @param id MCMC step + * @param coef_vec Coefficient vector draw + * @param contem_coef Contemporaneous coefficient draw + */ void assignRecords(int id, const Eigen::VectorXd& coef_vec, const Eigen::VectorXd& contem_coef) { coef_record.row(id) = coef_vec; contem_coef_record.row(id) = contem_coef; } + /** + * @copydoc assignRecords(int, const Eigen::VectorXd& coef_vec, const Eigen::VectorXd& coef_vec) + * + * @param diag_vec Diagonal term draw + */ virtual void assignRecords( int id, const Eigen::VectorXd& coef_vec, const Eigen::VectorXd& contem_coef, const Eigen::VectorXd& diag_vec ) = 0; + /** + * @copydoc assignRecords(int, const Eigen::VectorXd&, const Eigen::VectorXd&) + * + * @param lvol_draw Log volatilities draw + * @param lvol_sig Variance draw of log volatilities + * @param lvol_init Initial log volatlity draw + */ virtual void assignRecords( int id, const Eigen::VectorXd& coef_vec, const Eigen::VectorXd& contem_coef, const Eigen::MatrixXd& lvol_draw, const Eigen::VectorXd& lvol_sig, const Eigen::VectorXd& lvol_init ) = 0; + /** + * @brief Return the MCMC record `LIST` + * + * @param dim Time series dimension + * @param num_alpha The number of coefficient elements except constant term + * @param include_mean If `true`, constant term is included + * @return LIST A `LIST` containing MCMC records. If `include_mean` is `true`, it also includes a constant term record. + */ LIST returnListRecords(int dim, int num_alpha, bool include_mean) const { LIST res = CREATE_LIST( NAMED("alpha_record") = coef_record.leftCols(num_alpha), @@ -517,19 +635,95 @@ struct RegRecords { } return res; } + + /** + * @brief Append records to the MCMC record `LIST` + * + * @param list MCMC record `LIST` + */ virtual void appendRecords(LIST& list) = 0; + + /** + * @brief Return `LdltRecords` + * + * @param sparse_record `SparseRecords` object + * @param num_iter Number of MCMC iteration + * @param num_burn Number of burn-in + * @param thin Thinning + * @param sparse If `true`, return sparsified draws. + * @return LdltRecords `LdltRecords` object + */ virtual LdltRecords returnLdltRecords(const SparseRecords& sparse_record, int num_iter, int num_burn, int thin, bool sparse) const = 0; + + /** + * @brief Return `SvRecords` + * + * @param sparse_record `SparseRecords` object + * @param num_iter Number of MCMC iteration + * @param num_burn Number of burn-in + * @param thin Thinning + * @param sparse If `true`, return sparsified draws. + * @return SvRecords `SvRecords` object + */ virtual SvRecords returnSvRecords(const SparseRecords& sparse_record, int num_iter, int num_burn, int thin, bool sparse) const = 0; + /** + * @brief Return `LdltRecords` or `SvRecords` + * + * @tparam RecordType `LdltRecords` or `SvRecords` + * @param sparse_record `SparseRecords` object + * @param num_iter Number of MCMC iteration + * @param num_burn Number of burn-in + * @param thin Thinning + * @param sparse If `true`, return sparsified draws. + * @return RecordType `LdltRecords` or `SvRecords` + */ template RecordType returnRecords(const SparseRecords& sparse_record, int num_iter, int num_burn, int thin, bool sparse) const; + /** + * @brief Update parameters in \f$D\f$ + * + * @param i MCMC step + * @param sv_update Diagonal term draw + */ virtual void updateDiag(int i, Eigen::Ref sv_update) = 0; + + /** + * @copydoc updateDiag(int, Eigen::Ref) + * + * @param sv_sig Variance draw of AR log volatilties + */ virtual void updateDiag(int i, Eigen::Ref sv_update, Eigen::Ref sv_sig) = 0; + + /** + * @brief Remove unstable coefficients draw + * + * @param num_alpha The number of coefficient elements except constant term + * @param threshold Threashold to check stability + */ virtual void subsetStable(int num_alpha, double threshold) = 0; + + /** + * @copydoc subsetStable(int, double) + * + * @param har_trans Dense VHAR transformation matrix + */ virtual void subsetStable(int num_alpha, double threshold, Eigen::Ref har_trans) = 0; + + /** + * @copydoc subsetStable(int, double) + * + * @param har_trans Sprase VHAR transformation matrix + */ virtual void subsetStable(int num_alpha, double threshold, Eigen::Ref> har_trans) = 0; + /** + * @brief Get sparse draw using credible interval + * + * @param level Credible interval level + * @return Eigen::VectorXd Vector of 0 or 1. 0 if the credible interval includes 0. + */ Eigen::VectorXd computeActivity(double level) { Eigen::VectorXd lower_ci(coef_record.cols()); Eigen::VectorXd upper_ci(coef_record.cols()); @@ -543,6 +737,10 @@ struct RegRecords { } }; +/** + * @brief Signal adaptive variable selector records + * + */ struct SparseRecords { Eigen::MatrixXd coef_record; Eigen::MatrixXd contem_coef_record; @@ -556,11 +754,25 @@ struct SparseRecords { SparseRecords(const Eigen::MatrixXd& alpha_record, const Eigen::MatrixXd& a_record) : coef_record(alpha_record), contem_coef_record(a_record) {} + /** + * @brief Assign MCMC draw to the draw matrix + * + * @param id MCMC step + * @param coef_mat Coefficient matrix processed by SAVS + * @param contem_coef Contemporaneous vector processed by SAVS + */ void assignRecords(int id, const Eigen::MatrixXd& coef_mat, const Eigen::VectorXd& contem_coef) { coef_record.row(id) = coef_mat.reshaped(); contem_coef_record.row(id) = contem_coef; } + /** + * @copydoc assignRecords(int, const Eigen::MatrixXd&, const Eigen::VectorXd&) + * + * @param num_alpha The number of coefficient elements except constant term + * @param dim Time series dimension + * @param nrow_coef Number of rows of coefficient matrix + */ void assignRecords(int id, int num_alpha, int dim, int nrow_coef, const Eigen::MatrixXd& coef_mat, const Eigen::VectorXd& contem_coef) { if (coef_mat.size() == num_alpha) { coef_record.row(id) = coef_mat.reshaped(); @@ -571,6 +783,14 @@ struct SparseRecords { contem_coef_record.row(id) = contem_coef; } + /** + * @brief Append sparse records to the MCMC record `LIST` + * + * @param list MCMC record `LIST` + * @param dim Time series dimension + * @param num_alpha The number of coefficient elements except constant term + * @param include_mean If `true`, constant term is included + */ void appendRecords(LIST& list, int dim, int num_alpha, bool include_mean) { list["alpha_sparse_record"] = CAST_MATRIX(coef_record.leftCols(num_alpha)); list["a_sparse_record"] = contem_coef_record; @@ -580,6 +800,10 @@ struct SparseRecords { } }; +/** + * @brief MCMC records for `McmcReg` + * + */ struct LdltRecords : public RegRecords { Eigen::MatrixXd fac_record; // d_1, ..., d_m in D of LDLT @@ -792,6 +1016,10 @@ struct SvRecords : public RegRecords { } }; +/** + * @brief MCMC records for `McmcSsvs` + * + */ struct SsvsRecords { Eigen::MatrixXd coef_dummy_record; Eigen::MatrixXd coef_weight_record; @@ -813,6 +1041,15 @@ struct SsvsRecords { : coef_dummy_record(coef_dummy_record), coef_weight_record(coef_weight_record), contem_dummy_record(contem_dummy_record), contem_weight_record(contem_weight_record) {} + /** + * @brief Assign MCMC draw to the draw matrix + * + * @param id MCMC step + * @param coef_dummy Dummy parameter corresponding to coefficient draw + * @param coef_weight Weight parameter corresponding to coefficient draw + * @param contem_dummy Dummy parameter corresponding to contemporaneous coefficient draw + * @param contem_weight Weight parameter corresponding to contemporaneous coefficient draw + */ void assignRecords(int id, const Eigen::VectorXd& coef_dummy, const Eigen::VectorXd& coef_weight, const Eigen::VectorXd& contem_dummy, const Eigen::VectorXd& contem_weight) { coef_dummy_record.row(id) = coef_dummy; coef_weight_record.row(id) = coef_weight; @@ -820,6 +1057,14 @@ struct SsvsRecords { contem_weight_record.row(id) = contem_weight; } + /** + * @brief Return `SsvsRecords` + * + * @param num_iter Number of MCMC iteration + * @param num_burn Number of burn-in + * @param thin Thinning + * @return SsvsRecords `SsvsRecords` + */ SsvsRecords returnRecords(int num_iter, int num_burn, int thin) const { SsvsRecords res_record( thin_record(coef_dummy_record, num_iter, num_burn, thin).derived(), @@ -831,6 +1076,11 @@ struct SsvsRecords { } }; +/** + * @brief MCMC records for global-local shrinkage prior + * `McmcDl` directly uses this. + * + */ struct GlobalLocalRecords { Eigen::MatrixXd local_record; Eigen::VectorXd global_record; @@ -844,19 +1094,46 @@ struct GlobalLocalRecords { GlobalLocalRecords(const Eigen::MatrixXd& local_record, const Eigen::VectorXd& global_record) : local_record(local_record), global_record(global_record) {} + /** + * @brief Assign MCMC draw to the draw matrix + * + * @param id MCMC step + * @param local_lev Local shrinkage parameter draw + * @param global_lev Global shrinkage parameter draw + */ virtual void assignRecords(int id, const Eigen::VectorXd& local_lev, const double global_lev) { local_record.row(id) = local_lev; global_record[id] = global_lev; } + /** + * @copydoc assignRecords(int, const Eigen::VectorXd&, const double) + * + * @param id MCMC step + * @param group_lev Group shrinkage parameter draw + */ virtual void assignRecords(int id, const Eigen::VectorXd& local_lev, const Eigen::VectorXd& group_lev, const double global_lev) { assignRecords(id, local_lev, global_lev); } + /** + * @copydoc assignRecords(int, const Eigen::VectorXd&, const double) + * + * @param id MCMC step + * @param shrink_fac Shrinkage factor draw + */ virtual void assignRecords(int id, const Eigen::VectorXd& shrink_fac, const Eigen::VectorXd& local_lev, const Eigen::VectorXd& group_lev, const double global_lev) { assignRecords(id, local_lev, global_lev); } + /** + * @brief Return `GlobalLocalRecords` + * + * @param num_iter Number of MCMC iteration + * @param num_burn Number of burn-in + * @param thin Thinning + * @return GlobalLocalRecords `GlobalLocalRecords` + */ GlobalLocalRecords returnGlRecords(int num_iter, int num_burn, int thin) const { GlobalLocalRecords res_record( thin_record(local_record, num_iter, num_burn, thin).derived(), @@ -866,6 +1143,10 @@ struct GlobalLocalRecords { } }; +/** + * @brief MCMC records for `McmcHorseshoe` + * + */ struct HorseshoeRecords : public GlobalLocalRecords { Eigen::MatrixXd group_record; Eigen::MatrixXd shrink_record; @@ -890,6 +1171,14 @@ struct HorseshoeRecords : public GlobalLocalRecords { void assignRecords(int id, const Eigen::VectorXd& local_lev, const Eigen::VectorXd& group_lev, const double global_lev) override {} + /** + * @brief Return `HorseshoeRecords` + * + * @param num_iter Number of MCMC iteration + * @param num_burn Number of burn-in + * @param thin Thinning + * @return HorseshoeRecords `HorseshoeRecords` + */ HorseshoeRecords returnHsRecords(int num_iter, int num_burn, int thin) const { HorseshoeRecords res_record( thin_record(local_record, num_iter, num_burn, thin).derived(), @@ -901,6 +1190,10 @@ struct HorseshoeRecords : public GlobalLocalRecords { } }; +/** + * @brief MCMC records for `McmcNg` + * + */ struct NgRecords : public GlobalLocalRecords { Eigen::MatrixXd group_record; @@ -921,6 +1214,14 @@ struct NgRecords : public GlobalLocalRecords { global_record[id] = global_lev; } + /** + * @brief Return `NgRecords` + * + * @param num_iter Number of MCMC iteration + * @param num_burn Number of burn-in + * @param thin Thinning + * @return NgRecords `NgRecords` + */ NgRecords returnNgRecords(int num_iter, int num_burn, int thin) const { NgRecords res_record( thin_record(local_record, num_iter, num_burn, thin).derived(), From 881fd1f9b48e43fb04112e0164ba2992ff226128 Mon Sep 17 00:00:00 2001 From: Young Geun Kim Date: Mon, 16 Dec 2024 20:24:31 +0900 Subject: [PATCH 2/9] use doxygen ci temporarily in feature/cpp-document branch --- .github/workflows/doxygen.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doxygen.yaml b/.github/workflows/doxygen.yaml index 0309edcb..89d19c53 100644 --- a/.github/workflows/doxygen.yaml +++ b/.github/workflows/doxygen.yaml @@ -1,7 +1,7 @@ # Render doxygen to github page repo on: push: - branches: [main, master, develop] + branches: [main, master, develop, feature/cpp-document] # temporarily use feature/cpp-document to check pull_request: branches: [main, master] workflow_dispatch: From 06d7483ff3473c5de82bd0543e5c4120f39d8e6a Mon Sep 17 00:00:00 2001 From: Young Geun Kim Date: Mon, 16 Dec 2024 20:44:20 +0900 Subject: [PATCH 3/9] Fill doxygen comments in bvharmcmc --- .github/workflows/doxygen.yaml | 2 +- inst/include/bvharconfig.h | 4 +- inst/include/bvharmcmc.h | 96 +++++++++++++++++++++++++++++++++- 3 files changed, 98 insertions(+), 4 deletions(-) diff --git a/.github/workflows/doxygen.yaml b/.github/workflows/doxygen.yaml index 89d19c53..75537213 100644 --- a/.github/workflows/doxygen.yaml +++ b/.github/workflows/doxygen.yaml @@ -25,7 +25,7 @@ jobs: run: sudo apt-get install -y doxygen graphviz - name: Render doxygen - run: doxygen inst/doxygen/Doxyfile + run: doxygen inst/doxygen/Doxyfile -DUSE_RCPP - name: Create .nojekyll run: sudo touch inst/doxygen/html/.nojekyll diff --git a/inst/include/bvharconfig.h b/inst/include/bvharconfig.h index e4eee601..3c229de7 100644 --- a/inst/include/bvharconfig.h +++ b/inst/include/bvharconfig.h @@ -682,10 +682,10 @@ struct RegRecords { RecordType returnRecords(const SparseRecords& sparse_record, int num_iter, int num_burn, int thin, bool sparse) const; /** - * @brief Update parameters in \f$D\f$ + * @brief Update parameters in D * * @param i MCMC step - * @param sv_update Diagonal term draw + * @param sv_update State vector draw */ virtual void updateDiag(int i, Eigen::Ref sv_update) = 0; diff --git a/inst/include/bvharmcmc.h b/inst/include/bvharmcmc.h index cabc7979..bdfac385 100644 --- a/inst/include/bvharmcmc.h +++ b/inst/include/bvharmcmc.h @@ -69,6 +69,12 @@ class McmcTriangular { sparse_record.assignRecords(0, sparse_coef, sparse_contem); } virtual ~McmcTriangular() = default; + + /** + * @brief Append each class's additional record to the result `LIST` + * + * @param list `LIST` containing MCMC record result + */ virtual void appendRecords(LIST& list) = 0; /** @@ -124,7 +130,7 @@ class McmcTriangular { * * @param num_burn Number of burn-in * @param thin Thinning - * @return LIST + * @return LIST `LIST` containing every MCMC draws */ LIST returnRecords(int num_burn, int thin) { LIST res = gatherRecords(); @@ -138,12 +144,40 @@ class McmcTriangular { } return res; } + + /** + * @brief Return `LdltRecords` + * + * @param num_burn Number of burn-in + * @param thin Thinning + * @param sparse If `true`, return sparsified draws. + * @return LdltRecords `LdltRecords` object + */ LdltRecords returnLdltRecords(int num_burn, int thin, bool sparse = false) const { return reg_record->returnLdltRecords(sparse_record, num_iter, num_burn, thin, sparse); } + + /** + * @brief Return `SvRecords` + * + * @param num_burn Number of burn-in + * @param thin Thinning + * @param sparse If `true`, return sparsified draws. + * @return SvRecords `SvRecords` object + */ SvRecords returnSvRecords(int num_burn, int thin, bool sparse = false) const { return reg_record->returnSvRecords(sparse_record, num_iter, num_burn, thin, sparse); } + + /** + * @brief Return `LdltRecords` or `SvRecords` + * + * @tparam RecordType `LdltRecords` or `SvRecords` + * @param num_burn Number of burn-in + * @param thin Thinning + * @param sparse If `true`, return sparsified draws. + * @return RecordType `LdltRecords` or `SvRecords` + */ template RecordType returnStructRecords(int num_burn, int thin, bool sparse = false) const { return reg_record->returnRecords(sparse_record, num_iter, num_burn, thin, sparse); @@ -183,13 +217,53 @@ class McmcTriangular { Eigen::MatrixXd sqrt_sv; // stack sqrt of exp(h_t) = (exp(-h_1t / 2), ..., exp(-h_kt / 2)), t = 1, ..., n => n x k Eigen::VectorXd prior_sig_shp; Eigen::VectorXd prior_sig_scl; + + /** + * @brief Draw state vector + * + */ virtual void updateState() = 0; + + /** + * @brief Compute D + * + */ virtual void updateSv() = 0; + + /** + * @brief Save coefficient records + * + */ virtual void updateCoefRecords() = 0; + + /** + * @brief Draw precision of coefficient based on each shrinkage priors + * + */ virtual void updateCoefPrec() = 0; + + /** + * @brief Update SAVS penalty + * + */ virtual void updatePenalty() = 0; + + /** + * @brief Draw precision of contemporaneous coefficient based on each shrinkage priors + * + */ virtual void updateImpactPrec() = 0; + + /** + * @brief Save MCMC records + * + */ virtual void updateRecords() = 0; + + /** + * @brief Draw coefficients + * + */ void updateCoef() { for (int j = 0; j < dim; ++j) { coef_mat.col(j).setZero(); // j-th column of A = 0 @@ -226,6 +300,11 @@ class McmcTriangular { draw_mn_savs(sparse_coef.col(j), coef_mat.col(j), x, penalty_j); } } + + /** + * @brief Draw contemporaneous coefficients + * + */ void updateImpact() { for (int j = 1; j < dim; ++j) { response_contem = latent_innov.col(j).array() / sqrt_sv.col(j).array(); // n-dim @@ -241,8 +320,23 @@ class McmcTriangular { draw_savs(sparse_contem.segment(contem_id, j), contem_coef.segment(contem_id, j), latent_innov.leftCols(j)); } } + + /** + * @brief Compute residual matrix for orthogonalization + * + */ void updateLatent() { latent_innov = y - x * coef_mat; } + + /** + * @brief Compute L + * + */ void updateChol() { chol_lower = build_inv_lower(dim, contem_coef); } + + /** + * @brief Increment the MCMC step + * + */ void addStep() { mcmc_step++; } }; From 896a1f8d27f7ebbfe238333509d7ebd8dba84968 Mon Sep 17 00:00:00 2001 From: Young Geun Kim Date: Mon, 16 Dec 2024 21:25:31 +0900 Subject: [PATCH 4/9] fill doxygen comments in bvharforecaster --- inst/include/bvharforecaster.h | 256 +++++++++++++++++++++++++++++++++ inst/include/bvharmcmc.h | 20 ++- 2 files changed, 269 insertions(+), 7 deletions(-) diff --git a/inst/include/bvharforecaster.h b/inst/include/bvharforecaster.h index b322fcda..1e1ddfa2 100644 --- a/inst/include/bvharforecaster.h +++ b/inst/include/bvharforecaster.h @@ -20,6 +20,10 @@ template class McmcExpandforecastRun; template