LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar_content::AdaBoostDecisionTree Class Reference

AdaBoostDecisionTree class. More...

#include "LArAdaBoostDecisionTree.h"

Inheritance diagram for lar_content::AdaBoostDecisionTree:
lar_content::MvaInterface

Classes

class  Node
 Node class used for representing a decision tree. More...
 
class  StrongClassifier
 StrongClassifier class used in application of adaptive boost decision tree. More...
 
class  WeakClassifier
 WeakClassifier class containing a decision tree and a weight. More...
 

Public Member Functions

 AdaBoostDecisionTree ()
 Constructor. More...
 
 AdaBoostDecisionTree (const AdaBoostDecisionTree &rhs)
 Copy constructor. More...
 
AdaBoostDecisionTreeoperator= (const AdaBoostDecisionTree &rhs)
 Assignment operator. More...
 
 ~AdaBoostDecisionTree ()
 Destructor. More...
 
pandora::StatusCode Initialize (const std::string &parameterLocation, const std::string &bdtName)
 Initialize the bdt model. More...
 
bool Classify (const LArMvaHelper::MvaFeatureVector &features) const
 Classify the set of input features based on the trained model. More...
 
double CalculateClassificationScore (const LArMvaHelper::MvaFeatureVector &features) const
 Calculate the classification score for a set of input features, based on the trained model. More...
 
double CalculateProbability (const LArMvaHelper::MvaFeatureVector &features) const
 Calculate the classification probability for a set of input features, based on the trained model. More...
 

Private Types

typedef std::map< int, const Node * > IdToNodeMap
 
typedef std::vector< const WeakClassifier * > WeakClassifiers
 

Private Member Functions

double CalculateScore (const LArMvaHelper::MvaFeatureVector &features) const
 Calculate score for input features using strong classifier. More...
 

Private Attributes

StrongClassifierm_pStrongClassifier
 Strong adaptive boost tree classifier. More...
 

Detailed Description

AdaBoostDecisionTree class.

Definition at line 27 of file LArAdaBoostDecisionTree.h.

Member Typedef Documentation

typedef std::map<int, const Node *> lar_content::AdaBoostDecisionTree::IdToNodeMap
private

Definition at line 191 of file LArAdaBoostDecisionTree.h.

Definition at line 264 of file LArAdaBoostDecisionTree.h.

Constructor & Destructor Documentation

lar_content::AdaBoostDecisionTree::AdaBoostDecisionTree ( )

Constructor.

Definition at line 18 of file LArAdaBoostDecisionTree.cc.

18  :
19  m_pStrongClassifier(nullptr)
20 {
21 }
StrongClassifier * m_pStrongClassifier
Strong adaptive boost tree classifier.
lar_content::AdaBoostDecisionTree::AdaBoostDecisionTree ( const AdaBoostDecisionTree rhs)

Copy constructor.

Parameters
rhsthe AdaBoostDecisionTree to copy

Definition at line 25 of file LArAdaBoostDecisionTree.cc.

References m_pStrongClassifier.

26 {
27  m_pStrongClassifier = new StrongClassifier(*(rhs.m_pStrongClassifier));
28 }
StrongClassifier * m_pStrongClassifier
Strong adaptive boost tree classifier.
lar_content::AdaBoostDecisionTree::~AdaBoostDecisionTree ( )

Destructor.

Definition at line 42 of file LArAdaBoostDecisionTree.cc.

References m_pStrongClassifier.

43 {
44  delete m_pStrongClassifier;
45 }
StrongClassifier * m_pStrongClassifier
Strong adaptive boost tree classifier.

Member Function Documentation

double lar_content::AdaBoostDecisionTree::CalculateClassificationScore ( const LArMvaHelper::MvaFeatureVector features) const
virtual

Calculate the classification score for a set of input features, based on the trained model.

Parameters
featuresthe input features
Returns
the classification score

Implements lar_content::MvaInterface.

Definition at line 127 of file LArAdaBoostDecisionTree.cc.

References CalculateScore().

128 {
129  return this->CalculateScore(features);
130 }
double CalculateScore(const LArMvaHelper::MvaFeatureVector &features) const
Calculate score for input features using strong classifier.
double lar_content::AdaBoostDecisionTree::CalculateProbability ( const LArMvaHelper::MvaFeatureVector features) const
virtual

Calculate the classification probability for a set of input features, based on the trained model.

Parameters
featuresthe input features
Returns
the classification probability

Implements lar_content::MvaInterface.

Definition at line 134 of file LArAdaBoostDecisionTree.cc.

References CalculateScore().

135 {
136  // ATTN: BDT score, once normalised by total weight, is confined to the range -1 to +1. This linear mapping places the score in the
137  // range 0 to 1 so that it may be interpreted as a probability.
138  return (this->CalculateScore(features) + 1.) * 0.5;
139 }
double CalculateScore(const LArMvaHelper::MvaFeatureVector &features) const
Calculate score for input features using strong classifier.
double lar_content::AdaBoostDecisionTree::CalculateScore ( const LArMvaHelper::MvaFeatureVector features) const
private

Calculate score for input features using strong classifier.

Parameters
featuresthe input features
Returns
score

Definition at line 143 of file LArAdaBoostDecisionTree.cc.

References m_pStrongClassifier, lar_content::AdaBoostDecisionTree::Node::Node(), and lar_content::AdaBoostDecisionTree::StrongClassifier::Predict().

Referenced by CalculateClassificationScore(), CalculateProbability(), and Classify().

144 {
145  if (!m_pStrongClassifier)
146  {
147  std::cout << "AdaBoostDecisionTree: Attempting to use an uninitialized bdt" << std::endl;
148  throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
149  }
150 
151  try
152  {
153  // TODO: Add consistency check for number of features, bearing in mind not all features in a bdt may be used
154  return m_pStrongClassifier->Predict(features);
155  }
156  catch (StatusCodeException &statusCodeException)
157  {
158  if (STATUS_CODE_NOT_FOUND == statusCodeException.GetStatusCode())
159  {
160  std::cout << "AdaBoostDecisionTree: Caught exception thrown when trying to cut on an unknown variable." << std::endl;
161  }
162  else if (STATUS_CODE_INVALID_PARAMETER == statusCodeException.GetStatusCode())
163  {
164  std::cout << "AdaBoostDecisionTree: Caught exception thrown when classifier weights sum to zero indicating defunct classifier."
165  << std::endl;
166  }
167  else if (STATUS_CODE_OUT_OF_RANGE == statusCodeException.GetStatusCode())
168  {
169  std::cout << "AdaBoostDecisionTree: Caught exception thrown when heirarchy in decision tree is incomplete." << std::endl;
170  }
171  else
172  {
173  std::cout << "AdaBoostDecisionTree: Unexpected exception thrown." << std::endl;
174  }
175 
176  throw statusCodeException;
177  }
178 }
double Predict(const LArMvaHelper::MvaFeatureVector &features) const
Predict signal or background based on trained data.
StrongClassifier * m_pStrongClassifier
Strong adaptive boost tree classifier.
bool lar_content::AdaBoostDecisionTree::Classify ( const LArMvaHelper::MvaFeatureVector features) const
virtual

Classify the set of input features based on the trained model.

Parameters
featuresthe input features
Returns
the classification

Implements lar_content::MvaInterface.

Definition at line 120 of file LArAdaBoostDecisionTree.cc.

References CalculateScore().

121 {
122  return ((this->CalculateScore(features) > 0.) ? true : false);
123 }
double CalculateScore(const LArMvaHelper::MvaFeatureVector &features) const
Calculate score for input features using strong classifier.
StatusCode lar_content::AdaBoostDecisionTree::Initialize ( const std::string &  parameterLocation,
const std::string &  bdtName 
)

Initialize the bdt model.

Parameters
parameterLocationthe location of the model
bdtNamethe name of the model
Returns
success

Definition at line 49 of file LArAdaBoostDecisionTree.cc.

References m_pStrongClassifier.

Referenced by lar_content::BdtBeamParticleIdTool::ReadSettings().

50 {
52  {
53  std::cout << "AdaBoostDecisionTree: AdaBoostDecisionTree was already initialized" << std::endl;
54  return STATUS_CODE_ALREADY_INITIALIZED;
55  }
56 
57  TiXmlDocument xmlDocument(bdtXmlFileName);
58 
59  if (!xmlDocument.LoadFile())
60  {
61  std::cout << "AdaBoostDecisionTree::Initialize - Invalid xml file." << std::endl;
62  return STATUS_CODE_INVALID_PARAMETER;
63  }
64 
65  const TiXmlHandle xmlDocumentHandle(&xmlDocument);
66  TiXmlNode *pContainerXmlNode(TiXmlHandle(xmlDocumentHandle).FirstChildElement().Element());
67 
68  while (pContainerXmlNode)
69  {
70  if (pContainerXmlNode->ValueStr() != "AdaBoostDecisionTree")
71  return STATUS_CODE_FAILURE;
72 
73  const TiXmlHandle currentHandle(pContainerXmlNode);
74 
75  std::string currentName;
76  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(currentHandle, "Name", currentName));
77 
78  if (currentName.empty() || (currentName.size() > 1000))
79  {
80  std::cout << "AdaBoostDecisionTree::Initialize - Implausible AdaBoostDecisionTree name extracted from xml." << std::endl;
81  return STATUS_CODE_INVALID_PARAMETER;
82  }
83 
84  if (currentName == bdtName)
85  break;
86 
87  pContainerXmlNode = pContainerXmlNode->NextSibling();
88  }
89 
90  if (!pContainerXmlNode)
91  {
92  std::cout << "AdaBoostDecisionTree: Could not find an AdaBoostDecisionTree of name " << bdtName << std::endl;
93  return STATUS_CODE_NOT_FOUND;
94  }
95 
96  const TiXmlHandle xmlHandle(pContainerXmlNode);
97 
98  try
99  {
100  m_pStrongClassifier = new StrongClassifier(&xmlHandle);
101  }
102  catch (StatusCodeException &statusCodeException)
103  {
104  delete m_pStrongClassifier;
105 
106  if (STATUS_CODE_INVALID_PARAMETER == statusCodeException.GetStatusCode())
107  std::cout << "AdaBoostDecisionTree: Initialization failure, unknown component in xml file." << std::endl;
108 
109  if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
110  std::cout << "AdaBoostDecisionTree: Node definition does not contain expected leaf or branch variables." << std::endl;
111 
112  return statusCodeException.GetStatusCode();
113  }
114 
115  return STATUS_CODE_SUCCESS;
116 }
StrongClassifier * m_pStrongClassifier
Strong adaptive boost tree classifier.
AdaBoostDecisionTree & lar_content::AdaBoostDecisionTree::operator= ( const AdaBoostDecisionTree rhs)

Assignment operator.

Parameters
rhsthe AdaBoostDecisionTree to assign

Definition at line 32 of file LArAdaBoostDecisionTree.cc.

References m_pStrongClassifier.

33 {
34  if (this != &rhs)
35  m_pStrongClassifier = new StrongClassifier(*(rhs.m_pStrongClassifier));
36 
37  return *this;
38 }
StrongClassifier * m_pStrongClassifier
Strong adaptive boost tree classifier.

Member Data Documentation

StrongClassifier* lar_content::AdaBoostDecisionTree::m_pStrongClassifier
private

Strong adaptive boost tree classifier.

Definition at line 325 of file LArAdaBoostDecisionTree.h.

Referenced by AdaBoostDecisionTree(), CalculateScore(), Initialize(), operator=(), and ~AdaBoostDecisionTree().


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