| 237 | } |
| 238 | |
| 239 | Tree* SerialTreeLearner::FitByExistingTree(const Tree* old_tree, const score_t* gradients, const score_t *hessians) const { |
| 240 | auto tree = std::unique_ptr<Tree>(new Tree(*old_tree)); |
| 241 | CHECK(data_partition_->num_leaves() >= tree->num_leaves()); |
| 242 | OMP_INIT_EX(); |
| 243 | #pragma omp parallel for schedule(static) |
| 244 | for (int i = 0; i < tree->num_leaves(); ++i) { |
| 245 | OMP_LOOP_EX_BEGIN(); |
| 246 | data_size_t cnt_leaf_data = 0; |
| 247 | auto tmp_idx = data_partition_->GetIndexOnLeaf(i, &cnt_leaf_data); |
| 248 | double sum_grad = 0.0f; |
| 249 | double sum_hess = kEpsilon; |
| 250 | for (data_size_t j = 0; j < cnt_leaf_data; ++j) { |
| 251 | auto idx = tmp_idx[j]; |
| 252 | sum_grad += gradients[idx]; |
| 253 | sum_hess += hessians[idx]; |
| 254 | } |
| 255 | double output = FeatureHistogram::CalculateSplittedLeafOutput(sum_grad, sum_hess, |
| 256 | config_->lambda_l1, config_->lambda_l2, config_->max_delta_step); |
| 257 | auto old_leaf_output = tree->LeafOutput(i); |
| 258 | auto new_leaf_output = output * tree->shrinkage(); |
| 259 | tree->SetLeafOutput(i, config_->refit_decay_rate * old_leaf_output + (1.0 - config_->refit_decay_rate) * new_leaf_output); |
| 260 | OMP_LOOP_EX_END(); |
| 261 | } |
| 262 | OMP_THROW_EX(); |
| 263 | return tree.release(); |
| 264 | } |
| 265 | |
| 266 | Tree* SerialTreeLearner::FitByExistingTree(const Tree* old_tree, const std::vector<int>& leaf_pred, const score_t* gradients, const score_t *hessians) { |
| 267 | data_partition_->ResetByLeafPred(leaf_pred, old_tree->num_leaves()); |
no test coverage detected