MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / RefitTree

Method RefitTree

src/boosting/gbdt.cpp:308–331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

306}
307
308void GBDT::RefitTree(const std::vector<std::vector<int>>& tree_leaf_prediction) {
309 CHECK(tree_leaf_prediction.size() > 0);
310 CHECK(static_cast<size_t>(num_data_) == tree_leaf_prediction.size());
311 CHECK(static_cast<size_t>(models_.size()) == tree_leaf_prediction[0].size());
312 int num_iterations = static_cast<int>(models_.size() / num_tree_per_iteration_);
313 std::vector<int> leaf_pred(num_data_);
314 for (int iter = 0; iter < num_iterations; ++iter) {
315 Boosting();
316 for (int tree_id = 0; tree_id < num_tree_per_iteration_; ++tree_id) {
317 int model_index = iter * num_tree_per_iteration_ + tree_id;
318#pragma omp parallel for schedule(static)
319 for (int i = 0; i < num_data_; ++i) {
320 leaf_pred[i] = tree_leaf_prediction[i][model_index];
321 CHECK(leaf_pred[i] < models_[model_index]->num_leaves());
322 }
323 size_t offset = static_cast<size_t>(tree_id) * num_data_;
324 auto grad = gradients_.data() + offset;
325 auto hess = hessians_.data() + offset;
326 auto new_tree = tree_learner_->FitByExistingTree(models_[model_index].get(), leaf_pred, grad, hess);
327 train_score_updater_->AddScore(tree_learner_.get(), new_tree, tree_id);
328 models_[model_index].reset(new_tree);
329 }
330 }
331}
332
333/* If the custom "average" is implemented it will be used inplace of the label average (if enabled)
334*

Callers 2

RefitMethod · 0.45
PredictMethod · 0.45

Calls 8

dataMethod · 0.80
resetMethod · 0.80
BoostingFunction · 0.50
sizeMethod · 0.45
num_leavesMethod · 0.45
FitByExistingTreeMethod · 0.45
getMethod · 0.45
AddScoreMethod · 0.45

Tested by

no test coverage detected