LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 288 of file LArAdaBoostDecisionTree.cc.

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

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

Destructor.

Definition at line 320 of file LArAdaBoostDecisionTree.cc.

References m_idToNodeMap.

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

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 335 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().

336 {
337  const Node *pActiveNode(nullptr);
338 
339  if (m_idToNodeMap.find(nodeId) != m_idToNodeMap.end())
340  {
341  pActiveNode = m_idToNodeMap.at(nodeId);
342  }
343  else
344  {
345  throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
346  }
347 
348  if (pActiveNode->IsLeaf())
349  return pActiveNode->GetOutcome();
350 
351  if (static_cast<int>(features.size()) <= pActiveNode->GetVariableId())
352  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
353 
354  if (features.at(pActiveNode->GetVariableId()).Get() <= pActiveNode->GetThreshold())
355  {
356  return this->EvaluateNode(pActiveNode->GetLeftChildNodeId(), features);
357  }
358  else
359  {
360  return this->EvaluateNode(pActiveNode->GetRightChildNodeId(), features);
361  }
362 }
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 301 of file LArAdaBoostDecisionTree.cc.

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

302 {
303  if (this != &rhs)
304  {
305  for (const auto &mapEntry : rhs.m_idToNodeMap)
306  {
307  const Node *pNode = new Node(*(mapEntry.second));
308  m_idToNodeMap.insert(IdToNodeMap::value_type(pNode->GetNodeId(), pNode));
309  }
310 
311  m_weight = rhs.m_weight;
312  m_treeId = rhs.m_treeId;
313  }
314 
315  return *this;
316 }
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 328 of file LArAdaBoostDecisionTree.cc.

References EvaluateNode().

329 {
330  return this->EvaluateNode(0, features);
331 }
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: