double GenericGaussianVarianceSampler::draw(
     RNG &rng,
     double data_df,
     double data_ss) const {
   double DF = data_df + 2 * prior_->alpha();
   double SS = data_ss + 2 * prior_->beta();
   if (sigma_max_ == 0.0) {
     return 0.0;
   } else if(sigma_max_ == infinity()){
     return 1.0 / rgamma_mt(rng, DF/2, SS/2);
   } else {
     return 1.0 / rtrun_gamma_mt(rng, DF/2, SS/2, 1.0/square(sigma_max_));
   }
 }
Beispiel #2
0
  // Draws sigma given phi and observed data.
  void ArPosteriorSampler::draw_sigma(){
    // ss = y - xb  y - xb
    //     = yty - 2 bt xty + bt xtx b
    const Vec &phi(model_->phi());
    const Vec &xty(model_->suf()->xty());
    const Spd &xtx(model_->suf()->xtx());
    double ss = 2 * siginv_prior_->beta();
    ss += xtx.Mdist(phi) - 2 * phi.dot(xty) + model_->suf()->yty();

    double df = 2 * siginv_prior_->alpha();
    df += model_->suf()->n();

    double siginv;
    if (upper_sigma_truncation_point_ == BOOM::infinity()) {
      siginv = rgamma_mt(rng(), df/2, ss/2);
    } else {
      siginv = rtrun_gamma_mt(rng(), df/2, ss/2,
                           1.0/pow(upper_sigma_truncation_point_, 2));
    }
    model_->set_sigsq(1.0 / siginv);
  }