Skip to content

Commit

Permalink
fix some dl lines for numerical stability
Browse files Browse the repository at this point in the history
  • Loading branch information
ygeunkim committed Dec 23, 2024
1 parent c9180ed commit d4f00c1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions inst/include/bvhardraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ inline void dl_latent(Eigen::VectorXd& latent_param, Eigen::Ref<const Eigen::Vec
inline void dl_local_sparsity(Eigen::VectorXd& local_param, double& dir_concen,
Eigen::Ref<const Eigen::VectorXd> 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();
}
Expand All @@ -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<const Eigen::VectorXd> local_param, double& dir_concen,
Eigen::Ref<Eigen::VectorXd> 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
Expand Down Expand Up @@ -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
);
}
}

Expand Down

0 comments on commit d4f00c1

Please sign in to comment.