Medial Code Documentation
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes
LightGBM::SerialTreeLearner Class Reference

Used for learning a tree by single machine. More...

#include <serial_tree_learner.h>

Inheritance diagram for LightGBM::SerialTreeLearner:
LightGBM::TreeLearner LightGBM::GPUTreeLearner

Public Member Functions

 SerialTreeLearner (const Config *config)
 
void Init (const Dataset *train_data, bool is_constant_hessian) override
 Initialize tree learner with training dataset.
 
void ResetTrainingData (const Dataset *train_data) override
 
void ResetConfig (const Config *config) override
 Reset tree configs.
 
TreeTrain (const score_t *gradients, const score_t *hessians, bool is_constant_hessian, Json &forced_split_json) override
 training tree model on dataset
 
TreeFitByExistingTree (const Tree *old_tree, const score_t *gradients, const score_t *hessians) const override
 use a existing tree to fit the new gradients and hessians.
 
TreeFitByExistingTree (const Tree *old_tree, const std::vector< int > &leaf_pred, const score_t *gradients, const score_t *hessians) override
 
void SetBaggingData (const data_size_t *used_indices, data_size_t num_data) override
 Set bagging data.
 
void AddPredictionToScore (const Tree *tree, double *out_score) const override
 Using last trained tree to predict score then adding to out_score;.
 
void RenewTreeOutput (Tree *tree, const ObjectiveFunction *obj, const double *prediction, data_size_t total_num_data, const data_size_t *bag_indices, data_size_t bag_cnt) const override
 
void RenewTreeOutput (Tree *tree, const ObjectiveFunction *obj, double prediction, data_size_t total_num_data, const data_size_t *bag_indices, data_size_t bag_cnt) const override
 
- Public Member Functions inherited from LightGBM::TreeLearner
virtual ~TreeLearner ()
 virtual destructor
 
TreeLearneroperator= (const TreeLearner &)=delete
 Disable copy.
 
 TreeLearner (const TreeLearner &)=delete
 Disable copy.
 

Protected Member Functions

virtual void BeforeTrain ()
 Some initial works before training.
 
virtual bool BeforeFindBestSplit (const Tree *tree, int left_leaf, int right_leaf)
 Some initial works before FindBestSplit.
 
virtual void FindBestSplits ()
 
virtual void ConstructHistograms (const std::vector< int8_t > &is_feature_used, bool use_subtract)
 
virtual void FindBestSplitsFromHistograms (const std::vector< int8_t > &is_feature_used, bool use_subtract)
 
virtual void Split (Tree *tree, int best_leaf, int *left_leaf, int *right_leaf)
 Partition tree and data according best split.
 
virtual int32_t ForceSplits (Tree *tree, Json &forced_split_json, int *left_leaf, int *right_leaf, int *cur_depth, bool *aborted_last_force_split)
 
virtual data_size_t GetGlobalDataCountInLeaf (int leaf_idx) const
 Get the number of data in a leaf.
 

Protected Attributes

data_size_t num_data_
 number of data
 
int num_features_
 number of features
 
const Datasettrain_data_
 training data
 
const score_tgradients_
 gradients of current iteration
 
const score_thessians_
 hessians of current iteration
 
std::unique_ptr< DataPartitiondata_partition_
 training data partition on leaves
 
Random random_
 used for generate used features
 
std::vector< int8_t > is_feature_used_
 used for sub feature training, is_feature_used_[i] = false means don't used feature i
 
FeatureHistogramparent_leaf_histogram_array_
 pointer to histograms array of parent of current leaves
 
FeatureHistogramsmaller_leaf_histogram_array_
 pointer to histograms array of smaller leaf
 
FeatureHistogramlarger_leaf_histogram_array_
 pointer to histograms array of larger leaf
 
std::vector< SplitInfobest_split_per_leaf_
 store best split points for all leaves
 
std::unique_ptr< LeafSplitssmaller_leaf_splits_
 stores best thresholds for all feature for smaller leaf
 
std::unique_ptr< LeafSplitslarger_leaf_splits_
 stores best thresholds for all feature for larger leaf
 
std::vector< int > valid_feature_indices_
 
std::vector< score_tordered_gradients_
 gradients of current iteration, ordered for cache optimized
 
std::vector< score_tordered_hessians_
 hessians of current iteration, ordered for cache optimized
 
std::vector< std::unique_ptr< OrderedBin > > ordered_bins_
 Store ordered bin.
 
bool has_ordered_bin_ = false
 True if has ordered bin.
 
std::vector< char > is_data_in_leaf_
 is_data_in_leaf_[i] != 0 means i-th data is marked
 
HistogramPool histogram_pool_
 used to cache historical histogram to speed up
 
const Configconfig_
 config of tree learner
 
int num_threads_
 
std::vector< int > ordered_bin_indices_
 
bool is_constant_hessian_
 

Additional Inherited Members

- Static Public Member Functions inherited from LightGBM::TreeLearner
static TreeLearnerCreateTreeLearner (const std::string &learner_type, const std::string &device_type, const Config *config)
 Create object of tree learner.
 

Detailed Description

Used for learning a tree by single machine.

Member Function Documentation

◆ AddPredictionToScore()

void LightGBM::SerialTreeLearner::AddPredictionToScore ( const Tree tree,
double *  out_score 
) const
inlineoverridevirtual

Using last trained tree to predict score then adding to out_score;.

Parameters
out_scoreoutput score

Implements LightGBM::TreeLearner.

◆ FitByExistingTree() [1/2]

Tree * LightGBM::SerialTreeLearner::FitByExistingTree ( const Tree old_tree,
const score_t gradients,
const score_t hessians 
) const
overridevirtual

use a existing tree to fit the new gradients and hessians.

Implements LightGBM::TreeLearner.

◆ FitByExistingTree() [2/2]

Tree * LightGBM::SerialTreeLearner::FitByExistingTree ( const Tree old_tree,
const std::vector< int > &  leaf_pred,
const score_t gradients,
const score_t hessians 
)
overridevirtual

Implements LightGBM::TreeLearner.

◆ GetGlobalDataCountInLeaf()

data_size_t LightGBM::SerialTreeLearner::GetGlobalDataCountInLeaf ( int  leaf_idx) const
inlineprotectedvirtual

Get the number of data in a leaf.

Parameters
leaf_idxThe index of leaf
Returns
The number of data in the leaf_idx leaf

◆ Init()

void LightGBM::SerialTreeLearner::Init ( const Dataset train_data,
bool  is_constant_hessian 
)
overridevirtual

Initialize tree learner with training dataset.

Parameters
train_dataThe used training data
is_constant_hessianTrue if all hessians share the same value

Implements LightGBM::TreeLearner.

◆ RenewTreeOutput() [1/2]

void LightGBM::SerialTreeLearner::RenewTreeOutput ( Tree tree,
const ObjectiveFunction obj,
const double *  prediction,
data_size_t  total_num_data,
const data_size_t bag_indices,
data_size_t  bag_cnt 
) const
overridevirtual

Implements LightGBM::TreeLearner.

◆ RenewTreeOutput() [2/2]

void LightGBM::SerialTreeLearner::RenewTreeOutput ( Tree tree,
const ObjectiveFunction obj,
double  prediction,
data_size_t  total_num_data,
const data_size_t bag_indices,
data_size_t  bag_cnt 
) const
overridevirtual

Implements LightGBM::TreeLearner.

◆ ResetConfig()

void LightGBM::SerialTreeLearner::ResetConfig ( const Config config)
overridevirtual

Reset tree configs.

Parameters
configconfig of tree

Implements LightGBM::TreeLearner.

◆ ResetTrainingData()

void LightGBM::SerialTreeLearner::ResetTrainingData ( const Dataset train_data)
overridevirtual

Implements LightGBM::TreeLearner.

◆ SetBaggingData()

void LightGBM::SerialTreeLearner::SetBaggingData ( const data_size_t used_indices,
data_size_t  num_data 
)
inlineoverridevirtual

Set bagging data.

Parameters
used_indicesUsed data indices
num_dataNumber of used data

Implements LightGBM::TreeLearner.

◆ Split()

void LightGBM::SerialTreeLearner::Split ( Tree tree,
int  best_leaf,
int *  left_leaf,
int *  right_leaf 
)
protectedvirtual

Partition tree and data according best split.

Parameters
treeCurrent tree, will be splitted on this function.
best_leafThe index of leaf that will be splitted.
left_leafThe index of left leaf after splitted.
right_leafThe index of right leaf after splitted.

◆ Train()

Tree * LightGBM::SerialTreeLearner::Train ( const score_t gradients,
const score_t hessians,
bool  is_constant_hessian,
Json forced_split_json 
)
overridevirtual

training tree model on dataset

Parameters
gradientsThe first order gradients
hessiansThe second order gradients
is_constant_hessianTrue if all hessians share the same value
Returns
A trained tree

Implements LightGBM::TreeLearner.


The documentation for this class was generated from the following files: