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 
27  public:
28 
29  GBRForest();
30 
31  double GetResponse(const float* vector) const;
32  double GetGradBoostClassifier(const float* vector) const;
33  double GetAdaBoostClassifier(const float* vector) const { return GetResponse(vector); }
34 
35  //for backwards-compatibility
36  double GetClassifier(const float* vector) const { return GetGradBoostClassifier(vector); }
37 
38  void SetInitialResponse(double response) { fInitialResponse = response; }
39 
40  std::vector<GBRTree> &Trees() { return fTrees; }
41  const std::vector<GBRTree> &Trees() const { return fTrees; }
42 
43  protected:
44 
46  std::vector<GBRTree> fTrees;
47 
48 
50 };
51 
52 //_______________________________________________________________________
53 inline double GBRForest::GetResponse(const float* vector) const {
54  double response = fInitialResponse;
55  for (std::vector<GBRTree>::const_iterator it=fTrees.begin(); it!=fTrees.end(); ++it) {
56  response += it->GetResponse(vector);
57  }
58  return response;
59 }
60 
61 //_______________________________________________________________________
62 inline double GBRForest::GetGradBoostClassifier(const float* vector) const {
63  double response = GetResponse(vector);
64  return 2.0/(1.0+exp(-2.0*response))-1; //MVA output between -1 and 1
65 }
66 
67 #endif
double fInitialResponse
Definition: GBRForest.h:45
double GetResponse(const float *vector) const
Definition: GBRForest.h:53
std::vector< GBRTree > & Trees()
Definition: GBRForest.h:40
void SetInitialResponse(double response)
Definition: GBRForest.h:38
double GetGradBoostClassifier(const float *vector) const
Definition: GBRForest.h:62
std::vector< GBRTree > fTrees
Definition: GBRForest.h:46
const std::vector< GBRTree > & Trees() const
Definition: GBRForest.h:41
#define COND_SERIALIZABLE
Definition: Serializable.h:38
double GetClassifier(const float *vector) const
Definition: GBRForest.h:36
double GetAdaBoostClassifier(const float *vector) const
Definition: GBRForest.h:33