MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / RenewTreeOutput

Method RenewTreeOutput

src/treelearner/serial_tree_learner2.cpp:922–960  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

920}
921
922void 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

Callers

nothing calls this directly

Calls 5

IsRenewTreeOutputMethod · 0.45
num_leavesMethod · 0.45
LeafOutputMethod · 0.45
GetIndexOnLeafMethod · 0.45
SetLeafOutputMethod · 0.45

Tested by

no test coverage detected