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

WeakClassifier class containing a decision tree and a weight. More...

Public Member Functions

 WeakClassifier (const pandora::TiXmlHandle *const pXmlHandle)
 Constructor using xml handle to set member variables. More...
 
 WeakClassifier (const WeakClassifier &rhs)
 Copy constructor. More...
 
WeakClassifieroperator= (const WeakClassifier &rhs)
 Assignment operator. More...
 
 ~WeakClassifier ()
 Destructor. More...
 
bool Predict (const LArMvaHelper::MvaFeatureVector &features) const
 Predict signal or background based on trained data. More...
 
bool EvaluateNode (const int nodeId, const LArMvaHelper::MvaFeatureVector &features) const
 Evalute node and return outcome. More...
 
double GetWeight () const
 Get boost weight for weak classifier. More...
 
int GetTreeId () const
 Get tree id for weak classifier. More...
 

Private Attributes

IdToNodeMap m_idToNodeMap
 Decision tree nodes. More...
 
double m_weight
 Boost weight. More...
 
int m_treeId
 Decision tree id. More...
 

Detailed Description

WeakClassifier class containing a decision tree and a weight.

Definition at line 196 of file LArAdaBoostDecisionTree.h.

Constructor & Destructor Documentation

lar_content::AdaBoostDecisionTree::WeakClassifier::WeakClassifier ( const pandora::TiXmlHandle *const  pXmlHandle)
lar_content::AdaBoostDecisionTree::WeakClassifier::WeakClassifier ( const WeakClassifier rhs)

Copy constructor.

Parameters
rhsthe weak classifier to copy

Definition at line 290 of file LArAdaBoostDecisionTree.cc.

References lar_content::AdaBoostDecisionTree::Node::GetNodeId(), and m_idToNodeMap.

290  :
291  m_weight(rhs.m_weight),
292  m_treeId(rhs.m_treeId)
293 {
294  for (const auto &mapEntry : rhs.m_idToNodeMap)
295  {
296  const Node *pNode = new Node(*(mapEntry.second));
297  m_idToNodeMap.insert(IdToNodeMap::value_type(pNode->GetNodeId(), pNode));
298  }
299 }
lar_content::AdaBoostDecisionTree::WeakClassifier::~WeakClassifier ( )

Destructor.

Definition at line 322 of file LArAdaBoostDecisionTree.cc.

References m_idToNodeMap.

323 {
324  for (const auto &mapEntry : m_idToNodeMap)
325  delete mapEntry.second;
326 }

Member Function Documentation

bool lar_content::AdaBoostDecisionTree::WeakClassifier::EvaluateNode ( const int  nodeId,
const LArMvaHelper::MvaFeatureVector features 
) const

Evalute node and return outcome.

Parameters
nodeIdcurrent node id
featuresthe input features
Returns
is signal or background node

Definition at line 337 of file LArAdaBoostDecisionTree.cc.

References Get, lar_content::AdaBoostDecisionTree::Node::GetLeftChildNodeId(), lar_content::AdaBoostDecisionTree::Node::GetOutcome(), lar_content::AdaBoostDecisionTree::Node::GetRightChildNodeId(), lar_content::AdaBoostDecisionTree::Node::GetThreshold(), lar_content::AdaBoostDecisionTree::Node::GetVariableId(), lar_content::AdaBoostDecisionTree::Node::IsLeaf(), m_idToNodeMap, and lar_content::AdaBoostDecisionTree::StrongClassifier::StrongClassifier().

Referenced by Predict().

338 {
339  const Node *pActiveNode(nullptr);
340 
341  if (m_idToNodeMap.find(nodeId) != m_idToNodeMap.end())
342  {
343  pActiveNode = m_idToNodeMap.at(nodeId);
344  }
345  else
346  {
347  throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
348  }
349 
350  if (pActiveNode->IsLeaf())
351  return pActiveNode->GetOutcome();
352 
353  if (static_cast<int>(features.size()) <= pActiveNode->GetVariableId())
354  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
355 
356  if (features.at(pActiveNode->GetVariableId()).Get() <= pActiveNode->GetThreshold())
357  {
358  return this->EvaluateNode(pActiveNode->GetLeftChildNodeId(), features);
359  }
360  else
361  {
362  return this->EvaluateNode(pActiveNode->GetRightChildNodeId(), features);
363  }
364 }
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
bool EvaluateNode(const int nodeId, const LArMvaHelper::MvaFeatureVector &features) const
Evalute node and return outcome.
int lar_content::AdaBoostDecisionTree::WeakClassifier::GetTreeId ( ) const
inline

Get tree id for weak classifier.

Returns
tree id

Definition at line 393 of file LArAdaBoostDecisionTree.h.

394 {
395  return m_treeId;
396 }
double lar_content::AdaBoostDecisionTree::WeakClassifier::GetWeight ( ) const
inline

Get boost weight for weak classifier.

Returns
weight for decision tree

Definition at line 386 of file LArAdaBoostDecisionTree.h.

387 {
388  return m_weight;
389 }
AdaBoostDecisionTree::WeakClassifier & lar_content::AdaBoostDecisionTree::WeakClassifier::operator= ( const WeakClassifier rhs)

Assignment operator.

Parameters
rhsthe weak classifier to assign

Definition at line 303 of file LArAdaBoostDecisionTree.cc.

References lar_content::AdaBoostDecisionTree::Node::GetNodeId(), m_idToNodeMap, m_treeId, and m_weight.

304 {
305  if (this != &rhs)
306  {
307  for (const auto &mapEntry : rhs.m_idToNodeMap)
308  {
309  const Node *pNode = new Node(*(mapEntry.second));
310  m_idToNodeMap.insert(IdToNodeMap::value_type(pNode->GetNodeId(), pNode));
311  }
312 
313  m_weight = rhs.m_weight;
314  m_treeId = rhs.m_treeId;
315  }
316 
317  return *this;
318 }
bool lar_content::AdaBoostDecisionTree::WeakClassifier::Predict ( const LArMvaHelper::MvaFeatureVector features) const

Predict signal or background based on trained data.

Parameters
featuresthe input features
Returns
is signal or background

Definition at line 330 of file LArAdaBoostDecisionTree.cc.

References EvaluateNode().

331 {
332  return this->EvaluateNode(0, features);
333 }
bool EvaluateNode(const int nodeId, const LArMvaHelper::MvaFeatureVector &features) const
Evalute node and return outcome.

Member Data Documentation

IdToNodeMap lar_content::AdaBoostDecisionTree::WeakClassifier::m_idToNodeMap
private

Decision tree nodes.

Definition at line 259 of file LArAdaBoostDecisionTree.h.

Referenced by EvaluateNode(), operator=(), WeakClassifier(), and ~WeakClassifier().

int lar_content::AdaBoostDecisionTree::WeakClassifier::m_treeId
private

Decision tree id.

Definition at line 261 of file LArAdaBoostDecisionTree.h.

Referenced by operator=().

double lar_content::AdaBoostDecisionTree::WeakClassifier::m_weight
private

Boost weight.

Definition at line 260 of file LArAdaBoostDecisionTree.h.

Referenced by operator=().


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