Ejemplo n.º 1
0
 void MMS::draw(){
   Ptr<MvnSuf> s = mvn->suf();
   double n = s->n();
   const Spd &siginv(mvn->siginv());
   const Spd &ominv(mu_prior_->siginv());
   Spd Ivar = n*siginv + ominv;
   Vec mu = Ivar.solve(n*(siginv*s->ybar()) + ominv*mu_prior_->mu());
   mu = rmvn_ivar(mu, Ivar);
   mvn->set_mu(mu);
 }
Ejemplo n.º 2
0
 void ArPosteriorSampler::draw_phi(){
   const Spd &xtx(model_->suf()->xtx());
   const Vec &xty(model_->suf()->xty());
   Vec phi_hat = xtx.solve(xty);
   bool ok = false;
   int attempts = 0;
   while (!ok && ++attempts <= max_number_of_regression_proposals_) {
     Vec phi = rmvn_ivar(phi_hat, xtx / model_->sigsq());
     ok = ArModel::check_stationary(phi);
     if(ok) model_->set_phi(phi);
   }
   if(!ok){
     draw_phi_univariate();
   }
 }
  void BLSSS::draw_beta() {
    Selector g = m_->coef().inc();
    if(g.nvars() == 0) {
      m_->drop_all();
      return;
    }
    SpdMatrix ivar = g.select(pri_->siginv());
    Vector ivar_mu = ivar * g.select(pri_->mu());
    ivar += g.select(suf().xtx());
    ivar_mu += g.select(suf().xty());
    Vector b = ivar.solve(ivar_mu);
    b = rmvn_ivar(b, ivar);

    // If model selection is turned off and some elements of beta
    // happen to be zero (because, e.g., of a failed MH step) we don't
    // want the dimension of beta to change.
    m_->set_included_coefficients(b, g);
  }