|
ATLAS Offline Software
|
Go to the documentation of this file. 1 #ifndef CONIFER_CPP_H__
2 #define CONIFER_CPP_H__
3 #include "nlohmann/json.hpp"
20 template <
int B> constexpr
int pow(
int x) {
21 return x == 0 ? 1 : B * pow<B>(
x - 1);
24 constexpr
int pow2(
int x) {
return pow<2>(
x); }
26 template <
class T,
class Op> T
reduce(std::vector<T>
x, Op op) {
33 return op(
x.at(0),
x.at(1));
35 std::vector<T> left(
x.begin(),
x.begin() + leftN);
36 std::vector<T> right(
x.begin() + leftN,
x.end());
37 return op(reduce<T, Op>(left, op), reduce<T, Op>(right, op));
41 template <
class T>
class OpAdd {
73 [](
double t) -> T { return (T)t; });
75 [](
double v) -> U { return (U)v; });
84 j.at(
"value").get_to(o.
m_value);
89 template <
class T,
class U,
bool useAddTree = false>
class BDT {
98 std::vector<std::vector<DecisionTree<T, U>>>
m_trees;
113 [](
double ip) -> U { return (U)ip; });
123 assert(
"Size of feature vector mismatches expected m_n_features" &&
126 std::vector<std::vector<U>> values_trees;
132 std::back_inserter(values_trees.at(
i)),
133 [&
i, &
x](
auto tree_v) { return tree_v.at(i).decision_function(x); });
136 values.at(
i) += reduce<U, OpAdd<U>>(values_trees.at(
i),
m_add);
153 j.at(
"trees").get_to(o.
m_trees);
std::vector< T > m_threshold_
friend void from_json(const nlohmann::json &j, BDT &o)
std::vector< double > m_threshold
std::vector< int > m_feature
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
U decision_function(const std::vector< T > &x) const
std::vector< U > m_init_predict_
std::vector< double > m_value
constexpr int floorlog2(int x)
constexpr int pow2(int x)
std::vector< U > decision_function(std::vector< T > x) const
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
std::vector< U > m_value_
T reduce(std::vector< T > x, Op op)
std::vector< int > m_children_right
friend void from_json(const nlohmann::json &j, DecisionTree &o)
std::vector< int > m_children_left
std::vector< std::vector< DecisionTree< T, U > > > m_trees
std::vector< double > m_init_predict