From d4f00c1cf99788ed0659c7207869d1d0f6cc0985 Mon Sep 17 00:00:00 2001 From: Young Geun Kim Date: Sun, 22 Dec 2024 16:57:31 -0800 Subject: [PATCH] fix some dl lines for numerical stability --- inst/include/bvhardraw.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/inst/include/bvhardraw.h b/inst/include/bvhardraw.h index c436f886..f34f4741 100644 --- a/inst/include/bvhardraw.h +++ b/inst/include/bvhardraw.h @@ -765,7 +765,7 @@ inline void dl_latent(Eigen::VectorXd& latent_param, Eigen::Ref coef, boost::random::mt19937& rng) { for (int i = 0; i < coef.size(); ++i) { - local_param[i] = sim_gig(1, dir_concen - 1, 1, 2 * abs(coef[i]), rng)[0]; + local_param[i] = 1 / sim_gig(1, 1 - dir_concen, 1, 2 * abs(coef[i]), rng)[0]; } local_param /= local_param.sum(); } @@ -778,7 +778,7 @@ inline void dl_local_sparsity(Eigen::VectorXd& local_param, double& dir_concen, // @param rng boost rng inline double dl_global_sparsity(Eigen::Ref local_param, double& dir_concen, Eigen::Ref coef, boost::random::mt19937& rng) { - return sim_gig(1, coef.size() * (dir_concen - 1), 1, 2 * (coef.cwiseAbs().array() / local_param.array()).sum(), rng)[0]; + return 1 / sim_gig(1, coef.size() * (1 - dir_concen), 1, 2 * (coef.cwiseAbs().array() / local_param.array()).sum(), rng)[0]; } // Generating Group Parameter of Dirichlet-Laplace Prior @@ -806,12 +806,12 @@ inline void dl_mn_sparsity(Eigen::VectorXd& group_param, Eigen::VectorXi& grp_ve mn_scl[k++] = abs(coef_vec[j]) / (global_param * local_param[j]); } } - group_param[i] = sim_gig(1, shape - mn_size, 2 * rate, 2 * mn_scl.sum(), rng)[0]; - // group_param[i] = 1 / gamma_rand( - // shape + mn_size, - // 1 / (rate + mn_scl.sum()), - // rng - // ); + // group_param[i] = sim_gig(1, shape - mn_size, 2 * rate, 2 * mn_scl.sum(), rng)[0]; + group_param[i] = 1 / gamma_rand( + shape + mn_size, + 1 / (rate + mn_scl.sum()), + rng + ); } }