10
10
11
11
namespace LightGBM {
12
12
13
- void GBDT::PredictRaw (const double * features, double * output, const PredictionEarlyStopInstance* early_stop) const {
14
- int early_stop_round_counter = 0 ;
15
- // set zero
16
- std::memset (output, 0 , sizeof (double ) * num_tree_per_iteration_);
17
- const int end_iteration_for_pred = start_iteration_for_pred_ + num_iteration_for_pred_;
18
- for (int i = start_iteration_for_pred_; i < end_iteration_for_pred; ++i) {
19
- // predict all the trees for one iteration
20
- for (int k = 0 ; k < num_tree_per_iteration_; ++k) {
21
- output[k] += models_[i * num_tree_per_iteration_ + k]->Predict (features);
13
+ void GBDT::PredictRaw (const double * features, double * output, const PredictionEarlyStopInstance* early_stop) const {
14
+ int early_stop_round_counter = 0 ;
15
+ // set zero
16
+ std::memset (output, 0 , sizeof (double ) * num_tree_per_iteration_);
17
+ const int end_iteration_for_pred = start_iteration_for_pred_ + num_iteration_for_pred_;
18
+ for (int i = start_iteration_for_pred_; i < end_iteration_for_pred; ++i) {
19
+ // predict all the trees for one iteration
20
+ for (int k = 0 ; k < num_tree_per_iteration_; ++k) {
21
+ output[k] += models_[i * num_tree_per_iteration_ + k]->Predict (features);
22
+ }
23
+ // check early stopping
24
+ ++early_stop_round_counter;
25
+ if (early_stop->round_period == early_stop_round_counter) {
26
+ if (early_stop->callback_function (output, num_tree_per_iteration_)) {
27
+ return ;
28
+ }
29
+ early_stop_round_counter = 0 ;
30
+ }
31
+ }
22
32
}
23
- // check early stopping
24
- ++early_stop_round_counter;
25
- if (early_stop->round_period == early_stop_round_counter) {
26
- if (early_stop->callback_function (output, num_tree_per_iteration_)) {
27
- return ;
28
- }
29
- early_stop_round_counter = 0 ;
30
- }
31
- }
32
- }
33
33
34
- void GBDT::PredictRawByMap (const std::unordered_map<int , double >& features, double * output, const PredictionEarlyStopInstance* early_stop) const {
35
- int early_stop_round_counter = 0 ;
36
- // set zero
37
- std::memset (output, 0 , sizeof (double ) * num_tree_per_iteration_);
38
- const int end_iteration_for_pred = start_iteration_for_pred_ + num_iteration_for_pred_;
39
- for (int i = start_iteration_for_pred_; i < end_iteration_for_pred; ++i) {
40
- // predict all the trees for one iteration
41
- for (int k = 0 ; k < num_tree_per_iteration_; ++k) {
42
- output[k] += models_[i * num_tree_per_iteration_ + k]->PredictByMap (features);
43
- }
44
- // check early stopping
45
- ++early_stop_round_counter;
46
- if (early_stop->round_period == early_stop_round_counter) {
47
- if (early_stop->callback_function (output, num_tree_per_iteration_)) {
48
- return ;
49
- }
50
- early_stop_round_counter = 0 ;
34
+ void GBDT::PredictRawByMap (const std::unordered_map<int , double >& features, double * output, const PredictionEarlyStopInstance* early_stop) const {
35
+ int early_stop_round_counter = 0 ;
36
+ // set zero
37
+ std::memset (output, 0 , sizeof (double ) * num_tree_per_iteration_);
38
+ const int end_iteration_for_pred = start_iteration_for_pred_ + num_iteration_for_pred_;
39
+ for (int i = start_iteration_for_pred_; i < end_iteration_for_pred; ++i) {
40
+ // predict all the trees for one iteration
41
+ for (int k = 0 ; k < num_tree_per_iteration_; ++k) {
42
+ output[k] += models_[i * num_tree_per_iteration_ + k]->PredictByMap (features);
43
+ }
44
+ // check early stopping
45
+ ++early_stop_round_counter;
46
+ if (early_stop->round_period == early_stop_round_counter) {
47
+ if (early_stop->callback_function (output, num_tree_per_iteration_)) {
48
+ return ;
49
+ }
50
+ early_stop_round_counter = 0 ;
51
+ }
52
+ }
51
53
}
52
- }
53
- }
54
54
55
- void GBDT::Predict (const double * features, double * output, const PredictionEarlyStopInstance* early_stop) const {
56
- PredictRaw (features, output, early_stop);
57
- if (average_output_) {
58
- for (int k = 0 ; k < num_tree_per_iteration_; ++k) {
59
- output[k] /= num_iteration_for_pred_;
55
+ void GBDT::Predict (const double * features, double * output, const PredictionEarlyStopInstance* early_stop) const {
56
+ PredictRaw (features, output, early_stop);
57
+ if (average_output_) {
58
+ for (int k = 0 ; k < num_tree_per_iteration_; ++k) {
59
+ output[k] /= num_iteration_for_pred_;
60
+ }
61
+ }
62
+ if (objective_function_ != nullptr ) {
63
+ objective_function_->ConvertOutput (output, output);
64
+ }
60
65
}
61
- }
62
- if (objective_function_ != nullptr ) {
63
- objective_function_->ConvertOutput (output, output);
64
- }
65
- }
66
66
67
- void GBDT::PredictByMap (const std::unordered_map<int , double >& features, double * output, const PredictionEarlyStopInstance* early_stop) const {
68
- PredictRawByMap (features, output, early_stop);
69
- if (average_output_) {
70
- for (int k = 0 ; k < num_tree_per_iteration_; ++k) {
71
- output[k] /= num_iteration_for_pred_;
67
+ void GBDT::PredictByMap (const std::unordered_map<int , double >& features, double * output, const PredictionEarlyStopInstance* early_stop) const {
68
+ PredictRawByMap (features, output, early_stop);
69
+ if (average_output_) {
70
+ for (int k = 0 ; k < num_tree_per_iteration_; ++k) {
71
+ output[k] /= num_iteration_for_pred_;
72
+ }
73
+ }
74
+ if (objective_function_ != nullptr ) {
75
+ objective_function_->ConvertOutput (output, output);
76
+ }
72
77
}
73
- }
74
- if (objective_function_ != nullptr ) {
75
- objective_function_->ConvertOutput (output, output);
76
- }
77
- }
78
78
79
- void GBDT::PredictLeafIndex (const double * features, double * output) const {
80
- int start_tree = start_iteration_for_pred_ * num_tree_per_iteration_;
81
- int num_trees = num_iteration_for_pred_ * num_tree_per_iteration_;
82
- const auto * models_ptr = models_.data () + start_tree;
83
- for (int i = 0 ; i < num_trees; ++i) {
84
- output[i] = models_ptr[i]->PredictLeafIndex (features);
85
- }
86
- }
79
+ void GBDT::PredictLeafIndex (const double * features, double * output) const {
80
+ int start_tree = start_iteration_for_pred_ * num_tree_per_iteration_;
81
+ int num_trees = num_iteration_for_pred_ * num_tree_per_iteration_;
82
+ const auto * models_ptr = models_.data () + start_tree;
83
+ for (int i = 0 ; i < num_trees; ++i) {
84
+ output[i] = models_ptr[i]->PredictLeafIndex (features);
85
+ }
86
+ }
87
87
88
- void GBDT::PredictLeafIndexByMap (const std::unordered_map<int , double >& features, double * output) const {
89
- int start_tree = start_iteration_for_pred_ * num_tree_per_iteration_;
90
- int num_trees = num_iteration_for_pred_ * num_tree_per_iteration_;
91
- const auto * models_ptr = models_.data () + start_tree;
92
- for (int i = 0 ; i < num_trees; ++i) {
93
- output[i] = models_ptr[i]->PredictLeafIndexByMap (features);
94
- }
95
- }
88
+ void GBDT::PredictLeafIndexByMap (const std::unordered_map<int , double >& features, double * output) const {
89
+ int start_tree = start_iteration_for_pred_ * num_tree_per_iteration_;
90
+ int num_trees = num_iteration_for_pred_ * num_tree_per_iteration_;
91
+ const auto * models_ptr = models_.data () + start_tree;
92
+ for (int i = 0 ; i < num_trees; ++i) {
93
+ output[i] = models_ptr[i]->PredictLeafIndexByMap (features);
94
+ }
95
+ }
96
96
97
- } // namespace LightGBM
97
+ } // namespace LightGBM
0 commit comments