void BLSSS::draw_model_indicators() { Selector g = m_->coef().inc(); std::vector<int> indx = seq<int>(0, g.nvars_possible()-1); // I'd like to rely on std::random_shuffle for this, but I want // control over the random number generator. for (int i = 0; i < indx.size(); ++i) { int j = random_int_mt(rng(), 0, indx.size() - 1); std::swap(indx[i], indx[j]); } double logp = log_model_prob(g); if(!std::isfinite(logp)) { vpri_->make_valid(g); logp = log_model_prob(g); } if(!std::isfinite(logp)) { ostringstream err; err << "BinomialLogitSpikeSlabSampler did not start with a " << "legal configuration." << endl << "Selector vector: " << g << endl << "beta: " << m_->included_coefficients() << endl; report_error(err.str()); } uint n = g.nvars_possible(); if(max_flips_ > 0) n = std::min<int>(n, max_flips_); for(uint i=0; i<n; ++i) { logp = mcmc_one_flip(g, indx[i], logp); } m_->coef().set_inc(g); }
void LSB::draw_gamma(){ // draws vector of 0's and 1's indicating which coefficients are // nonzero if(max_nflips_ == 0) return; Selector inc = mod_->inc(); uint nv = inc.nvars_possible(); double logp = log_model_prob(inc); if(!std::isfinite(logp)){ ostringstream err; err << "LogitSamplerBma did not start with a legal configuration." << endl << "Selector vector: " << inc << endl << "beta: " << mod_->included_coefficients() <<endl; throw_exception<std::runtime_error>(err.str()); } std::vector<uint> flips = seq<uint>(0, nv-1); std::random_shuffle(flips.begin(), flips.end()); uint hi = std::min<uint>(nv, max_nflips_); for(uint i=0; i<hi; ++i){ uint I = flips[i]; inc.flip(I); double logp_new = log_model_prob(inc); if( keep_flip(logp, logp_new)) logp = logp_new; else inc.flip(I); // reject the flip, so flip back } mod_->coef().set_inc(inc); }