CMS 3D CMS Logo

GBRForest.h
Go to the documentation of this file.
1 
2 #ifndef EGAMMAOBJECTS_GBRForest
3 #define EGAMMAOBJECTS_GBRForest
4 
6 // //
7 // GBRForest //
8 // //
9 // A fast minimal implementation of Gradient-Boosted Regression Trees //
10 // which has been especially optimized for size on disk and in memory. //
11 // //
12 // Designed to be built from TMVA-trained trees, but could also be //
13 // generalized to otherwise-trained trees, classification, //
14 // or other boosting methods in the future //
15 // //
16 // Josh Bendavid - MIT //
18 
21 
22 #include <vector>
23 #include <cmath>
24 
25 class GBRForest {
26 public:
27  GBRForest();
28 
29  double GetResponse(const float* vector) const;
30  double GetGradBoostClassifier(const float* vector) const;
31  double GetAdaBoostClassifier(const float* vector) const { return GetResponse(vector); }
32 
33  //for backwards-compatibility
34  double GetClassifier(const float* vector) const { return GetGradBoostClassifier(vector); }
35 
36  void SetInitialResponse(double response) { fInitialResponse = response; }
37 
38  std::vector<GBRTree>& Trees() { return fTrees; }
39  const std::vector<GBRTree>& Trees() const { return fTrees; }
40 
41 protected:
43  std::vector<GBRTree> fTrees;
44 
46 };
47 
48 //_______________________________________________________________________
49 inline double GBRForest::GetResponse(const float* vector) const {
50  double response = fInitialResponse;
51  for (std::vector<GBRTree>::const_iterator it = fTrees.begin(); it != fTrees.end(); ++it) {
52  response += it->GetResponse(vector);
53  }
54  return response;
55 }
56 
57 //_______________________________________________________________________
58 inline double GBRForest::GetGradBoostClassifier(const float* vector) const {
59  double response = GetResponse(vector);
60  return 2.0 / (1.0 + exp(-2.0 * response)) - 1; //MVA output between -1 and 1
61 }
62 
63 #endif
GBRForest::GetClassifier
double GetClassifier(const float *vector) const
Definition: GBRForest.h:34
GBRForest::GetGradBoostClassifier
double GetGradBoostClassifier(const float *vector) const
Definition: GBRForest.h:58
GBRTree.h
GBRForest
Definition: GBRForest.h:25
COND_SERIALIZABLE
#define COND_SERIALIZABLE
Definition: Serializable.h:39
GBRForest::Trees
std::vector< GBRTree > & Trees()
Definition: GBRForest.h:38
GBRForest::GetResponse
double GetResponse(const float *vector) const
Definition: GBRForest.h:49
GBRForest::Trees
const std::vector< GBRTree > & Trees() const
Definition: GBRForest.h:39
GBRForest::fTrees
std::vector< GBRTree > fTrees
Definition: GBRForest.h:43
Serializable.h
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
GBRForest::GBRForest
GBRForest()
GBRForest::SetInitialResponse
void SetInitialResponse(double response)
Definition: GBRForest.h:36
GBRForest::GetAdaBoostClassifier
double GetAdaBoostClassifier(const float *vector) const
Definition: GBRForest.h:31
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
GBRForest::fInitialResponse
double fInitialResponse
Definition: GBRForest.h:42