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