CMS 3D CMS Logo

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 <cmath>
24 #include <cstdio>
25 #include "Rtypes.h"
26 
27 class GBRForestD {
28 public:
29  typedef GBRTreeD TreeT;
30 
31  GBRForestD();
32  template <typename InputForestT>
33  GBRForestD(const InputForestT &forest);
34  virtual ~GBRForestD();
35 
36  double GetResponse(const float *vector) const;
37 
38  double InitialResponse() const { return fInitialResponse; }
39  void SetInitialResponse(double response) { fInitialResponse = response; }
40 
41  std::vector<GBRTreeD> &Trees() { return fTrees; }
42  const std::vector<GBRTreeD> &Trees() const { return fTrees; }
43 
44 protected:
46  std::vector<GBRTreeD> fTrees;
47 
49 };
50 
51 //_______________________________________________________________________
52 inline double GBRForestD::GetResponse(const float *vector) const {
53  double response = fInitialResponse;
54  for (std::vector<GBRTreeD>::const_iterator it = fTrees.begin(); it != fTrees.end(); ++it) {
55  int termidx = it->TerminalIndex(vector);
56  response += it->GetResponse(termidx);
57  }
58  return response;
59 }
60 
61 //_______________________________________________________________________
62 template <typename InputForestT>
63 GBRForestD::GBRForestD(const InputForestT &forest) : fInitialResponse(forest.InitialResponse()) {
64  //templated constructor to allow construction from Forest classes in GBRLikelihood
65  //without creating an explicit dependency
66 
67  for (typename std::vector<typename InputForestT::TreeT>::const_iterator treeit = forest.Trees().begin();
68  treeit != forest.Trees().end();
69  ++treeit) {
70  fTrees.push_back(GBRTreeD(*treeit));
71  }
72 }
73 
74 #endif
double GetResponse(const float *vector) const
Definition: GBRForestD.h:52
std::vector< GBRTreeD > & Trees()
Definition: GBRForestD.h:41
double InitialResponse() const
Definition: GBRForestD.h:38
std::vector< GBRTreeD > fTrees
Definition: GBRForestD.h:46
void SetInitialResponse(double response)
Definition: GBRForestD.h:39
GBRTreeD TreeT
Definition: GBRForestD.h:29
#define COND_SERIALIZABLE
Definition: Serializable.h:38
const std::vector< GBRTreeD > & Trees() const
Definition: GBRForestD.h:42
virtual ~GBRForestD()
Definition: GBRForestD.cc:7
double fInitialResponse
Definition: GBRForestD.h:45