| 37 | } |
| 38 | |
| 39 | void GBDT::PredictRawByMap(const std::unordered_map<int, double>& features, double* output, const PredictionEarlyStopInstance* early_stop) const { |
| 40 | int early_stop_round_counter = 0; |
| 41 | // set zero |
| 42 | std::memset(output, 0, sizeof(double) * num_tree_per_iteration_); |
| 43 | for (int i = 0; i < num_iteration_for_pred_; ++i) { |
| 44 | // predict all the trees for one iteration |
| 45 | for (int k = 0; k < num_tree_per_iteration_; ++k) { |
| 46 | output[k] += models_[i * num_tree_per_iteration_ + k]->PredictByMap(features); |
| 47 | } |
| 48 | // check early stopping |
| 49 | ++early_stop_round_counter; |
| 50 | if (early_stop->round_period == early_stop_round_counter) { |
| 51 | if (early_stop->callback_function(output, num_tree_per_iteration_)) { |
| 52 | return; |
| 53 | } |
| 54 | early_stop_round_counter = 0; |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | void GBDT::Predict(const double* features, double* output, const PredictionEarlyStopInstance* early_stop) const { |
| 60 | PredictRaw(features, output, early_stop); |