本文整理汇总了C++中Rand::rand_normal方法的典型用法代码示例。如果您正苦于以下问题:C++ Rand::rand_normal方法的具体用法?C++ Rand::rand_normal怎么用?C++ Rand::rand_normal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rand
的用法示例。
在下文中一共展示了Rand::rand_normal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sample_alpha
double Prior::sample_alpha(Model* model, const VectorView& y, Rand& rng)
{
// then use full conditional of alpha to update it
size_t nterms = (model->beta).length() - m_e;
double a = alpha_;
do { // disallow exact zero value
if (nterms > 0){
// propose switching sign of alpha and eta (sign of eta has no effect as long
// as we actually sample beta; note that eta has symmetric zero mean
// distribution); this is metropolis move with deterministic
// proposal; no effect is mu_alpha is zero (might as well skip...)
if ((a <= 0.0) || log(rng.rand_01()) <= -2.0 * mu_alpha * a){
a = -a;
}
Vector xb(n);
Vector eb(n);
xb.set_to_product((model->x).columnblock(m_e, nterms),
(model->beta).block(m_e, nterms), false);
eb.set_to_product((model->x).columnblock(0, m_e),
(model->beta).block(0, m_e), false);
eb -= y; // note: this is E * b - y, hence there is minus below in mu formul.
double alpha_sigma2 = a * model->sigma2;
double var = 1.0 / (1.0 + VectorView::dotproduct(xb, xb) / (a * alpha_sigma2));
double mu = var * (mu_alpha - VectorView::dotproduct(eb, xb) / alpha_sigma2);
a = sqrt(var) * rng.rand_normal() + mu;
} else {
// sample from prior
a = rng.rand_normal() + mu_alpha;
}
} while (a == 0 || a * a == 0);
model->mu_beta_computed = false;
return a;
}