! * \brief drop trees based on drop_rate */
| 95 | * \brief drop trees based on drop_rate |
| 96 | */ |
| 97 | void DroppingTrees() { |
| 98 | drop_index_.clear(); |
| 99 | bool is_skip = random_for_drop_.NextFloat() < config_->skip_drop; |
| 100 | // select dropping tree indices based on drop_rate and tree weights |
| 101 | if (!is_skip) { |
| 102 | double drop_rate = config_->drop_rate; |
| 103 | if (!config_->uniform_drop) { |
| 104 | double inv_average_weight = static_cast<double>(tree_weight_.size()) / sum_weight_; |
| 105 | if (config_->max_drop > 0) { |
| 106 | drop_rate = std::min(drop_rate, config_->max_drop * inv_average_weight / sum_weight_); |
| 107 | } |
| 108 | for (int i = 0; i < iter_; ++i) { |
| 109 | if (random_for_drop_.NextFloat() < drop_rate * tree_weight_[i] * inv_average_weight) { |
| 110 | drop_index_.push_back(num_init_iteration_ + i); |
| 111 | if (drop_index_.size() >= static_cast<size_t>(config_->max_drop)) { |
| 112 | break; |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | } else { |
| 117 | if (config_->max_drop > 0) { |
| 118 | drop_rate = std::min(drop_rate, config_->max_drop / static_cast<double>(iter_)); |
| 119 | } |
| 120 | for (int i = 0; i < iter_; ++i) { |
| 121 | if (random_for_drop_.NextFloat() < drop_rate) { |
| 122 | drop_index_.push_back(num_init_iteration_ + i); |
| 123 | if (drop_index_.size() >= static_cast<size_t>(config_->max_drop)) { |
| 124 | break; |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | // drop trees |
| 131 | for (auto i : drop_index_) { |
| 132 | for (int cur_tree_id = 0; cur_tree_id < num_tree_per_iteration_; ++cur_tree_id) { |
| 133 | auto curr_tree = i * num_tree_per_iteration_ + cur_tree_id; |
| 134 | models_[curr_tree]->Shrinkage(-1.0); |
| 135 | train_score_updater_->AddScore(models_[curr_tree].get(), cur_tree_id); |
| 136 | } |
| 137 | } |
| 138 | if (!config_->xgboost_dart_mode) { |
| 139 | shrinkage_rate_ = config_->learning_rate / (1.0f + static_cast<double>(drop_index_.size())); |
| 140 | } else { |
| 141 | if (drop_index_.empty()) { |
| 142 | shrinkage_rate_ = config_->learning_rate; |
| 143 | } else { |
| 144 | shrinkage_rate_ = config_->learning_rate / (config_->learning_rate + static_cast<double>(drop_index_.size())); |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | /*! |
| 149 | * \brief normalize dropped trees |
| 150 | * NOTE: num_drop_tree(k), learning_rate(lr), shrinkage_rate_ = lr / (k + 1) |