19 std::vector<int> *vars =
nullptr;
20 std::vector<float> *values =
nullptr;
22 std::vector<NodeLGBMSimple> nodes;
24 tree->SetBranchAddress(
"vars", &vars);
25 tree->SetBranchAddress(
"values", &values);
27 int numEntries =
tree->GetEntries();
28 for (
int entry = 0; entry < numEntries; ++entry)
31 tree->GetEntry(entry);
33 throw std::runtime_error(
34 "vars pointer is null in ForestLGBMSimple constructor");
37 throw std::runtime_error(
38 "values pointers is null in ForestLGBMSimple constructor");
40 if (vars->size() != values->size()) {
41 throw std::runtime_error(
"inconsistent size for vars and values in "
42 "ForestLGBMSimple constructor");
49 for (
size_t i = 0; i < vars->size(); ++i) {
50 nodes.emplace_back(vars->at(i), values->at(i), right[i]);
62 TTree *
tree =
new TTree(name.Data(),
"creator=lgbm;node_type=lgbm_simple");
64 std::vector<int> vars;
65 std::vector<float> values;
67 tree->Branch(
"vars", &vars);
68 tree->Branch(
"values", &values);
70 for (
size_t itree = 0; itree <
GetNTrees(); ++itree) {
74 vars.push_back(
node.GetVar());
75 values.push_back(
node.GetVal());
84 std::cout <<
"***BDT LGBMSimple: Printing entire forest***" << std::endl;
95 std::vector<int> *vars =
nullptr;
96 std::vector<float> *values =
nullptr;
97 std::vector<bool> *default_left =
nullptr;
99 std::vector<NodeLGBM> nodes;
101 tree->SetBranchAddress(
"vars", &vars);
102 tree->SetBranchAddress(
"values", &values);
103 tree->SetBranchAddress(
"default_left", &default_left);
104 int numEntries =
tree->GetEntries();
105 for (
int entry = 0; entry < numEntries; ++entry) {
107 tree->GetEntry(entry);
109 throw std::runtime_error(
110 "vars pointer is null in ForestLGBM constructor");
113 throw std::runtime_error(
114 "values pointers is null in ForestLGBM constructor");
117 throw std::runtime_error(
118 "default_left pointers is null in ForestLGBM constructor");
120 if (vars->size() != values->size()) {
121 throw std::runtime_error(
122 "inconsistent size for vars and values in ForestLGBM constructor");
124 if (default_left->size() != values->size()) {
125 throw std::runtime_error(
"inconsistent size for default_left and "
126 "values in ForestLGBM constructor");
133 for (
size_t i = 0; i < vars->size(); ++i) {
135 vars->at(i), values->at(i), right[i], default_left->at(i));
150 TTree *
tree =
new TTree(name.Data(),
"creator=lgbm;node_type=lgbm");
152 std::vector<int> vars;
153 std::vector<float> values;
154 std::vector<bool> default_left;
156 tree->Branch(
"vars", &vars);
157 tree->Branch(
"values", &values);
158 tree->Branch(
"default_left", &default_left);
160 for (
size_t itree = 0; itree <
GetNTrees(); ++itree) {
163 default_left.clear();
165 vars.push_back(
node.GetVar());
166 values.push_back(
node.GetVal());
167 default_left.push_back(
node.GetDefaultLeft());
176 std::cout <<
"***BDT LGBM: Printing entire forest***" << std::endl;
virtual TTree * WriteTree(TString name) const override
Return a TTree representing the BDT.
virtual void PrintForest() const override
ForestLGBMSimple()=default
virtual TTree * WriteTree(TString name) const override
Return a TTree representing the BDT.
virtual void PrintForest() const override
void newTree(const std::vector< NodeLGBMSimple > &nodes)
std::vector< NodeLGBMSimple > GetTree(unsigned int itree) const
virtual void PrintForest() const override
virtual unsigned int GetNTrees() const override final
Node for LGBM without nan implementation.
Node for LGBM with nan implementation.
std::vector< index_t > computeRight(const std::vector< int > &vars)
Compute the offsets between the nodes to their right children from a serialized representation of the...