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.
2 #include <cmath>
3 #include <vector>
4 #include <iostream>
5 #include <limits>
6 
7 using namespace std;
8 
10  theTemperatures({256,64,16,4,2,1}),
12 {
13 }
14 
15 DeterministicAnnealing::DeterministicAnnealing( const vector < float > & sched, float cutoff ) :
16  theTemperatures(sched),theIndex(0), theChi2cut ( cutoff*cutoff ), theIsAnnealed ( false )
17 {
18 }
19 
21 {
22  if ( theIndex < ( theTemperatures.size() - 1 ) )
23  {
24  theIndex++;
25  } else {
26  theIsAnnealed = true;
27  };
28 }
29 
30 double DeterministicAnnealing::weight ( double chi2 ) const
31 {
32  long double mphi = phi ( chi2 );
33  /*
34  if ( mphi < std::numeric_limits<double>::epsilon() ) return 0.;
35  return 1. / ( 1. + phi ( theChi2cut * theChi2cut ) / mphi );
36  */
37  // return mphi / ( mphi + phi ( theChi2cut ) );
38  long double newtmp = mphi / ( mphi + phi ( theChi2cut ) );
39  if ( std::isinf(newtmp ) )
40  {
41  if ( chi2 < theChi2cut ) newtmp=1.;
42  else newtmp=0.;
43  }
44  return newtmp;
45 }
46 
48 {
49  theIndex=0;
50  theIsAnnealed = false;
51 }
52 
53 inline double DeterministicAnnealing::phi( double chi2 ) const
54 {
55  return exp ( -.5 * chi2 / theTemperatures[theIndex] );
56 }
57 
59 {
60  return sqrt(theChi2cut);
61 }
62 
64 {
65  return theTemperatures[theIndex];
66 }
67 
69 {
70  return theTemperatures[0];
71 }
72 
74 {
75  return theIsAnnealed;
76 }
77 
79 {
80  cout << "[DeterministicAnnealing] schedule=";
81  for ( vector< float >::const_iterator i=theTemperatures.begin();
82  i!=theTemperatures.end() ; ++i )
83  {
84  cout << *i << " ";
85  };
86  cout << endl;
87 }
int i
Definition: DBlmapReader.cc:9
double weight(double chi2) const
theIndex(0)
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