ATLAS Offline Software
ForestTMVA.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 namespace MVAUtils {
5 
6 template<typename Node_t>
7 float
8 ForestWeighted<Node_t>::GetTreeResponseWeighted(
9  const std::vector<float>& values,
10  unsigned int itree) const
11 {
12  return Forest<Node_t>::GetTreeResponse(values, itree) * m_weights[itree];
13 }
14 template<typename Node_t>
15 float
16 ForestWeighted<Node_t>::GetTreeResponseWeighted(
17  const std::vector<float*>& pointers,
18  unsigned int itree) const
19 {
20  return Forest<Node_t>::GetTreeResponse(pointers, itree) * m_weights[itree];
21 }
22 
23 template<typename Node_t>
24 float
25 ForestWeighted<Node_t>::GetWeightedResponse(
26  const std::vector<float>& values) const
27 {
28  float result = 0.;
29  for (unsigned int itree = 0; itree != GetNTrees(); ++itree) {
30  result += GetTreeResponseWeighted(values, itree);
31  }
32  return result;
33 }
34 
35 template<typename Node_t>
36 float
37 ForestWeighted<Node_t>::GetWeightedResponse(
38  const std::vector<float*>& pointers) const
39 {
40  float result = 0.;
41  for (unsigned int itree = 0; itree != GetNTrees(); ++itree) {
42  result += GetTreeResponseWeighted(pointers, itree);
43  }
44  return result;
45 }
46 
47 template<typename Node_t>
48 void
49 ForestWeighted<Node_t>::newTree(const std::vector<Node_t>& nodes, float weight)
50 {
51  newTree(nodes);
52  m_weights.push_back(weight);
53  m_sumWeights += weight;
54 }
55 
56 inline float
57 ForestTMVA::GetResponse(const std::vector<float>& values) const
58 {
59  return GetRawResponse(values) + GetOffset();
60 }
61 
62 inline float
63 ForestTMVA::GetResponse(const std::vector<float*>& pointers) const
64 {
65  return GetRawResponse(pointers) + GetOffset();
66 }
67 
68 inline float
69 ForestTMVA::GetClassification(const std::vector<float>& values) const
70 {
71  float result = GetWeightedResponse(values);
72  return result / GetSumWeights();
73 }
74 
75 inline float
76 ForestTMVA::GetClassification(const std::vector<float*>& pointers) const
77 {
78  float result = GetWeightedResponse(pointers);
79  return result / GetSumWeights();
80 }
81 }