ATLAS Offline Software
Loading...
Searching...
No Matches
Reconstruction/MVAUtils/MVAUtils/BDT.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef MVAUtils_BDT_H
6#define MVAUtils_BDT_H
7
9#include "TString.h"
10#include <vector>
11#include <map>
12#include <cassert>
13#include <memory>
14#include <cmath>
15#include "ForestBase.h"
16
17class TTree;
18namespace MVAUtils
19{
20
33
34 class BDT
35 {
36 public:
42 explicit BDT(TTree *tree);//ctor TTree
43
44 explicit BDT(std::unique_ptr<IForest> forest):
45 m_forest(std::move(forest)){
46 }
47
48 /* delete default ctor
49 * and default copy / assignment*/
50 BDT() = delete;
51 BDT (const BDT&) = delete;
52 BDT& operator=(const BDT&) = delete;
55 BDT (BDT&&) = default;
56 BDT& operator=(BDT&&) = default;
57 ~BDT()=default;
58
59
60
62 unsigned int GetNTrees() const ;
64 int GetNVars() const ;
66 float GetOffset() const ;
68 float GetResponse(const std::vector<float>& values) const;
69 float GetResponse(const std::vector<float*>& pointers) const;
70 float GetResponse() const;
71
73 float GetClassification(const std::vector<float>& values) const;
74 float GetClassification(const std::vector<float*>& pointers) const;
75 float GetClassification() const;
76
77 // TMVA specific: return 2.0/(1.0+exp(-2.0*sum))-1, with no offset.
78 float GetGradBoostMVA(const std::vector<float>& values) const;
79 float GetGradBoostMVA(const std::vector<float*>& pointers) const;
80
82 std::vector<float> GetMultiResponse(const std::vector<float>& values, unsigned int numClasses) const;
83 std::vector<float> GetMultiResponse(const std::vector<float*>& pointers, unsigned int numClasses) const;
84 std::vector<float> GetMultiResponse(unsigned int numClasses) const;
85
87 std::vector<float> GetValues() const;
89 const std::vector<float*>& GetPointers() const;
91 void SetPointers(const std::vector<float*>& pointers);
92
96 TTree* WriteTree(TString name = "BDT") const;
97
99 void PrintForest() const;
100 void PrintTree(unsigned int itree) const;
101
103 float GetTreeResponse(const std::vector<float>& values, MVAUtils::index_t index) const;
104 float GetTreeResponse(const std::vector<float*>& pointers, MVAUtils::index_t index) const;
105
106 private:
107 std::unique_ptr<IForest> m_forest;
108 std::vector<float*> m_pointers;
109 };
110}
111
112#include "MVAUtils/BDT.icc"
113#endif
BDT(std::unique_ptr< IForest > forest)
float GetResponse(const std::vector< float * > &pointers) const
BDT(TTree *tree)
Constructor.
float GetClassification(const std::vector< float * > &pointers) const
int GetNVars() const
Number of variables expected in the inputs.
void SetPointers(const std::vector< float * > &pointers)
Set the stored pointers so that one can use methods with no args.
const std::vector< float * > & GetPointers() const
Return stored pointers (which are used by methods with no args)
std::vector< float > GetValues() const
Return the values corresponding to m_pointers (or an empty vector)
float GetTreeResponse(const std::vector< float > &values, MVAUtils::index_t index) const
for debugging, return the response of a sigle tree given the index of its top node
std::vector< float > GetMultiResponse(const std::vector< float > &values, unsigned int numClasses) const
Get response of the forest, for multiclassification (e.g.
float GetTreeResponse(const std::vector< float * > &pointers, MVAUtils::index_t index) const
BDT(BDT &&)=default
default move ctor, move assignment and dtor
float GetGradBoostMVA(const std::vector< float * > &pointers) const
TTree * WriteTree(TString name="BDT") const
Return a TTree representing the BDT: each entry is a binary tree, each element of the vectors is a no...
Definition BDT.cxx:91
std::vector< float > GetMultiResponse(const std::vector< float * > &pointers, unsigned int numClasses) const
float GetOffset() const
Get the offset to the whole forest.
std::unique_ptr< IForest > m_forest
the implementation of the forest, doing the hard work
void PrintTree(unsigned int itree) const
Definition BDT.cxx:93
~BDT()=default
unsigned int GetNTrees() const
Number of trees in the whole forest.
float GetClassification(const std::vector< float > &values) const
Get response of the forest, for classification.
BDT & operator=(BDT &&)=default
float GetResponse(const std::vector< float > &values) const
Get response of the forest, for regression.
std::vector< float * > m_pointers
where vars to cut on can be set (but can also be passed)
float GetResponse() const
std::vector< float > GetMultiResponse(unsigned int numClasses) const
BDT & operator=(const BDT &)=delete
void PrintForest() const
for debugging, print out tree or forest to stdout
Definition BDT.cxx:92
BDT(const BDT &)=delete
float GetClassification() const
float GetGradBoostMVA(const std::vector< float > &values) const
BDT()=delete
int32_t index_t
The index type of the node in the vector.
Definition index.py:1
STL namespace.
std::vector< T * > pointers(std::vector< T > &v)
Definition rmain.cxx:367
TChain * tree