Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:11

0001 
0002 #ifndef EGAMMAOBJECTS_GBRForest2D
0003 #define EGAMMAOBJECTS_GBRForest2D
0004 
0005 //////////////////////////////////////////////////////////////////////////
0006 //                                                                      //
0007 // GBRForest2D                                                            //
0008 //                                                                      //
0009 // A fast minimal implementation of Gradient-Boosted Regression Trees   //
0010 // which has been especially optimized for size on disk and in memory.  //
0011 //                                                                      //
0012 // Designed to be built from TMVA-trained trees, but could also be      //
0013 // generalized to otherwise-trained trees, classification,              //
0014 //  or other boosting methods in the future                             //
0015 //                                                                      //
0016 //  Josh Bendavid - MIT                                                 //
0017 //////////////////////////////////////////////////////////////////////////
0018 
0019 #include "CondFormats/Serialization/interface/Serializable.h"
0020 
0021 #include "GBRTree2D.h"
0022 
0023 #include <vector>
0024 
0025 class GBRForest2D {
0026 public:
0027   GBRForest2D() {}
0028 
0029   void GetResponse(const float *vector, double &x, double &y) const;
0030 
0031   void SetInitialResponse(double x, double y) {
0032     fInitialResponseX = x;
0033     fInitialResponseY = y;
0034   }
0035 
0036   std::vector<GBRTree2D> &Trees() { return fTrees; }
0037   const std::vector<GBRTree2D> &Trees() const { return fTrees; }
0038 
0039 protected:
0040   double fInitialResponseX = 0.0;
0041   double fInitialResponseY = 0.0;
0042   std::vector<GBRTree2D> fTrees;
0043 
0044   COND_SERIALIZABLE;
0045 };
0046 
0047 //_______________________________________________________________________
0048 inline void GBRForest2D::GetResponse(const float *vector, double &x, double &y) const {
0049   x = fInitialResponseX;
0050   y = fInitialResponseY;
0051   double tx, ty;
0052   for (std::vector<GBRTree2D>::const_iterator it = fTrees.begin(); it != fTrees.end(); ++it) {
0053     it->GetResponse(vector, tx, ty);
0054     x += tx;
0055     y += ty;
0056   }
0057   return;
0058 }
0059 
0060 #endif