CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
conifer::DecisionTree< T, U > Class Template Reference

#include <conifer.h>

Public Member Functions

decision_function (std::vector< T > x) const
 
void init_ ()
 
 NLOHMANN_DEFINE_TYPE_INTRUSIVE (DecisionTree, feature, children_left, children_right, threshold, value)
 

Private Attributes

std::vector< int > children_left
 
std::vector< int > children_right
 
std::vector< int > feature
 
std::vector< double > threshold
 
std::vector< Tthreshold_
 
std::vector< double > value
 
std::vector< U > value_
 

Detailed Description

template<class T, class U>
class conifer::DecisionTree< T, U >

Definition at line 53 of file conifer.h.

Member Function Documentation

◆ decision_function()

template<class T , class U >
U conifer::DecisionTree< T, U >::decision_function ( std::vector< T x) const
inline

Definition at line 64 of file conifer.h.

References conifer::DecisionTree< T, U >::children_left, conifer::DecisionTree< T, U >::children_right, conifer::DecisionTree< T, U >::feature, mps_fire::i, conifer::DecisionTree< T, U >::threshold_, conifer::DecisionTree< T, U >::value_, and x.

64  {
65  /* Do the prediction */
66  int i = 0;
67  while (feature[i] != -2) { // continue until reaching leaf
68  bool comparison = x[feature[i]] <= threshold_[i];
69  i = comparison ? children_left[i] : children_right[i];
70  }
71  return value_[i];
72  }
std::vector< int > feature
Definition: conifer.h:55
std::vector< T > threshold_
Definition: conifer.h:58
std::vector< int > children_right
Definition: conifer.h:57
std::vector< U > value_
Definition: conifer.h:59
std::vector< int > children_left
Definition: conifer.h:56

◆ init_()

template<class T , class U >
void conifer::DecisionTree< T, U >::init_ ( void  )
inline

Definition at line 74 of file conifer.h.

References submitPVValidationJobs::t, conifer::DecisionTree< T, U >::threshold, conifer::DecisionTree< T, U >::threshold_, HcalDetIdTransform::transform(), mitigatedMETSequence_cff::U, findQualityFiles::v, and conifer::DecisionTree< T, U >::value_.

74  {
75  /* Since T, U types may not be readable from the JSON, read them to double and the cast them here */
77  threshold.begin(), threshold.end(), std::back_inserter(threshold_), [](double t) -> T { return (T)t; });
78  std::transform(value.begin(), value.end(), std::back_inserter(value_), [](double v) -> U { return (U)v; });
79  }
std::vector< T > threshold_
Definition: conifer.h:58
Definition: value.py:1
std::vector< double > threshold
Definition: conifer.h:60
std::vector< U > value_
Definition: conifer.h:59
long double T
unsigned transform(const HcalDetId &id, unsigned transformCode)

◆ NLOHMANN_DEFINE_TYPE_INTRUSIVE()

template<class T , class U >
conifer::DecisionTree< T, U >::NLOHMANN_DEFINE_TYPE_INTRUSIVE ( DecisionTree< T, U >  ,
feature  ,
children_left  ,
children_right  ,
threshold  ,
value   
)

Member Data Documentation

◆ children_left

template<class T , class U >
std::vector<int> conifer::DecisionTree< T, U >::children_left
private

Definition at line 56 of file conifer.h.

Referenced by conifer::DecisionTree< T, U >::decision_function().

◆ children_right

template<class T , class U >
std::vector<int> conifer::DecisionTree< T, U >::children_right
private

Definition at line 57 of file conifer.h.

Referenced by conifer::DecisionTree< T, U >::decision_function().

◆ feature

template<class T , class U >
std::vector<int> conifer::DecisionTree< T, U >::feature
private

Definition at line 55 of file conifer.h.

Referenced by conifer::DecisionTree< T, U >::decision_function().

◆ threshold

template<class T , class U >
std::vector<double> conifer::DecisionTree< T, U >::threshold
private

◆ threshold_

template<class T , class U >
std::vector<T> conifer::DecisionTree< T, U >::threshold_
private

◆ value

template<class T , class U >
std::vector<double> conifer::DecisionTree< T, U >::value
private

◆ value_

template<class T , class U >
std::vector<U> conifer::DecisionTree< T, U >::value_
private