Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
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...
 
- Public Member Functions inherited from lar_content::MvaInterface
virtual ~MvaInterface ()=default
 Destructor. 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  : m_pStrongClassifier(nullptr)
19 {
20 }
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 24 of file LArAdaBoostDecisionTree.cc.

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

Destructor.

Definition at line 41 of file LArAdaBoostDecisionTree.cc.

42 {
43  delete m_pStrongClassifier;
44 }
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 126 of file LArAdaBoostDecisionTree.cc.

127 {
128  return this->CalculateScore(features);
129 }
const char features[]
Definition: feature_tests.c:2
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 133 of file LArAdaBoostDecisionTree.cc.

134 {
135  // ATTN: BDT score, once normalised by total weight, is confined to the range -1 to +1. This linear mapping places the score in the
136  // range 0 to 1 so that it may be interpreted as a probability.
137  return (this->CalculateScore(features) + 1.) * 0.5;
138 }
const char features[]
Definition: feature_tests.c:2
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 142 of file LArAdaBoostDecisionTree.cc.

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

120 {
121  return ((this->CalculateScore(features) > 0.) ? true : false);
122 }
const char features[]
Definition: feature_tests.c:2
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 48 of file LArAdaBoostDecisionTree.cc.

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

Assignment operator.

Parameters
rhsthe AdaBoostDecisionTree to assign

Definition at line 31 of file LArAdaBoostDecisionTree.cc.

32 {
33  if (this != &rhs)
34  m_pStrongClassifier = new StrongClassifier(*(rhs.m_pStrongClassifier));
35 
36  return *this;
37 }
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.


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