ATLAS Offline Software
BDT.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 namespace MVAUtils {
5 
6 inline float
7 BDT::GetResponse() const
8 {
9  return (!m_pointers.empty() ? GetResponse(m_pointers) : -9999.);
10 }
11 
12 inline float
13 BDT::GetClassification() const
14 {
15  return (!m_pointers.empty() ? GetClassification(m_pointers) : -9999.);
16 }
17 
18 inline std::vector<float>
19 BDT::GetMultiResponse(unsigned int numClasses) const
20 {
21  return (!m_pointers.empty() ? GetMultiResponse(m_pointers, numClasses)
22  : std::vector<float>());
23 }
24 
25 inline std::vector<float>
26 BDT::GetValues() const
27 {
28  std::vector<float> result;
29  for (float* ptr : m_pointers) {
30  assert(ptr);
31  result.push_back(*ptr);
32  }
33  return result;
34 }
35 
36 inline const std::vector<float*>&
37 BDT::GetPointers() const
38 {
39  return m_pointers;
40 }
41 inline void
42 BDT::SetPointers(const std::vector<float*>& pointers)
43 {
44  m_pointers = pointers;
45 }
46 inline unsigned int
47 BDT::GetNTrees() const
48 {
49  return m_forest->GetNTrees();
50 }
51 inline int
52 BDT::GetNVars() const
53 {
54  return m_forest->GetNVars();
55 }
56 inline float
57 BDT::GetOffset() const
58 {
59  return m_forest->GetOffset();
60 }
61 
62 /** Return offset + the sum of the response of each tree **/
63 inline float
64 BDT::GetResponse(const std::vector<float>& values) const
65 {
66  return m_forest->GetResponse(values);
67 }
68 
69 /** Return offset + the sum of the response of each tree **/
70 inline float
71 BDT::GetResponse(const std::vector<float*>& pointers) const
72 {
73  return m_forest->GetResponse(pointers);
74 }
75 
76 inline float
77 BDT::GetClassification(const std::vector<float>& values) const
78 {
79  return m_forest->GetClassification(values);
80 }
81 
82 inline float
83 BDT::GetClassification(const std::vector<float*>& pointers) const
84 {
85  return m_forest->GetClassification(pointers);
86 }
87 
88 inline float
89 BDT::GetGradBoostMVA(const std::vector<float>& values) const
90 {
91  const float sum = m_forest->GetRawResponse(values); // ignores the offset
92  return 2. / (1 + std::exp(-2 * sum)) -
93  1; // output shaping for gradient boosted decision tree (-1,1)
94 }
95 
96 inline float
97 BDT::GetGradBoostMVA(const std::vector<float*>& pointers) const
98 {
99  const float sum = m_forest->GetRawResponse(pointers); // ignores the offset
100  // output shaping for gradient boosted decision tree (-1,1)
101  return 2. / (1 + std::exp(-2 * sum)) - 1;
102 }
103 
104 inline std::vector<float>
105 BDT::GetMultiResponse(const std::vector<float>& values,
106  unsigned int numClasses) const
107 {
108  return m_forest->GetMultiResponse(values, numClasses);
109 }
110 
111 inline std::vector<float>
112 BDT::GetMultiResponse(const std::vector<float*>& pointers,
113  unsigned int numClasses) const
114 {
115  return m_forest->GetMultiResponse(pointers, numClasses);
116 }
117 
118 inline float
119 BDT::GetTreeResponse(const std::vector<float>& values,
120  MVAUtils::index_t index) const
121 {
122  return m_forest->GetTreeResponse(values, index);
123 }
124 
125 inline float
126 BDT::GetTreeResponse(const std::vector<float*>& pointers,
127  MVAUtils::index_t index) const
128 {
129  return m_forest->GetTreeResponse(pointers, index);
130 }
131 
132 }