CMS 3D CMS Logo

Forest.h
Go to the documentation of this file.
1 // Forest.h
2 
3 #ifndef L1Trigger_L1TMuonEndCap_emtf_Forest
4 #define L1Trigger_L1TMuonEndCap_emtf_Forest
5 
6 #include "Tree.h"
7 #include "LossFunctions.h"
9 
10 namespace emtf {
11 
12 class Forest
13 {
14  public:
15 
16  // Constructor(s)/Destructor
17  Forest();
18  Forest(std::vector<Event*>& trainingEvents);
19  ~Forest();
20 
21  Forest(const Forest &forest);
22  Forest& operator=(const Forest &forest);
23  Forest(Forest && forest) = default;
24 
25  // Get/Set
26  void setTrainingEvents(std::vector<Event*>& trainingEvents);
27  std::vector<Event*> getTrainingEvents();
28 
29  // Returns the number of trees in the forest.
30  unsigned int size();
31 
32  // Get info on variable importance.
33  void rankVariables(std::vector<int>& rank);
34 
35  // Output the list of split values used for each variable.
36  void saveSplitValues(const char* savefilename);
37 
38  // Helpful operations
39  void listEvents(std::vector< std::vector<Event*> >& e);
40  void sortEventVectors(std::vector< std::vector<Event*> >& e);
41  void generate(int numTrainEvents, int numTestEvents, double sigma);
42  void loadForestFromXML(const char* directory, unsigned int numTrees);
44 
45  // Perform the regression
46  void updateRegTargets(Tree *tree, double learningRate, LossFunction* l);
47  void doRegression(int nodeLimit, int treeLimit, double learningRate, LossFunction* l,
48  const char* savetreesdirectory, bool saveTrees);
49 
50  // Stochastic Gradient Boosting
51  void prepareRandomSubsample(double fraction);
52  void doStochasticRegression(int nodeLimit, int treeLimit, double learningRate,
53  double fraction, LossFunction* l);
54 
55  // Predict some events
56  void updateEvents(Tree* tree);
57  void appendCorrection(std::vector<Event*>& eventsp, int treenum);
58  void predictEvents(std::vector<Event*>& eventsp, unsigned int trees);
59  void appendCorrection(Event* e, int treenum);
60  void predictEvent(Event* e, unsigned int trees);
61 
62  Tree* getTree(unsigned int i);
63 
64  private:
65 
66  std::vector< std::vector<Event*> > events;
67  std::vector< std::vector<Event*> > subSample;
68  std::vector<Tree*> trees;
69 };
70 
71 } // end of emtf namespace
72 
73 #endif
void appendCorrection(std::vector< Event * > &eventsp, int treenum)
Definition: Forest.cc:464
void predictEvent(Event *e, unsigned int trees)
Definition: Forest.cc:479
void updateEvents(Tree *tree)
Definition: Forest.cc:364
void prepareRandomSubsample(double fraction)
Definition: Forest.cc:568
void doRegression(int nodeLimit, int treeLimit, double learningRate, LossFunction *l, const char *savetreesdirectory, bool saveTrees)
Definition: Forest.cc:394
std::vector< std::vector< Event * > > subSample
Definition: Forest.h:67
void doStochasticRegression(int nodeLimit, int treeLimit, double learningRate, double fraction, LossFunction *l)
Definition: Forest.cc:597
void sortEventVectors(std::vector< std::vector< Event * > > &e)
Definition: Forest.cc:203
Definition: Event.h:15
void saveSplitValues(const char *savefilename)
Definition: Forest.cc:274
void loadFromCondPayload(const L1TMuonEndCapForest::DForest &payload)
Definition: Forest.cc:542
void updateRegTargets(Tree *tree, double learningRate, LossFunction *l)
Definition: Forest.cc:322
std::vector< Event * > getTrainingEvents()
Definition: Forest.cc:122
std::vector< DTree > DForest
void generate(int numTrainEvents, int numTestEvents, double sigma)
std::vector< Tree * > trees
Definition: Forest.h:68
void listEvents(std::vector< std::vector< Event * > > &e)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Definition: Forest.cc:159
unsigned int size()
Definition: Forest.cc:143
void loadForestFromXML(const char *directory, unsigned int numTrees)
Definition: Forest.cc:520
void rankVariables(std::vector< int > &rank)
Definition: Forest.cc:219
Tree * getTree(unsigned int i)
Definition: Forest.cc:129
Forest & operator=(const Forest &forest)
Definition: Forest.cc:80
void predictEvents(std::vector< Event * > &eventsp, unsigned int trees)
Definition: Forest.cc:441
Definition: tree.py:1
std::vector< std::vector< Event * > > events
Definition: Forest.h:66
void setTrainingEvents(std::vector< Event * > &trainingEvents)
Definition: Forest.cc:100