| 830 | } |
| 831 | |
| 832 | void SerialTreeLearner2::Split(Tree* tree, int best_leaf, int* left_leaf, int* right_leaf) { |
| 833 | // for (int i = 0; i < tree->num_leaves(); ++i) { |
| 834 | // double output = static_cast<double>(tree->LeafOutput(i)); |
| 835 | // Log::Info("TrainOneIter_a %d %f",i,output); |
| 836 | // } |
| 837 | const SplitInfo& best_split_info = best_split_per_leaf_[best_leaf]; |
| 838 | const int inner_feature_index = train_data_->InnerFeatureIndex(best_split_info.feature); |
| 839 | if (cegb_ != nullptr) { |
| 840 | cegb_->UpdateLeafBestSplits(tree, best_leaf, &best_split_info, &best_split_per_leaf_); |
| 841 | } |
| 842 | |
| 843 | |
| 844 | // left = parent |
| 845 | *left_leaf = best_leaf; |
| 846 | bool is_numerical_split = train_data_->FeatureBinMapper(inner_feature_index)->bin_type() == BinType::NumericalBin; |
| 847 | if (is_numerical_split) { |
| 848 | auto threshold_double = train_data_->RealThreshold(inner_feature_index, best_split_info.threshold); |
| 849 | // split tree, will return right leaf |
| 850 | *right_leaf = tree->Split(best_leaf, |
| 851 | inner_feature_index, |
| 852 | best_split_info.feature, |
| 853 | best_split_info.threshold, |
| 854 | threshold_double, |
| 855 | static_cast<double>(best_split_info.left_output), |
| 856 | static_cast<double>(best_split_info.right_output), |
| 857 | static_cast<data_size_t>(best_split_info.left_count), |
| 858 | static_cast<data_size_t>(best_split_info.right_count), |
| 859 | static_cast<double>(best_split_info.left_sum_hessian), |
| 860 | static_cast<double>(best_split_info.right_sum_hessian), |
| 861 | static_cast<float>(best_split_info.gain), |
| 862 | train_data_->FeatureBinMapper(inner_feature_index)->missing_type(), |
| 863 | best_split_info.default_left); |
| 864 | |
| 865 | data_partition_->Split(best_leaf, train_data_, inner_feature_index, |
| 866 | &best_split_info.threshold, 1, best_split_info.default_left, *right_leaf); |
| 867 | } else { |
| 868 | std::vector<uint32_t> cat_bitset_inner = Common::ConstructBitset(best_split_info.cat_threshold.data(), best_split_info.num_cat_threshold); |
| 869 | std::vector<int> threshold_int(best_split_info.num_cat_threshold); |
| 870 | for (int i = 0; i < best_split_info.num_cat_threshold; ++i) { |
| 871 | threshold_int[i] = static_cast<int>(train_data_->RealThreshold(inner_feature_index, best_split_info.cat_threshold[i])); |
| 872 | } |
| 873 | std::vector<uint32_t> cat_bitset = Common::ConstructBitset(threshold_int.data(), best_split_info.num_cat_threshold); |
| 874 | *right_leaf = tree->SplitCategorical(best_leaf, |
| 875 | inner_feature_index, |
| 876 | best_split_info.feature, |
| 877 | cat_bitset_inner.data(), |
| 878 | static_cast<int>(cat_bitset_inner.size()), |
| 879 | cat_bitset.data(), |
| 880 | static_cast<int>(cat_bitset.size()), |
| 881 | static_cast<double>(best_split_info.left_output), |
| 882 | static_cast<double>(best_split_info.right_output), |
| 883 | static_cast<data_size_t>(best_split_info.left_count), |
| 884 | static_cast<data_size_t>(best_split_info.right_count), |
| 885 | static_cast<double>(best_split_info.left_sum_hessian), |
| 886 | static_cast<double>(best_split_info.right_sum_hessian), |
| 887 | static_cast<float>(best_split_info.gain), |
| 888 | train_data_->FeatureBinMapper(inner_feature_index)->missing_type()); |
| 889 | data_partition_->Split(best_leaf, train_data_, inner_feature_index, |
no test coverage detected