gbdt.h 15.4 KB
Newer Older
Guolin Ke's avatar
Guolin Ke committed
1
2
3
4
#ifndef LIGHTGBM_BOOSTING_GBDT_H_
#define LIGHTGBM_BOOSTING_GBDT_H_

#include <LightGBM/boosting.h>
5
#include <LightGBM/objective_function.h>
Guolin Ke's avatar
Guolin Ke committed
6
#include <LightGBM/prediction_early_stop.h>
7

Guolin Ke's avatar
Guolin Ke committed
8
9
10
11
12
#include "score_updater.hpp"

#include <cstdio>
#include <vector>
#include <string>
13
#include <fstream>
Guolin Ke's avatar
Guolin Ke committed
14
#include <memory>
15
#include <mutex>
16
#include <map>
Guolin Ke's avatar
Guolin Ke committed
17
18

namespace LightGBM {
Guolin Ke's avatar
Guolin Ke committed
19

Guolin Ke's avatar
Guolin Ke committed
20
21
22
/*!
* \brief GBDT algorithm implementation. including Training, prediction, bagging.
*/
Guolin Ke's avatar
Guolin Ke committed
23
class GBDT : public GBDTBase {
Guolin Ke's avatar
Guolin Ke committed
24
public:
Guolin Ke's avatar
Guolin Ke committed
25

Guolin Ke's avatar
Guolin Ke committed
26
27
28
  /*!
  * \brief Constructor
  */
29
  GBDT();
Guolin Ke's avatar
Guolin Ke committed
30

Guolin Ke's avatar
Guolin Ke committed
31
32
33
34
  /*!
  * \brief Destructor
  */
  ~GBDT();
Guolin Ke's avatar
Guolin Ke committed
35

Guolin Ke's avatar
Guolin Ke committed
36
  /*!
Qiwei Ye's avatar
Qiwei Ye committed
37
  * \brief Initialization logic
zhangyafeikimi's avatar
zhangyafeikimi committed
38
  * \param gbdt_config Config for boosting
Guolin Ke's avatar
Guolin Ke committed
39
  * \param train_data Training data
40
  * \param objective_function Training objective function
Guolin Ke's avatar
Guolin Ke committed
41
42
  * \param training_metrics Training metrics
  */
43
  void Init(const BoostingConfig* gbdt_config, const Dataset* train_data, const ObjectiveFunction* objective_function,
Guolin Ke's avatar
Guolin Ke committed
44
            const std::vector<const Metric*>& training_metrics) override;
wxchan's avatar
wxchan committed
45
46

  /*!
Guolin Ke's avatar
Guolin Ke committed
47
  * \brief Merge model from other boosting object. Will insert to the front of current boosting object
wxchan's avatar
wxchan committed
48
49
50
51
52
53
54
55
56
57
58
59
  * \param other
  */
  void MergeFrom(const Boosting* other) override {
    auto other_gbdt = reinterpret_cast<const GBDT*>(other);
    // tmp move to other vector
    auto original_models = std::move(models_);
    models_ = std::vector<std::unique_ptr<Tree>>();
    // push model from other first
    for (const auto& tree : other_gbdt->models_) {
      auto new_tree = std::unique_ptr<Tree>(new Tree(*(tree.get())));
      models_.push_back(std::move(new_tree));
    }
Guolin Ke's avatar
Guolin Ke committed
60
    num_init_iteration_ = static_cast<int>(models_.size()) / num_tree_per_iteration_;
wxchan's avatar
wxchan committed
61
62
63
64
65
    // push model in current object
    for (const auto& tree : original_models) {
      auto new_tree = std::unique_ptr<Tree>(new Tree(*(tree.get())));
      models_.push_back(std::move(new_tree));
    }
Guolin Ke's avatar
Guolin Ke committed
66
    num_iteration_for_pred_ = static_cast<int>(models_.size()) / num_tree_per_iteration_;
wxchan's avatar
wxchan committed
67
68
  }

Guolin Ke's avatar
Guolin Ke committed
69
70
71
72
73
74
  /*!
  * \brief Reset the training data
  * \param train_data New Training data
  * \param objective_function Training objective function
  * \param training_metrics Training metrics
  */
75
76
  void ResetTrainingData(const Dataset* train_data, const ObjectiveFunction* objective_function,
                         const std::vector<const Metric*>& training_metrics) override;
wxchan's avatar
wxchan committed
77

Guolin Ke's avatar
Guolin Ke committed
78
79
80
81
82
83
  /*!
  * \brief Reset Boosting Config
  * \param gbdt_config Config for boosting
  */
  void ResetConfig(const BoostingConfig* gbdt_config) override;

Guolin Ke's avatar
Guolin Ke committed
84
  /*!
Qiwei Ye's avatar
Qiwei Ye committed
85
86
87
  * \brief Adding a validation dataset
  * \param valid_data Validation dataset
  * \param valid_metrics Metrics for validation dataset
Guolin Ke's avatar
Guolin Ke committed
88
  */
wxchan's avatar
wxchan committed
89
  void AddValidDataset(const Dataset* valid_data,
90
                       const std::vector<const Metric*>& valid_metrics) override;
Guolin Ke's avatar
Guolin Ke committed
91

Guolin Ke's avatar
Guolin Ke committed
92
93
94
95
96
  /*!
  * \brief Perform a full training procedure
  * \param snapshot_freq frequence of snapshot
  * \param model_output_path path of model file
  */
Guolin Ke's avatar
Guolin Ke committed
97
98
  void Train(int snapshot_freq, const std::string& model_output_path) override;

99
100
  void RefitTree(const std::vector<std::vector<int>>& tree_leaf_prediction) override;

Guolin Ke's avatar
Guolin Ke committed
101
  /*!
Guolin Ke's avatar
Guolin Ke committed
102
  * \brief Training logic
Guolin Ke's avatar
Guolin Ke committed
103
104
105
  * \param gradients nullptr for using default objective, otherwise use self-defined boosting
  * \param hessians nullptr for using default objective, otherwise use self-defined boosting
  * \return True if cannot train any more
Guolin Ke's avatar
Guolin Ke committed
106
  */
Guolin Ke's avatar
Guolin Ke committed
107
  virtual bool TrainOneIter(const score_t* gradients, const score_t* hessians) override;
108

wxchan's avatar
wxchan committed
109
110
111
112
113
  /*!
  * \brief Rollback one iteration
  */
  void RollbackOneIter() override;

Guolin Ke's avatar
Guolin Ke committed
114
115
116
  /*!
  * \brief Get current iteration
  */
Guolin Ke's avatar
Guolin Ke committed
117
  int GetCurrentIteration() const override { return static_cast<int>(models_.size()) / num_tree_per_iteration_; }
wxchan's avatar
wxchan committed
118

Guolin Ke's avatar
Guolin Ke committed
119
120
121
122
  /*!
  * \brief Can use early stopping for prediction or not
  * \return True if cannot use early stopping for prediction
  */
123
  bool NeedAccuratePrediction() const override {
124
125
126
127
128
129
130
    if (objective_function_ == nullptr) {
      return true;
    } else {
      return objective_function_->NeedAccuratePrediction();
    }
  }

Guolin Ke's avatar
Guolin Ke committed
131
132
133
134
135
  /*!
  * \brief Get evaluation result at data_idx data
  * \param data_idx 0: training data, 1: 1st validation data
  * \return evaluation result
  */
136
  std::vector<double> GetEvalAt(int data_idx) const override;
137

Guolin Ke's avatar
Guolin Ke committed
138
139
  /*!
  * \brief Get current training score
Guolin Ke's avatar
Guolin Ke committed
140
  * \param out_len length of returned score
Guolin Ke's avatar
Guolin Ke committed
141
142
  * \return training score
  */
143
  virtual const double* GetTrainingScore(int64_t* out_len) override;
144

Guolin Ke's avatar
Guolin Ke committed
145
146
147
148
149
  /*!
  * \brief Get size of prediction at data_idx data
  * \param data_idx 0: training data, 1: 1st validation data
  * \return The size of prediction
  */
Guolin Ke's avatar
Guolin Ke committed
150
151
152
153
154
155
156
157
  virtual int64_t GetNumPredictAt(int data_idx) const override {
    CHECK(data_idx >= 0 && data_idx <= static_cast<int>(valid_score_updater_.size()));
    data_size_t num_data = train_data_->num_data();
    if (data_idx > 0) {
      num_data = valid_score_updater_[data_idx - 1]->num_data();
    }
    return num_data * num_class_;
  }
Guolin Ke's avatar
Guolin Ke committed
158

Guolin Ke's avatar
Guolin Ke committed
159
160
161
162
  /*!
  * \brief Get prediction result at data_idx data
  * \param data_idx 0: training data, 1: 1st validation data
  * \param result used to store prediction result, should allocate memory before call this function
163
  * \param out_len length of returned score
Guolin Ke's avatar
Guolin Ke committed
164
  */
Guolin Ke's avatar
Guolin Ke committed
165
  void GetPredictAt(int data_idx, double* out_result, int64_t* out_len) override;
Guolin Ke's avatar
Guolin Ke committed
166

Guolin Ke's avatar
Guolin Ke committed
167
168
169
170
171
172
173
  /*!
  * \brief Get number of prediction for one data
  * \param num_iteration number of used iterations
  * \param is_pred_leaf True if predicting  leaf index
  * \param is_pred_contrib True if predicting feature contribution
  * \return number of prediction
  */
174
  inline int NumPredictOneRow(int num_iteration, bool is_pred_leaf, bool is_pred_contrib) const override {
Guolin Ke's avatar
Guolin Ke committed
175
176
177
178
179
180
181
182
    int num_preb_in_one_row = num_class_;
    if (is_pred_leaf) {
      int max_iteration = GetCurrentIteration();
      if (num_iteration > 0) {
        num_preb_in_one_row *= static_cast<int>(std::min(max_iteration, num_iteration));
      } else {
        num_preb_in_one_row *= max_iteration;
      }
183
184
    } else if (is_pred_contrib) {
      num_preb_in_one_row = max_feature_idx_ + 2; // +1 for 0-based indexing, +1 for baseline
Guolin Ke's avatar
Guolin Ke committed
185
186
187
    }
    return num_preb_in_one_row;
  }
Guolin Ke's avatar
Guolin Ke committed
188

cbecker's avatar
cbecker committed
189
  void PredictRaw(const double* features, double* output,
190
                  const PredictionEarlyStopInstance* earlyStop) const override;
wxchan's avatar
wxchan committed
191

Guolin Ke's avatar
Guolin Ke committed
192
193
  void PredictRawByMap(const std::unordered_map<int, double>& features, double* output,
                       const PredictionEarlyStopInstance* early_stop) const override;
194

cbecker's avatar
cbecker committed
195
196
  void Predict(const double* features, double* output,
               const PredictionEarlyStopInstance* earlyStop) const override;
Guolin Ke's avatar
Guolin Ke committed
197

Guolin Ke's avatar
Guolin Ke committed
198
199
  void PredictByMap(const std::unordered_map<int, double>& features, double* output,
                    const PredictionEarlyStopInstance* early_stop) const override;
200

201
  void PredictLeafIndex(const double* features, double* output) const override;
wxchan's avatar
wxchan committed
202

203
204
  void PredictLeafIndexByMap(const std::unordered_map<int, double>& features, double* output) const override;

205
206
207
  void PredictContrib(const double* features, double* output,
                      const PredictionEarlyStopInstance* earlyStop) const override;

Guolin Ke's avatar
Guolin Ke committed
208
  /*!
wxchan's avatar
wxchan committed
209
  * \brief Dump model to json format string
210
  * \param num_iteration Number of iterations that want to dump, -1 means dump all
wxchan's avatar
wxchan committed
211
  * \return Json format string of model
Guolin Ke's avatar
Guolin Ke committed
212
  */
213
  std::string DumpModel(int num_iteration) const override;
wxchan's avatar
wxchan committed
214

215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
  /*!
  * \brief Translate model to if-else statement
  * \param num_iteration Number of iterations that want to translate, -1 means translate all
  * \return if-else format codes of model
  */
  std::string ModelToIfElse(int num_iteration) const override;

  /*!
  * \brief Translate model to if-else statement
  * \param num_iteration Number of iterations that want to translate, -1 means translate all
  * \param filename Filename that want to save to
  * \return is_finish Is training finished or not
  */
  bool SaveModelToIfElse(int num_iteration, const char* filename) const override;

wxchan's avatar
wxchan committed
230
231
  /*!
  * \brief Save model to file
wxchan's avatar
wxchan committed
232
  * \param num_iterations Number of model that want to save, -1 means save all
wxchan's avatar
wxchan committed
233
  * \param filename Filename that want to save to
234
  * \return is_finish Is training finished or not
wxchan's avatar
wxchan committed
235
  */
236
  virtual bool SaveModelToFile(int num_iterations, const char* filename) const override;
wxchan's avatar
wxchan committed
237

238
239
  /*!
  * \brief Save model to string
wxchan's avatar
wxchan committed
240
  * \param num_iterations Number of model that want to save, -1 means save all
241
242
  * \return Non-empty string if succeeded
  */
243
  virtual std::string SaveModelToString(int num_iterations) const override;
244

Guolin Ke's avatar
Guolin Ke committed
245
  /*!
246
  * \brief Restore from a serialized buffer
Guolin Ke's avatar
Guolin Ke committed
247
  */
248
  bool LoadModelFromString(const char* buffer, size_t len) override;
wxchan's avatar
wxchan committed
249

250
251
252
253
254
255
256
257
  /*!
  * \brief Calculate feature importances
  * \param num_iteration Number of model that want to use for feature importance, -1 means use all
  * \param importance_type: 0 for split, 1 for gain
  * \return vector of feature_importance
  */
  std::vector<double> FeatureImportance(int num_iteration, int importance_type) const override;

Guolin Ke's avatar
Guolin Ke committed
258
259
260
261
262
  /*!
  * \brief Get max feature index of this model
  * \return Max feature index of this model
  */
  inline int MaxFeatureIdx() const override { return max_feature_idx_; }
Guolin Ke's avatar
Guolin Ke committed
263

wxchan's avatar
wxchan committed
264
265
266
267
268
269
  /*!
  * \brief Get feature names of this model
  * \return Feature names of this model
  */
  inline std::vector<std::string> FeatureNames() const override { return feature_names_; }

Guolin Ke's avatar
Guolin Ke committed
270
271
272
273
274
275
  /*!
  * \brief Get index of label column
  * \return index of label column
  */
  inline int LabelIdx() const override { return label_idx_; }

Guolin Ke's avatar
Guolin Ke committed
276
277
278
279
  /*!
  * \brief Get number of weak sub-models
  * \return Number of weak sub-models
  */
wxchan's avatar
wxchan committed
280
  inline int NumberOfTotalModel() const override { return static_cast<int>(models_.size()); }
Guolin Ke's avatar
Guolin Ke committed
281

Guolin Ke's avatar
Guolin Ke committed
282
283
284
285
  /*!
  * \brief Get number of tree per iteration
  * \return number of tree per iteration
  */
Guolin Ke's avatar
Guolin Ke committed
286
  inline int NumModelPerIteration() const override { return num_tree_per_iteration_; }
Guolin Ke's avatar
Guolin Ke committed
287

288
289
290
291
  /*!
  * \brief Get number of classes
  * \return Number of classes
  */
Guolin Ke's avatar
Guolin Ke committed
292
  inline int NumberOfClasses() const override { return num_class_; }
293

294
  inline void InitPredict(int num_iteration, bool is_pred_contrib) override {
Guolin Ke's avatar
Guolin Ke committed
295
    num_iteration_for_pred_ = static_cast<int>(models_.size()) / num_tree_per_iteration_;
wxchan's avatar
wxchan committed
296
    if (num_iteration > 0) {
Guolin Ke's avatar
Guolin Ke committed
297
      num_iteration_for_pred_ = std::min(num_iteration, num_iteration_for_pred_);
298
    }
299
300
301
302
303
304
    if (is_pred_contrib) {
      #pragma omp parallel for schedule(static)
      for (int i = 0; i < static_cast<int>(models_.size()); ++i) {
        models_[i]->RecomputeMaxDepth();
      }
    }
305
  }
wxchan's avatar
wxchan committed
306

Guolin Ke's avatar
Guolin Ke committed
307
  inline double GetLeafValue(int tree_idx, int leaf_idx) const override {
Guolin Ke's avatar
Guolin Ke committed
308
309
310
311
312
    CHECK(tree_idx >= 0 && static_cast<size_t>(tree_idx) < models_.size());
    CHECK(leaf_idx >= 0 && leaf_idx < models_[tree_idx]->num_leaves());
    return models_[tree_idx]->LeafOutput(leaf_idx);
  }

Guolin Ke's avatar
Guolin Ke committed
313
  inline void SetLeafValue(int tree_idx, int leaf_idx, double val) override {
Guolin Ke's avatar
Guolin Ke committed
314
315
316
317
318
    CHECK(tree_idx >= 0 && static_cast<size_t>(tree_idx) < models_.size());
    CHECK(leaf_idx >= 0 && leaf_idx < models_[tree_idx]->num_leaves());
    models_[tree_idx]->SetLeafOutput(leaf_idx, val);
  }

319
320
321
  /*!
  * \brief Get Type name of this boosting object
  */
Guolin Ke's avatar
Guolin Ke committed
322
  virtual const char* SubModelName() const override { return "tree"; }
323

324
protected:
Guolin Ke's avatar
Guolin Ke committed
325
326
327
328
329
330
331
332
333

  /*!
  * \brief Print eval result and check early stopping
  */
  bool EvalAndCheckEarlyStopping();

  /*!
  * \brief reset config for bagging
  */
Guolin Ke's avatar
Guolin Ke committed
334
  void ResetBaggingConfig(const BoostingConfig* config, bool is_change_dataset);
Guolin Ke's avatar
Guolin Ke committed
335

Guolin Ke's avatar
Guolin Ke committed
336
337
338
339
  /*!
  * \brief Implement bagging logic
  * \param iter Current interation
  */
340
341
342
343
344
345
346
347
348
  virtual void Bagging(int iter);

  /*!
  * \brief Helper function for bagging, used for multi-threading optimization
  * \param start start indice of bagging
  * \param cnt count
  * \param buffer output buffer
  * \return count of left size
  */
Guolin Ke's avatar
Guolin Ke committed
349
  data_size_t BaggingHelper(Random& cur_rand, data_size_t start, data_size_t cnt, data_size_t* buffer);
Guolin Ke's avatar
Guolin Ke committed
350

Guolin Ke's avatar
Guolin Ke committed
351
352
353
  /*!
  * \brief calculate the object function
  */
Guolin Ke's avatar
Guolin Ke committed
354
  virtual void Boosting();
Guolin Ke's avatar
Guolin Ke committed
355

Guolin Ke's avatar
Guolin Ke committed
356
  /*!
Qiwei Ye's avatar
Qiwei Ye committed
357
  * \brief updating score after tree was trained
Guolin Ke's avatar
Guolin Ke committed
358
  * \param tree Trained tree of this iteration
359
  * \param cur_tree_id Current tree for multiclass training
Guolin Ke's avatar
Guolin Ke committed
360
  */
361
  virtual void UpdateScore(const Tree* tree, const int cur_tree_id);
Guolin Ke's avatar
Guolin Ke committed
362

Guolin Ke's avatar
Guolin Ke committed
363
364
365
366
  /*!
  * \brief eval results for one metric

  */
Guolin Ke's avatar
Guolin Ke committed
367
  virtual std::vector<double> EvalOneMetric(const Metric* metric, const double* score) const;
Guolin Ke's avatar
Guolin Ke committed
368

Guolin Ke's avatar
Guolin Ke committed
369
  /*!
Hui Xue's avatar
Hui Xue committed
370
  * \brief Print metric result of current iteration
Guolin Ke's avatar
Guolin Ke committed
371
  * \param iter Current interation
Guolin Ke's avatar
Guolin Ke committed
372
  * \return best_msg if met early_stopping
Guolin Ke's avatar
Guolin Ke committed
373
  */
Guolin Ke's avatar
Guolin Ke committed
374
  std::string OutputMetric(int iter);
375

Guolin Ke's avatar
Guolin Ke committed
376
377
  double BoostFromAverage();

378
379
  /*! \brief current iteration */
  int iter_;
Guolin Ke's avatar
Guolin Ke committed
380
381
382
  /*! \brief Pointer to training data */
  const Dataset* train_data_;
  /*! \brief Config of gbdt */
Guolin Ke's avatar
Guolin Ke committed
383
  std::unique_ptr<BoostingConfig> gbdt_config_;
Hui Xue's avatar
Hui Xue committed
384
  /*! \brief Tree learner, will use this class to learn trees */
385
  std::unique_ptr<TreeLearner> tree_learner_;
Guolin Ke's avatar
Guolin Ke committed
386
  /*! \brief Objective function */
387
  const ObjectiveFunction* objective_function_;
Hui Xue's avatar
Hui Xue committed
388
  /*! \brief Store and update training data's score */
Guolin Ke's avatar
Guolin Ke committed
389
  std::unique_ptr<ScoreUpdater> train_score_updater_;
Guolin Ke's avatar
Guolin Ke committed
390
391
392
  /*! \brief Metrics for training data */
  std::vector<const Metric*> training_metrics_;
  /*! \brief Store and update validation data's scores */
Guolin Ke's avatar
Guolin Ke committed
393
  std::vector<std::unique_ptr<ScoreUpdater>> valid_score_updater_;
Guolin Ke's avatar
Guolin Ke committed
394
395
  /*! \brief Metric for validation data */
  std::vector<std::vector<const Metric*>> valid_metrics_;
wxchan's avatar
wxchan committed
396
397
  /*! \brief Number of rounds for early stopping */
  int early_stopping_round_;
Guolin Ke's avatar
Guolin Ke committed
398
  /*! \brief Best iteration(s) for early stopping */
wxchan's avatar
wxchan committed
399
  std::vector<std::vector<int>> best_iter_;
Guolin Ke's avatar
Guolin Ke committed
400
  /*! \brief Best score(s) for early stopping */
401
  std::vector<std::vector<double>> best_score_;
Guolin Ke's avatar
Guolin Ke committed
402
403
  /*! \brief output message of best iteration */
  std::vector<std::vector<std::string>> best_msg_;
Guolin Ke's avatar
Guolin Ke committed
404
  /*! \brief Trained models(trees) */
Guolin Ke's avatar
Guolin Ke committed
405
  std::vector<std::unique_ptr<Tree>> models_;
Guolin Ke's avatar
Guolin Ke committed
406
407
408
  /*! \brief Max feature index of training data*/
  int max_feature_idx_;
  /*! \brief First order derivative of training data */
409
  std::vector<score_t> gradients_;
Guolin Ke's avatar
Guolin Ke committed
410
  /*! \brief Secend order derivative of training data */
411
  std::vector<score_t> hessians_;
Guolin Ke's avatar
Guolin Ke committed
412
  /*! \brief Store the indices of in-bag data */
Guolin Ke's avatar
Guolin Ke committed
413
  std::vector<data_size_t> bag_data_indices_;
Guolin Ke's avatar
Guolin Ke committed
414
415
  /*! \brief Number of in-bag data */
  data_size_t bag_data_cnt_;
416
417
  /*! \brief Store the indices of in-bag data */
  std::vector<data_size_t> tmp_indices_;
wxchan's avatar
wxchan committed
418
  /*! \brief Number of training data */
Guolin Ke's avatar
Guolin Ke committed
419
  data_size_t num_data_;
420
421
422
  /*! \brief Number of trees per iterations */
  int num_tree_per_iteration_;
  /*! \brief Number of class */
423
  int num_class_;
Guolin Ke's avatar
Guolin Ke committed
424
425
  /*! \brief Index of label column */
  data_size_t label_idx_;
426
  /*! \brief number of used model */
wxchan's avatar
wxchan committed
427
  int num_iteration_for_pred_;
Guolin Ke's avatar
Guolin Ke committed
428
429
  /*! \brief Shrinkage rate for one iteration */
  double shrinkage_rate_;
wxchan's avatar
wxchan committed
430
431
  /*! \brief Number of loaded initial models */
  int num_init_iteration_;
Guolin Ke's avatar
Guolin Ke committed
432
433
  /*! \brief Feature names */
  std::vector<std::string> feature_names_;
Guolin Ke's avatar
Guolin Ke committed
434
  std::vector<std::string> feature_infos_;
435
436
437
438
439
440
441
442
443
444
445
446
  /*! \brief number of threads */
  int num_threads_;
  /*! \brief Buffer for multi-threading bagging */
  std::vector<data_size_t> offsets_buf_;
  /*! \brief Buffer for multi-threading bagging */
  std::vector<data_size_t> left_cnts_buf_;
  /*! \brief Buffer for multi-threading bagging */
  std::vector<data_size_t> right_cnts_buf_;
  /*! \brief Buffer for multi-threading bagging */
  std::vector<data_size_t> left_write_pos_buf_;
  /*! \brief Buffer for multi-threading bagging */
  std::vector<data_size_t> right_write_pos_buf_;
Guolin Ke's avatar
Guolin Ke committed
447
448
  std::unique_ptr<Dataset> tmp_subset_;
  bool is_use_subset_;
449
450
  std::vector<bool> class_need_train_;
  std::vector<double> class_default_output_;
451
  bool is_constant_hessian_;
452
  std::unique_ptr<ObjectiveFunction> loaded_objective_;
Guolin Ke's avatar
Guolin Ke committed
453
  bool average_output_;
Guolin Ke's avatar
Guolin Ke committed
454
  bool need_re_bagging_;
Guolin Ke's avatar
Guolin Ke committed
455
456
457
};

}  // namespace LightGBM
Guolin Ke's avatar
Guolin Ke committed
458
#endif   // LightGBM_BOOSTING_GBDT_H_