5#ifndef MVAUtils_Forest_H
6#define MVAUtils_Forest_H
21 inline T
sigmoid(T
x) {
return 1. / (1. + exp(-
x)); }
34 inline std::vector<index_t>
computeRight(
const std::vector<int>& vars);
52 template<
typename Node_t>
57 unsigned int itree)
const override final;
59 unsigned int itree)
const override final;
63 virtual float GetOffset()
const override {
return 0.; }
68 const std::vector<float>& values)
const override final;
70 const std::vector<float*>&
pointers)
const override final;
76 const std::vector<float>& values)
const override;
78 const std::vector<float*>&
pointers)
const override;
87 const std::vector<float>& values,
88 unsigned int numClasses)
const override;
92 unsigned int numClasses)
const override;
101 virtual void PrintTree(
unsigned int itree)
const override;
104 std::vector<Node_t>
GetTree(
unsigned int itree)
const;
114 void newTree(
const std::vector<Node_t>& nodes);
Generic Forest base class.
virtual float GetRawResponse(const std::vector< float * > &pointers) const override final
void newTree(const std::vector< Node_t > &nodes)
append a new tree (defined by a vector of nodes serialized in preorder) to the forest
std::vector< Node_t > GetTree(unsigned int itree) const
Return the vector of nodes for the tree itree.
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 float GetOffset() const override
Return the offset of the forest.
std::vector< index_t > m_forest
indices of the top-level nodes of each tree
float GetTreeResponseFromNode(const std::vector< float * > &pointers, index_t index) const
virtual std::vector< float > GetMultiResponse(const std::vector< float * > &pointers, unsigned int numClasses) const override
virtual float GetTreeResponse(const std::vector< float * > &pointers, unsigned int itree) const override final
virtual float GetRawResponse(const std::vector< float > &values) const override final
Return the response of the whole Forest.
std::vector< Node_t > m_nodes
where the nodes of the forest are stored
virtual void PrintForest() const override
virtual float GetResponse(const std::vector< float * > &pointers) const override
virtual void PrintTree(unsigned int itree) const override
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 o...
virtual float GetResponse(const std::vector< float > &values) const override
Compute the prediction for regression.
float GetTreeResponseFromNode(const std::vector< float > &values, index_t index) const
Get the response of a tree.
virtual unsigned int GetNTrees() const override final
Compute the response from the binary trees in the forest.
void applySoftmax(Container_t &x)
apply softmax to the input: {exp[xi] / sum(exp[xj]) for xi in x}
std::vector< index_t > computeRight(const std::vector< int > &vars)
Compute the offsets between the nodes to their right children from a serialized representation of the...
int32_t index_t
The index type of the node in the vector.
std::vector< T * > pointers(std::vector< T > &v)