src/ell/MinimumSelector.cc
Go to the documentation of this file.00001 #include "ell/MinimumSelector.hh" 00002 00003 namespace ell 00004 { 00005 00007 MinimumSelector::~MinimumSelector() 00009 { 00010 } 00011 00012 } // namespace ell 00013 00014 #include "biu/RandomNumberFactory.hh" 00015 00016 namespace ell 00017 { 00019 MS_Uniform:: 00020 MS_Uniform() 00022 { 00023 } 00024 00025 00027 MS_Uniform:: 00028 ~MS_Uniform() 00030 { 00031 } 00032 00034 size_t 00035 MS_Uniform:: 00036 select( const LandscapeTopology* const lt 00037 , const bool minimaChanged ) 00039 { 00040 size_t selected = LandscapeTopology::INVALID_INDEX; 00041 00042 // select uniformly a minimum 00043 if (lt->getMinCount() > 0) { 00044 selected = (size_t)biu::RNF::getRN((unsigned int)lt->getMinCount()); 00045 } 00046 00047 return selected; 00048 } 00049 00050 } // namespace ell 00051 00052 #include <cmath> 00053 #include <algorithm> 00054 00055 namespace ell 00056 { 00058 MS_Boltzmann:: 00059 MS_Boltzmann( const double shiftFactor_ ) 00060 : shiftFactor( shiftFactor_ ) 00061 , boltzWeightSum() 00063 { 00064 } 00065 00066 00068 MS_Boltzmann:: 00069 ~MS_Boltzmann() 00071 { 00072 } 00073 00075 size_t 00076 MS_Boltzmann:: 00077 select( const LandscapeTopology* const lt 00078 , const bool minimaChanged ) 00080 { 00081 size_t selected = LandscapeTopology::INVALID_INDEX; 00082 00083 // select uniformly a minimum 00084 if (lt->getMinCount() > 0) { 00085 // check if boltzWeightSum has to be updated 00086 if (minimaChanged || boltzWeightSum.size()!=(lt->getMinCount()+1)) { 00087 // resize the weight sum container 00088 boltzWeightSum.resize(lt->getMinCount()+1,0.0); 00089 // sum successively over the Boltzmann weights 00090 boltzWeightSum[0] = 0.0; 00091 for (size_t i=1; i<boltzWeightSum.size(); i++) { 00092 boltzWeightSum[i] = exp( -lt->getMin(i-1)->getEnergy() 00093 / LandscapeTopology::BOLTZMANN_KT ) 00094 + boltzWeightSum[i-1]; 00095 } 00096 } 00097 // calculate a random number in interval [0,fullBoltzWeightSum] 00098 double selectedProp = (((double) biu::RNF::getRN()) 00099 / ((double) biu::RNF::getMaxRN())) 00100 * (*(boltzWeightSum.rbegin())); 00101 // get index of the corresponding interval to find the minimum 00102 std::vector<double>::const_iterator pos 00103 = std::lower_bound( boltzWeightSum.begin() 00104 , boltzWeightSum.end() 00105 , selectedProp ); 00106 // recalculate position from iterators 00107 selected = (size_t)(pos - boltzWeightSum.begin()); 00108 } 00109 00110 return selected; 00111 } 00112 00113 } // namespace ell 00114 00115