CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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}), theIndex(0), theChi2cut(cutoff * cutoff), theIsAnnealed(false) {}
12 
13 DeterministicAnnealing::DeterministicAnnealing(const vector<float>& sched, float cutoff)
14  : theTemperatures(sched), theIndex(0), theChi2cut(cutoff * cutoff), theIsAnnealed(false) {}
15 
17  if (theIndex < (theTemperatures.size() - 1)) {
18  theIndex++;
19  } else {
20  theIsAnnealed = true;
21  };
22 }
23 
24 double DeterministicAnnealing::weight(double chi2) const {
25  long double mphi = phi(chi2);
26  /*
27  if ( mphi < std::numeric_limits<double>::epsilon() ) return 0.;
28  return 1. / ( 1. + phi ( theChi2cut * theChi2cut ) / mphi );
29  */
30  // return mphi / ( mphi + phi ( theChi2cut ) );
31  long double newtmp = mphi / (mphi + phi(theChi2cut));
32  if (edm::isNotFinite(newtmp)) {
33  if (chi2 < theChi2cut)
34  newtmp = 1.;
35  else
36  newtmp = 0.;
37  }
38  return newtmp;
39 }
40 
42  theIndex = 0;
43  theIsAnnealed = false;
44 }
45 
46 inline double DeterministicAnnealing::phi(double chi2) const { return exp(-.5 * chi2 / theTemperatures[theIndex]); }
47 
48 double DeterministicAnnealing::cutoff() const { return sqrt(theChi2cut); }
49 
51 
53 
55 
57  cout << "[DeterministicAnnealing] schedule=";
58  for (vector<float>::const_iterator i = theTemperatures.begin(); i != theTemperatures.end(); ++i) {
59  cout << *i << " ";
60  };
61  cout << endl;
62 }
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
theIndex(0)
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
double currentTemp() const override
double phi(double chi2) const override
T sqrt(T t)
Definition: SSEVec.h:19
theIsAnnealed(false)
double weight(double chi2) const override
double cutoff() const override
double initialTemp() const override
theChi2cut(cutoff *cutoff)
DeterministicAnnealing(float cutoff=3.0)
bool isAnnealed() const override
tuple cout
Definition: gather_cfg.py:144
std::vector< float > theTemperatures
void debug() const override