| 920 | } |
| 921 | |
| 922 | void SerialTreeLearner2::RenewTreeOutput(Tree* tree, const ObjectiveFunction* obj, std::function<double(const label_t*, int)> residual_getter, |
| 923 | data_size_t total_num_data, const data_size_t* bag_indices, data_size_t bag_cnt) const { |
| 924 | if (obj != nullptr && obj->IsRenewTreeOutput()) { |
| 925 | CHECK(tree->num_leaves() <= data_partition_->num_leaves()); |
| 926 | const data_size_t* bag_mapper = nullptr; |
| 927 | if (total_num_data != num_data_) { |
| 928 | CHECK(bag_cnt == num_data_); |
| 929 | bag_mapper = bag_indices; |
| 930 | } |
| 931 | std::vector<int> n_nozeroworker_perleaf(tree->num_leaves(), 1); |
| 932 | int num_machines = Network::num_machines(); |
| 933 | #pragma omp parallel for schedule(static) |
| 934 | for (int i = 0; i < tree->num_leaves(); ++i) { |
| 935 | const double output = static_cast<double>(tree->LeafOutput(i)); |
| 936 | data_size_t cnt_leaf_data = 0; |
| 937 | auto index_mapper = data_partition_->GetIndexOnLeaf(i, &cnt_leaf_data); |
| 938 | if (cnt_leaf_data > 0) { |
| 939 | // bag_mapper[index_mapper[i]] |
| 940 | const double new_output = obj->RenewTreeOutput(output, residual_getter, index_mapper, bag_mapper, cnt_leaf_data); |
| 941 | tree->SetLeafOutput(i, new_output); |
| 942 | } else { |
| 943 | CHECK(num_machines > 1); |
| 944 | tree->SetLeafOutput(i, 0.0); |
| 945 | n_nozeroworker_perleaf[i] = 0; |
| 946 | } |
| 947 | } |
| 948 | if (num_machines > 1) { |
| 949 | std::vector<double> outputs(tree->num_leaves()); |
| 950 | for (int i = 0; i < tree->num_leaves(); ++i) { |
| 951 | outputs[i] = static_cast<double>(tree->LeafOutput(i)); |
| 952 | } |
| 953 | outputs = Network::GlobalSum(&outputs); |
| 954 | n_nozeroworker_perleaf = Network::GlobalSum(&n_nozeroworker_perleaf); |
| 955 | for (int i = 0; i < tree->num_leaves(); ++i) { |
| 956 | tree->SetLeafOutput(i, outputs[i] / n_nozeroworker_perleaf[i]); |
| 957 | } |
| 958 | } |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | } // namespace LightGBM |
nothing calls this directly
no test coverage detected