MCPcopy Create free account
hub / github.com/dmlc/xgboost / GrowTree

Function GrowTree

tests/cpp/tree/test_tree_model.cc:108–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108void GrowTree(RegTree* p_tree) {
109 SimpleLCG lcg;
110 size_t n_expands = 10;
111 constexpr size_t kCols = 256;
112 SimpleRealUniformDistribution<double> coin(0.0, 1.0);
113 SimpleRealUniformDistribution<double> feat(0.0, kCols);
114 SimpleRealUniformDistribution<double> split_cat(0.0, 128.0);
115 SimpleRealUniformDistribution<double> split_value(0.0, kCols);
116
117 std::stack<bst_node_t> stack;
118 stack.push(RegTree::kRoot);
119 auto& tree = *p_tree;
120
121 for (size_t i = 0; i < n_expands; ++i) {
122 auto is_cat = coin(&lcg) <= 0.5;
123 bst_node_t node = stack.top();
124 stack.pop();
125
126 bst_feature_t f = feat(&lcg);
127 if (is_cat) {
128 bst_cat_t cat = common::AsCat(split_cat(&lcg));
129 std::vector<uint32_t> split_cats(
130 LBitField32::ComputeStorageSize(cat + 1));
131 LBitField32 bitset{split_cats};
132 bitset.Set(cat);
133 tree.ExpandCategorical(node, f, split_cats, true, 1.0, 2.0, 3.0, 11.0, 2.0,
134 /*left_sum=*/3.0, /*right_sum=*/4.0);
135 } else {
136 auto split = split_value(&lcg);
137 tree.ExpandNode(node, f, split, true, 1.0, 2.0, 3.0, 11.0, 2.0,
138 /*left_sum=*/3.0, /*right_sum=*/4.0);
139 }
140
141 stack.push(tree[node].LeftChild());
142 stack.push(tree[node].RightChild());
143 }
144}
145
146void CheckReload(RegTree const &tree) {
147 Json out{Object()};

Callers 1

TESTFunction · 0.85

Calls 6

AsCatFunction · 0.85
ExpandCategoricalMethod · 0.80
ExpandNodeMethod · 0.80
SetMethod · 0.45
LeftChildMethod · 0.45
RightChildMethod · 0.45

Tested by

no test coverage detected