//---------------------------------------------------------------------- void BLCSSS::rwm_draw(){ if(m_->coef().nvars() == 0) return; int total_number_of_chunks = compute_number_of_chunks(max_rwm_chunk_size_); for(int chunk = 0; chunk < total_number_of_chunks; ++chunk) { rwm_draw_chunk(chunk); } }
//---------------------------------------------------------------------- // TODO(stevescott): This code currently discards the tim_sampler void BLCSSS::tim_draw(){ int nvars = m_->coef().nvars(); if(nvars == 0) return; int chunk_size = compute_chunk_size(max_tim_chunk_size_); int number_of_chunks = compute_number_of_chunks(max_tim_chunk_size_); assert(number_of_chunks * chunk_size >= nvars); for(int chunk = 0; chunk < number_of_chunks; ++chunk) { clock_t mode_start = clock(); TIM tim_sampler(log_posterior(chunk, max_tim_chunk_size_), tdf_, &rng()); Vector beta = m_->included_coefficients(); int start = chunk_size * chunk; int elements_remaining = nvars - start; VectorView beta_chunk(beta, start, std::min(elements_remaining, chunk_size)); bool ok = tim_sampler.locate_mode(beta_chunk); move_accounting_.stop_time("tim mode finding", mode_start); if (ok) { move_accounting_.record_acceptance("tim mode finding"); tim_sampler.fix_mode(true); MoveTimer timer = move_accounting_.start_time("TIM chunk"); beta_chunk = tim_sampler.draw(beta_chunk); m_->set_included_coefficients(beta); if (tim_sampler.last_draw_was_accepted()) { move_accounting_.record_acceptance("TIM chunk"); } else { move_accounting_.record_rejection("TIM chunk"); } } else { move_accounting_.record_rejection("tim mode finding"); rwm_draw_chunk(chunk); } } }
//---------------------------------------------------------------------- void BLCSSS::tim_draw(){ int nvars = m_->coef().nvars(); if(nvars == 0) return; int chunk_size = compute_chunk_size(); int number_of_chunks = compute_number_of_chunks(); assert(number_of_chunks * chunk_size >= nvars); for(int chunk = 0; chunk < number_of_chunks; ++chunk) { ++tim_chunk_attempts_; clock_t mode_start = clock(); TIM tim_sampler(log_posterior(chunk), tdf_); Vec beta = m_->beta(); int start = chunk_size * chunk; int elements_remaining = nvars - start; VectorView beta_chunk(beta, start, std::min(elements_remaining, chunk_size)); bool ok = tim_sampler.locate_mode(beta_chunk); clock_t mode_end = clock(); double mode_time = double(mode_end - mode_start) / CLOCKS_PER_SEC; tim_mode_finding_times_ += mode_time; if(ok){ tim_sampler.fix_mode(true); clock_t trial_start = clock(); beta_chunk = tim_sampler.draw(beta_chunk); m_->set_beta(beta); tim_chunk_successes_ += tim_sampler.last_draw_was_accepted(); clock_t trial_end = clock(); tim_trial_times_ += double(trial_end - trial_start) / CLOCKS_PER_SEC; }else{ rwm_draw_chunk(chunk); tim_mode_finding_wasted_time_ += mode_time; ++tim_chunk_mode_failures_; } } }