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 
9 namespace {
10  vector < float > temperatures;
11 }
12 
14  theIndex(0), theChi2cut ( cutoff*cutoff ), theIsAnnealed ( false )
15 {
16  temperatures.push_back(256);
17  temperatures.push_back(64);
18  temperatures.push_back(16);
19  temperatures.push_back(4);
20  temperatures.push_back(2);
21  temperatures.push_back(1);
22 }
23 
24 DeterministicAnnealing::DeterministicAnnealing( const vector < float > & sched,
25  float cutoff ) : theIndex(0), theChi2cut ( cutoff*cutoff ), theIsAnnealed ( false )
26 {
27  temperatures = sched;
28 }
29 
31 {
32  if ( theIndex < ( temperatures.size() - 1 ) )
33  {
34  theIndex++;
35  } else {
36  theIsAnnealed = true;
37  };
38 }
39 
40 double DeterministicAnnealing::weight ( double chi2 ) const
41 {
42  long double mphi = phi ( chi2 );
43  /*
44  if ( mphi < std::numeric_limits<double>::epsilon() ) return 0.;
45  return 1. / ( 1. + phi ( theChi2cut * theChi2cut ) / mphi );
46  */
47  // return mphi / ( mphi + phi ( theChi2cut ) );
48  long double newtmp = mphi / ( mphi + phi ( theChi2cut ) );
49  if ( std::isinf(newtmp ) )
50  {
51  if ( chi2 < theChi2cut ) newtmp=1.;
52  else newtmp=0.;
53  }
54  return newtmp;
55 }
56 
58 {
59  theIndex=0;
60  theIsAnnealed = false;
61 }
62 
63 inline double DeterministicAnnealing::phi( double chi2 ) const
64 {
65  return exp ( -.5 * chi2 / temperatures[theIndex] );
66 }
67 
69 {
70  return sqrt(theChi2cut);
71 }
72 
74 {
75  return temperatures[theIndex];
76 }
77 
79 {
80  return temperatures[0];
81 }
82 
84 {
85  return theIsAnnealed;
86 }
87 
89 {
90  cout << "[DeterministicAnnealing] schedule=";
91  for ( vector< float >::const_iterator i=temperatures.begin();
92  i!=temperatures.end() ; ++i )
93  {
94  cout << *i << " ";
95  };
96  cout << endl;
97 }
int i
Definition: DBlmapReader.cc:9
double weight(double chi2) const
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
T sqrt(T t)
Definition: SSEVec.h:28
DeterministicAnnealing(float cutoff=3.0)
tuple cout
Definition: gather_cfg.py:41
double phi(double chi2) const