void HybridMonteCarlo::do_step()
{
    //gibbs sampler on x and v
    //persistence=p samples p times x and once v
    //However because it's constant E, a rejected move
    //will result in recalculating the same move up to p times
    //until it is either accepted or the velocities are redrawn
    //since p has to be independent of the outcome (markov property)
    //we avoid recalculating the trajectory on rejection by just trying
    //it over and over without doing the md again.
    persistence_counter_ += 1;
    if (persistence_counter_ == persistence_)
    {
        persistence_counter_ = 0;
        //boltzmann constant in kcal/mol
        static const double kB = 8.31441 / 4186.6;
        md_->assign_velocities(get_kt() / kB);
    }
    double last = do_evaluate(get_model()->get_particles());
    ParticlesTemp moved = do_move(get_move_probability());
    double energy = do_evaluate(moved);
    bool accepted = do_accept_or_reject_move(energy, last);
    while ((!accepted) && (persistence_counter_ < persistence_-1))
    {
        persistence_counter_ += 1;
        accepted = do_accept_or_reject_move(energy, last);
    }

    /*std::cout << "hmc"
        << " old " << last
        << " new " << energy
        << " delta " << energy-last
        << " accepted " << accepted
        <<std::endl;*/
}
Example #2
0
void MonteCarlo::do_step() {
    MonteCarloMoverResult moved = do_move();
    MoverCleanup cleanup(this);
    double energy = do_evaluate(moved.get_moved_particles());
    do_accept_or_reject_move(energy, moved.get_proposal_ratio());
    cleanup.reset();
}
Example #3
0
void HybridMonteCarlo::do_step()
{
    //gibbs sampler on x and v
    //persistence=p samples p times x and once v
    //However because it's constant E, a rejected move
    //will result in recalculating the same move up to p times
    //until it is either accepted or the velocities are redrawn
    //since p has to be independent of the outcome (markov property)
    //we avoid recalculating the trajectory on rejection by just trying
    //it over and over without doing the md again.
    persistence_counter_ += 1;
    if (persistence_counter_ == persistence_)
    {
        persistence_counter_ = 0;
        //boltzmann constant in kcal/mol
        static const double kB = 8.31441 / 4186.6;
        md_->assign_velocities(get_kt() / kB);
    }
    ParticleIndexes all_optimized_particles;
    {
      ModelObjectsTemp op = get_model()->get_optimized_particles();
      for (unsigned int i = 0; i< op.size(); ++i) {
        all_optimized_particles.push_back(dynamic_cast<Particle*>(op[i].get())
                                          ->get_index());
      }
    }
    double last = do_evaluate(all_optimized_particles);
    core::MonteCarloMoverResult moved = do_move();

    double energy = do_evaluate(all_optimized_particles);
    bool accepted = do_accept_or_reject_move(energy, last,
                                             moved.get_proposal_ratio());
    while ((!accepted) && (persistence_counter_ < persistence_-1))
    {
        persistence_counter_ += 1;
        accepted = do_accept_or_reject_move(energy, last,
                                            moved.get_proposal_ratio());
    }

    /*std::cout << "hmc"
        << " old " << last
        << " new " << energy
        << " delta " << energy-last
        << " accepted " << accepted
        <<std::endl;*/
}