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  public:
14  // Constructor(s)/Destructor
15  Forest();
16  Forest(std::vector<Event*>& trainingEvents);
17  ~Forest();
18 
19  Forest(const Forest& forest);
20  Forest& operator=(const Forest& forest);
21  Forest(Forest&& forest) = default;
22 
23  // Get/Set
24  void setTrainingEvents(std::vector<Event*>& trainingEvents);
25  std::vector<Event*> getTrainingEvents();
26 
27  // Returns the number of trees in the forest.
28  unsigned int size();
29 
30  // Get info on variable importance.
31  void rankVariables(std::vector<int>& rank);
32 
33  // Output the list of split values used for each variable.
34  void saveSplitValues(const char* savefilename);
35 
36  // Helpful operations
37  void listEvents(std::vector<std::vector<Event*> >& e);
38  void sortEventVectors(std::vector<std::vector<Event*> >& e);
39  void generate(int numTrainEvents, int numTestEvents, double sigma);
40  void loadForestFromXML(const char* directory, unsigned int numTrees);
42 
43  // Perform the regression
44  void updateRegTargets(Tree* tree, double learningRate, LossFunction* l);
45  void doRegression(int nodeLimit,
46  int treeLimit,
47  double learningRate,
48  LossFunction* l,
49  const char* savetreesdirectory,
50  bool saveTrees);
51 
52  // Stochastic Gradient Boosting
53  void prepareRandomSubsample(double fraction);
54  void doStochasticRegression(int nodeLimit, int treeLimit, double learningRate, double fraction, LossFunction* l);
55 
56  // Predict some events
57  void updateEvents(Tree* tree);
58  void appendCorrection(std::vector<Event*>& eventsp, int treenum);
59  void predictEvents(std::vector<Event*>& eventsp, unsigned int trees);
60  void appendCorrection(Event* e, int treenum);
61  void predictEvent(Event* e, unsigned int trees);
62 
63  Tree* getTree(unsigned int i);
64 
65  private:
66  std::vector<std::vector<Event*> > events;
67  std::vector<std::vector<Event*> > subSample;
68  std::vector<Tree*> trees;
69  };
70 
71 } // namespace emtf
72 
73 #endif
void predictEvents(std::vector< Event *> &eventsp, unsigned int trees)
Definition: Forest.cc:406
void predictEvent(Event *e, unsigned int trees)
Definition: Forest.cc:440
std::vector< std::vector< Event * > > events
Definition: Forest.h:66
void updateEvents(Tree *tree)
Definition: Forest.cc:328
void prepareRandomSubsample(double fraction)
Definition: Forest.cc:521
void doRegression(int nodeLimit, int treeLimit, double learningRate, LossFunction *l, const char *savetreesdirectory, bool saveTrees)
Definition: Forest.cc:355
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:548
Definition: Event.h:15
void saveSplitValues(const char *savefilename)
Definition: Forest.cc:245
void loadFromCondPayload(const L1TMuonEndCapForest::DForest &payload)
Definition: Forest.cc:497
void updateRegTargets(Tree *tree, double learningRate, LossFunction *l)
Definition: Forest.cc:289
std::vector< Event * > getTrainingEvents()
Definition: Forest.cc:107
void listEvents(std::vector< std::vector< Event *> > &e)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Definition: Forest.cc:142
std::vector< DTree > DForest
void sortEventVectors(std::vector< std::vector< Event *> > &e)
Definition: Forest.cc:181
void generate(int numTrainEvents, int numTestEvents, double sigma)
std::vector< Tree * > trees
Definition: Forest.h:68
unsigned int size()
Definition: Forest.cc:127
void loadForestFromXML(const char *directory, unsigned int numTrees)
Definition: Forest.cc:477
void setTrainingEvents(std::vector< Event *> &trainingEvents)
Definition: Forest.cc:87
void rankVariables(std::vector< int > &rank)
Definition: Forest.cc:195
Tree * getTree(unsigned int i)
Definition: Forest.cc:114
Forest & operator=(const Forest &forest)
Definition: Forest.cc:70
void appendCorrection(std::vector< Event *> &eventsp, int treenum)
Definition: Forest.cc:426
Definition: tree.py:1