ATLAS Offline Software
Loading...
Searching...
No Matches
MVAUtils::Forest< Node_t > Class Template Referenceabstract

Generic Forest base class. More...

#include <Forest.h>

Inheritance diagram for MVAUtils::Forest< Node_t >:
Collaboration diagram for MVAUtils::Forest< Node_t >:

Public Member Functions

virtual float GetTreeResponse (const std::vector< float > &values, unsigned int itree) const override final
 Return the response of one tree Must pass the features in a std::vector<float> values and the index of the tree.
virtual float GetTreeResponse (const std::vector< float * > &pointers, unsigned int itree) const override final
virtual float GetOffset () const override
 Return the offset of the forest.
virtual float GetRawResponse (const std::vector< float > &values) const override final
 Return the response of the whole Forest.
virtual float GetRawResponse (const std::vector< float * > &pointers) const override final
virtual float GetResponse (const std::vector< float > &values) const override
 Compute the prediction for regression.
virtual float GetResponse (const std::vector< float * > &pointers) const override
virtual std::vector< float > GetMultiResponse (const std::vector< float > &values, unsigned int numClasses) const override
 Compute the prediction for multiclassification (a score for each class).
virtual std::vector< float > GetMultiResponse (const std::vector< float * > &pointers, unsigned int numClasses) const override
virtual unsigned int GetNTrees () const override final
virtual void PrintForest () const override
virtual void PrintTree (unsigned int itree) const override
std::vector< Node_t > GetTree (unsigned int itree) const
 Return the vector of nodes for the tree itree.
virtual float GetClassification (const std::vector< float > &values) const =0
 Compute the prediction of a classification.
virtual float GetClassification (const std::vector< float * > &pointers) const =0
virtual TTree * WriteTree (TString) const =0
 Return a TTree representing the BDT.
virtual int GetNVars () const =0
 Get the number of input variable to be passed with std::vector to Get* methods.

Protected Member Functions

float GetTreeResponseFromNode (const std::vector< float > &values, index_t index) const
 Get the response of a tree.
float GetTreeResponseFromNode (const std::vector< float * > &pointers, index_t index) const
void newTree (const std::vector< Node_t > &nodes)
 append a new tree (defined by a vector of nodes serialized in preorder) to the forest

Private Attributes

std::vector< index_tm_forest
 indices of the top-level nodes of each tree
std::vector< Node_t > m_nodes
 where the nodes of the forest are stored

Detailed Description

template<typename Node_t>
class MVAUtils::Forest< Node_t >

Generic Forest base class.

It implements only the non-specific methods. It implement a representation of the forest and basic methods that are common to the other implementations. It does not provide a contructor since that is specific to derived classes. Concrete classes should derive from this.

The goal of this class is to manage the creation and the computation of the raw-response of the trees. Derived class should implement how the raw-response of the trees are used to compute the final predictions. Some prediction methods (e.g. GetResponseMulticlass) are implemented here since they are common to the present final concrete classes (TMVA/lgbm)

Definition at line 53 of file Forest.h.

Member Function Documentation

◆ GetClassification() [1/2]

virtual float MVAUtils::IForest::GetClassification ( const std::vector< float * > & pointers) const
pure virtualinherited

◆ GetClassification() [2/2]

virtual float MVAUtils::IForest::GetClassification ( const std::vector< float > & values) const
pure virtualinherited

◆ GetMultiResponse() [1/2]

template<typename Node_t>
virtual std::vector< float > MVAUtils::Forest< Node_t >::GetMultiResponse ( const std::vector< float * > & pointers,
unsigned int numClasses ) const
overridevirtual

Implements MVAUtils::IForest.

◆ GetMultiResponse() [2/2]

template<typename Node_t>
virtual std::vector< float > MVAUtils::Forest< Node_t >::GetMultiResponse ( const std::vector< float > & values,
unsigned int numClasses ) const
overridevirtual

Compute the prediction for multiclassification (a score for each class).

In addition to the input values need to pass the number of classes

Implements MVAUtils::IForest.

◆ GetNTrees()

template<typename Node_t>
virtual unsigned int MVAUtils::Forest< Node_t >::GetNTrees ( ) const
inlinefinaloverridevirtual

Implements MVAUtils::IForest.

Definition at line 94 of file Forest.h.

95 {
96 return m_forest.size();
97 }
std::vector< index_t > m_forest
indices of the top-level nodes of each tree
Definition Forest.h:117

◆ GetNVars()

virtual int MVAUtils::IForest::GetNVars ( ) const
pure virtualinherited

Get the number of input variable to be passed with std::vector to Get* methods.

Implemented in MVAUtils::ForestLGBM, MVAUtils::ForestLGBMSimple, MVAUtils::ForestTMVA, and MVAUtils::ForestXGBoost.

◆ GetOffset()

template<typename Node_t>
virtual float MVAUtils::Forest< Node_t >::GetOffset ( ) const
inlineoverridevirtual

Return the offset of the forest.

Since by default there is no offset, return 0

Implements MVAUtils::IForest.

Reimplemented in MVAUtils::ForestWeighted< Node_t >, and MVAUtils::ForestWeighted< NodeTMVA >.

Definition at line 63 of file Forest.h.

63{ return 0.; }

◆ GetRawResponse() [1/2]

template<typename Node_t>
virtual float MVAUtils::Forest< Node_t >::GetRawResponse ( const std::vector< float * > & pointers) const
finaloverridevirtual

Implements MVAUtils::IForest.

◆ GetRawResponse() [2/2]

template<typename Node_t>
virtual float MVAUtils::Forest< Node_t >::GetRawResponse ( const std::vector< float > & values) const
finaloverridevirtual

Return the response of the whole Forest.

Raw is just the sum of all the trees

Implements MVAUtils::IForest.

◆ GetResponse() [1/2]

template<typename Node_t>
virtual float MVAUtils::Forest< Node_t >::GetResponse ( const std::vector< float * > & pointers) const
overridevirtual

Implements MVAUtils::IForest.

◆ GetResponse() [2/2]

template<typename Node_t>
virtual float MVAUtils::Forest< Node_t >::GetResponse ( const std::vector< float > & values) const
overridevirtual

Compute the prediction for regression.

Implements MVAUtils::IForest.

Reimplemented in MVAUtils::ForestTMVA.

◆ GetTree()

template<typename Node_t>
std::vector< Node_t > MVAUtils::Forest< Node_t >::GetTree ( unsigned int itree) const

Return the vector of nodes for the tree itree.

◆ GetTreeResponse() [1/2]

template<typename Node_t>
virtual float MVAUtils::Forest< Node_t >::GetTreeResponse ( const std::vector< float * > & pointers,
unsigned int itree ) const
finaloverridevirtual

Implements MVAUtils::IForest.

◆ GetTreeResponse() [2/2]

template<typename Node_t>
virtual float MVAUtils::Forest< Node_t >::GetTreeResponse ( const std::vector< float > & values,
unsigned int itree ) const
finaloverridevirtual

Return the response of one tree Must pass the features in a std::vector<float> values and the index of the tree.

Implements MVAUtils::IForest.

◆ GetTreeResponseFromNode() [1/2]

template<typename Node_t>
float MVAUtils::Forest< Node_t >::GetTreeResponseFromNode ( const std::vector< float * > & pointers,
index_t index ) const
protected

◆ GetTreeResponseFromNode() [2/2]

template<typename Node_t>
float MVAUtils::Forest< Node_t >::GetTreeResponseFromNode ( const std::vector< float > & values,
index_t index ) const
protected

Get the response of a tree.

Instead of specifying the index of the tree (as in GetTreeResponse) the index of the top node of the tree should be specified

◆ newTree()

template<typename Node_t>
void MVAUtils::Forest< Node_t >::newTree ( const std::vector< Node_t > & nodes)
protected

append a new tree (defined by a vector of nodes serialized in preorder) to the forest

◆ PrintForest()

template<typename Node_t>
virtual void MVAUtils::Forest< Node_t >::PrintForest ( ) const
overridevirtual

◆ PrintTree()

template<typename Node_t>
virtual void MVAUtils::Forest< Node_t >::PrintTree ( unsigned int itree) const
overridevirtual

◆ WriteTree()

virtual TTree * MVAUtils::IForest::WriteTree ( TString ) const
pure virtualinherited

Return a TTree representing the BDT.

The called is the owner of the returned TTree

Implemented in MVAUtils::ForestLGBM, MVAUtils::ForestLGBMSimple, MVAUtils::ForestTMVA, and MVAUtils::ForestXGBoost.

Member Data Documentation

◆ m_forest

template<typename Node_t>
std::vector<index_t> MVAUtils::Forest< Node_t >::m_forest
private

indices of the top-level nodes of each tree

Definition at line 117 of file Forest.h.

◆ m_nodes

template<typename Node_t>
std::vector<Node_t> MVAUtils::Forest< Node_t >::m_nodes
private

where the nodes of the forest are stored

Definition at line 118 of file Forest.h.


The documentation for this class was generated from the following file: