mcpele
1.0.0
The Monte Carlo Python Energy Landscape Explorer
|
00001 #include "mcpele/adaptive_takestep.h" 00002 00003 namespace mcpele { 00004 00005 AdaptiveTakeStep::AdaptiveTakeStep(std::shared_ptr<TakeStep> ts, 00006 const size_t interval, const double factor, 00007 const double min_acceptance_ratio, const double max_acceptance_ratio) 00008 : m_ts(ts), 00009 m_interval(interval), 00010 m_total_steps(0), 00011 m_accepted_steps(0), 00012 m_factor(factor), 00013 m_min_acceptance_ratio(min_acceptance_ratio), 00014 m_max_acceptance_ratio(max_acceptance_ratio) 00015 { 00016 if (factor <= 0 || factor >= 1) { 00017 throw std::runtime_error("AdaptiveTakeStep::AdaptiveTakeStep: input factor has illegal value"); 00018 } 00019 } 00020 00021 void AdaptiveTakeStep::report(pele::Array<double>&, const double, 00022 pele::Array<double>&, const double, const bool success, MC* mc) 00023 { 00024 ++m_total_steps; 00025 if (success) { 00026 ++m_accepted_steps; 00027 } 00028 if (mc->get_iterations_count() % m_interval == 0) { 00029 const double acceptance_fraction = static_cast<double>(m_accepted_steps) / static_cast<double>(m_total_steps); 00030 m_accepted_steps = 0; 00031 m_total_steps = 0; 00032 if (acceptance_fraction < get_min_acceptance_ratio()) { 00033 m_ts->increase_acceptance(m_factor); 00034 } 00035 else if (acceptance_fraction > get_max_acceptance_ratio()) { 00036 m_ts->decrease_acceptance(m_factor); 00037 } 00038 } 00039 } 00040 00041 } // namespace mcpele