CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
20 
21 #include <vector>
22 #include "GBRTree.h"
23 #include <math.h>
24 #include <stdio.h>
25 
26  namespace TMVA {
27  class MethodBDT;
28  }
29 
30  class GBRForest {
31 
32  public:
33 
34  GBRForest();
35  explicit GBRForest(const TMVA::MethodBDT *bdt);
36  virtual ~GBRForest();
37 
38  double GetResponse(const float* vector) const;
39  double GetClassifier(const float* vector) const;
40 
41  void SetInitialResponse(double response) { fInitialResponse = response; }
42 
43  std::vector<GBRTree> &Trees() { return fTrees; }
44  const std::vector<GBRTree> &Trees() const { return fTrees; }
45 
46  protected:
48  std::vector<GBRTree> fTrees;
49 
50 
52 };
53 
54 //_______________________________________________________________________
55 inline double GBRForest::GetResponse(const float* vector) const {
56  double response = fInitialResponse;
57  for (std::vector<GBRTree>::const_iterator it=fTrees.begin(); it!=fTrees.end(); ++it) {
58  response += it->GetResponse(vector);
59  }
60  return response;
61 }
62 
63 //_______________________________________________________________________
64 inline double GBRForest::GetClassifier(const float* vector) const {
65  double response = GetResponse(vector);
66  return 2.0/(1.0+exp(-2.0*response))-1; //MVA output between -1 and 1
67 }
68 
69 #endif
double fInitialResponse
Definition: GBRForest.h:47
double GetResponse(const float *vector) const
Definition: GBRForest.h:55
virtual ~GBRForest()
std::vector< GBRTree > & Trees()
Definition: GBRForest.h:43
void SetInitialResponse(double response)
Definition: GBRForest.h:41
std::vector< GBRTree > fTrees
Definition: GBRForest.h:48
const std::vector< GBRTree > & Trees() const
Definition: GBRForest.h:44
#define COND_SERIALIZABLE
Definition: Serializable.h:30
double GetClassifier(const float *vector) const
Definition: GBRForest.h:64