本文整理汇总了C++中Rand::rand_sinvchi2方法的典型用法代码示例。如果您正苦于以下问题:C++ Rand::rand_sinvchi2方法的具体用法?C++ Rand::rand_sinvchi2怎么用?C++ Rand::rand_sinvchi2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rand
的用法示例。
在下文中一共展示了Rand::rand_sinvchi2方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: beta
void Prior::sample_tau2(Model* model, Rand& rng)
{
const std::vector<DataModel::ef_t>& x_types = model->x_types;
const VectorView& beta = model->beta;
double alpha2_sigma2 = alpha2_ * model->sigma2;
if (use_individual_tau2){
for (size_t i = m_e; i < beta.length(); ++i){
double nu = nu_tau2[x_types[i]] + 1.0;
double s2 = (nus2_tau2[x_types[i]] + beta(i) * beta(i) / alpha2_sigma2) / nu;
model->inv_tau2_alpha2(i) = 1.0 / (alpha2_ * rng.rand_sinvchi2(nu, s2));
assert(model->inv_tau2_alpha2(i) > 0);
}
} else {
size_t m = beta.length();
double beta2sum[] = {0.0, 0.0, 0.0, 0.0};
size_t m_types[] = {0, 0, 0, 0};
for (size_t i = m_e; i < m; ++i){
beta2sum[x_types[i]] += beta(i) * beta(i);
++m_types[x_types[i]];
}
for (size_t t = 0; t < 4; ++t){
if (allow_terms[t]){
double nu = nu_tau2[t] + m_types[t];
double s2 = (nus2_tau2[t] + beta2sum[t] / alpha2_sigma2) / nu;
assert(std::isfinite(s2));
inv_tau2_alpha2[t] = 1.0 / (alpha2_ * rng.rand_sinvchi2(nu, s2));
assert(inv_tau2_alpha2[t] > 0);
}
}
for (size_t i = m_e; i < m; ++i){
model->inv_tau2_alpha2(i) = inv_tau2_alpha2[x_types[i]];
}
}
model->mu_beta_computed = false;
}