CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DeterministicAnnealing.cc
Go to the documentation of this file.
3 #include <cmath>
4 #include <vector>
5 #include <iostream>
6 #include <limits>
7 
8 using namespace std;
9 
11  theTemperatures({256,64,16,4,2,1}),
13 {
14 }
15 
16 DeterministicAnnealing::DeterministicAnnealing( const vector < float > & sched, float cutoff ) :
17  theTemperatures(sched),theIndex(0), theChi2cut ( cutoff*cutoff ), theIsAnnealed ( false )
18 {
19 }
20 
22 {
23  if ( theIndex < ( theTemperatures.size() - 1 ) )
24  {
25  theIndex++;
26  } else {
27  theIsAnnealed = true;
28  };
29 }
30 
31 double DeterministicAnnealing::weight ( double chi2 ) const
32 {
33  long double mphi = phi ( chi2 );
34  /*
35  if ( mphi < std::numeric_limits<double>::epsilon() ) return 0.;
36  return 1. / ( 1. + phi ( theChi2cut * theChi2cut ) / mphi );
37  */
38  // return mphi / ( mphi + phi ( theChi2cut ) );
39  long double newtmp = mphi / ( mphi + phi ( theChi2cut ) );
40  if ( edm::isNotFinite(newtmp ) )
41  {
42  if ( chi2 < theChi2cut ) newtmp=1.;
43  else newtmp=0.;
44  }
45  return newtmp;
46 }
47 
49 {
50  theIndex=0;
51  theIsAnnealed = false;
52 }
53 
54 inline double DeterministicAnnealing::phi( double chi2 ) const
55 {
56  return exp ( -.5 * chi2 / theTemperatures[theIndex] );
57 }
58 
60 {
61  return sqrt(theChi2cut);
62 }
63 
65 {
66  return theTemperatures[theIndex];
67 }
68 
70 {
71  return theTemperatures[0];
72 }
73 
75 {
76  return theIsAnnealed;
77 }
78 
80 {
81  cout << "[DeterministicAnnealing] schedule=";
82  for ( vector< float >::const_iterator i=theTemperatures.begin();
83  i!=theTemperatures.end() ; ++i )
84  {
85  cout << *i << " ";
86  };
87  cout << endl;
88 }
int i
Definition: DBlmapReader.cc:9
double weight(double chi2) const
theIndex(0)
bool isNotFinite(T x)
Definition: isFinite.h:10
T sqrt(T t)
Definition: SSEVec.h:48
theIsAnnealed(false)
theChi2cut(cutoff *cutoff)
DeterministicAnnealing(float cutoff=3.0)
tuple cout
Definition: gather_cfg.py:121
std::vector< float > theTemperatures
volatile std::atomic< bool > shutdown_flag false
double phi(double chi2) const