CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GBRForestD.h
Go to the documentation of this file.
1 
2 #ifndef EGAMMAOBJECTS_GBRForestD
3 #define EGAMMAOBJECTS_GBRForestD
4 
6 // //
7 // GBRForestD //
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 the output of GBRLikelihood, //
13 // but could also be generalized to otherwise-trained trees //
14 // classification, or other boosting methods in the future //
15 // //
16 // Josh Bendavid - CERN //
18 
20 
21 #include <vector>
22 #include "GBRTreeD.h"
23 #include <math.h>
24 #include <stdio.h>
25 #include "Rtypes.h"
26 
27 class GBRForestD {
28  public:
29  typedef GBRTreeD TreeT;
30 
31  GBRForestD();
32  template<typename InputForestT> GBRForestD(const InputForestT &forest);
33  virtual ~GBRForestD();
34 
35  double GetResponse(const float* vector) const;
36 
37  double InitialResponse() const { return fInitialResponse; }
38  void SetInitialResponse(double response) { fInitialResponse = response; }
39 
40  std::vector<GBRTreeD> &Trees() { return fTrees; }
41  const std::vector<GBRTreeD> &Trees() const { return fTrees; }
42 
43  protected:
45  std::vector<GBRTreeD> fTrees;
46 
48 };
49 
50 //_______________________________________________________________________
51 inline double GBRForestD::GetResponse(const float* vector) const {
52  double response = fInitialResponse;
53  for (std::vector<GBRTreeD>::const_iterator it=fTrees.begin(); it!=fTrees.end(); ++it) {
54  int termidx = it->TerminalIndex(vector);
55  response += it->GetResponse(termidx);
56  }
57  return response;
58 }
59 
60 //_______________________________________________________________________
61 template<typename InputForestT> GBRForestD::GBRForestD(const InputForestT &forest) :
62  fInitialResponse(forest.InitialResponse()) {
63  //templated constructor to allow construction from Forest classes in GBRLikelihood
64  //without creating an explicit dependency
65 
66  for (typename std::vector<typename InputForestT::TreeT>::const_iterator treeit = forest.Trees().begin(); treeit!=forest.Trees().end(); ++treeit) {
67  fTrees.push_back(GBRTreeD(*treeit));
68  }
69 
70 }
71 
72 
73 
74 #endif
double GetResponse(const float *vector) const
Definition: GBRForestD.h:51
std::vector< GBRTreeD > & Trees()
Definition: GBRForestD.h:40
double InitialResponse() const
Definition: GBRForestD.h:37
std::vector< GBRTreeD > fTrees
Definition: GBRForestD.h:45
void SetInitialResponse(double response)
Definition: GBRForestD.h:38
GBRTreeD TreeT
Definition: GBRForestD.h:29
#define COND_SERIALIZABLE
Definition: Serializable.h:37
const std::vector< GBRTreeD > & Trees() const
Definition: GBRForestD.h:41
virtual ~GBRForestD()
Definition: GBRForestD.cc:11
double fInitialResponse
Definition: GBRForestD.h:44