7#include "nlohmann/json.hpp"
27template <
int B>
constexpr int pow(
int x) {
28 return x == 0 ? 1 : B *
pow<B>(
x - 1);
33template <
class T,
class Op> T
reduce(std::vector<T>
x, Op op) {
40 return op(
x.at(0),
x.at(1));
42 std::vector<T> left(
x.begin(),
x.begin() + leftN);
43 std::vector<T> right(
x.begin() + leftN,
x.end());
80 [](
double t) -> T { return (T)t; });
82 [](
double v) -> U { return (U)v; });
91 j.at(
"value").get_to(o.
m_value);
96template <
class T,
class U,
bool useAddTree = false>
class BDT {
105 std::vector<std::vector<DecisionTree<T, U>>>
m_trees;
120 [](
double ip) -> U { return (U)ip; });
130 assert(
"Size of feature vector mismatches expected m_n_features" &&
132 std::vector<U> values;
133 std::vector<std::vector<U>> values_trees;
139 std::back_inserter(values_trees.at(i)),
140 [&i, &
x](
auto tree_v) { return tree_v.at(i).decision_function(x); });
146 std::accumulate(values_trees.at(i).begin(),
160 j.at(
"trees").get_to(o.
m_trees);
static const std::map< unsigned int, unsigned int > pow2
std::vector< double > m_init_predict
std::vector< U > decision_function(std::vector< T > x) const
std::vector< std::vector< DecisionTree< T, U > > > m_trees
std::vector< U > m_init_predict_
friend void from_json(const nlohmann::json &j, BDT &o)
std::vector< int > m_feature
std::vector< double > m_threshold
std::vector< int > m_children_right
std::vector< U > m_value_
std::vector< T > m_threshold_
friend void from_json(const nlohmann::json &j, DecisionTree &o)
std::vector< int > m_children_left
U decision_function(const std::vector< T > &x) const
std::vector< double > m_value
constexpr int floorlog2(int x)
T reduce(std::vector< T > x, Op op)