Exemplo n.º 1
0
 size_t operator()(size_t numActive) {
   adjustPermSize(numActive);
   if (stepsLeft_-- == 0) {
     stepsLeft_ = stepsBetweenSelect_ - 1;
     shufflePrefix();
   }
   return perm_[uniform_(std::min(numActive, subsetSize_))];
 }
Exemplo n.º 2
0
 // Method to return the parameter value for a walker randomly chosen from the
 // complementary ensemble
 arma::vec GrabParameter()
 {
     do {
         // Randomly pick another walker from the complementary ensemble
         other_parameter_index_ = uniform_(rng);
     } while (other_parameter_index_ == this->parameter_index_);
     
     // Return the value of the parameter
     return this->ensemble_[other_parameter_index_].Value();
 }
Exemplo n.º 3
0
// Method to calculate whether the proposal is accepted
bool AdaptiveMetro::Accept(arma::vec new_value, arma::vec old_value) {

    // MH accept/reject criteria: Proposal must be symmetric!!
    alpha_ = (parameter_.LogDensity(new_value) - parameter_.LogDensity(old_value)) / parameter_.GetTemperature();

    if (!arma::is_finite(alpha_)) {
        // New value of the log-posterior is not finite, so reject this
        // proposal
        alpha_ = 0.0;
        return false;
    }

    double unif = uniform_(rng);
    alpha_ = std::min(exp(alpha_), 1.0);
    if (unif < alpha_) {
        naccept_++;
        return true;
    } else {
        return false;
    }
}