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

Method ConstructHistograms

src/io/dataset.cpp:822–991  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

820}
821
822void Dataset::ConstructHistograms(const std::vector<int8_t>& is_feature_used,
823 const data_size_t* data_indices, data_size_t num_data,
824 int leaf_idx,
825 std::vector<std::unique_ptr<OrderedBin>>* ordered_bins,
826 const score_t* gradients, const score_t* hessians,
827 score_t* ordered_gradients, score_t* ordered_hessians,
828 bool is_constant_hessian,
829 HistogramBinEntry* hist_data) const {
830 if (leaf_idx < 0 || num_data < 0 || hist_data == nullptr) {
831 return;
832 }
833
834 std::vector<int> used_group;
835 used_group.reserve(num_groups_);
836 for (int group = 0; group < num_groups_; ++group) {
837 const int f_cnt = group_feature_cnt_[group];
838 bool is_group_used = false;
839 for (int j = 0; j < f_cnt; ++j) {
840 const int fidx = group_feature_start_[group] + j;
841 if (is_feature_used[fidx]) {
842 is_group_used = true;
843 break;
844 }
845 }
846 if (is_group_used) {
847 used_group.push_back(group);
848 }
849 }
850 int num_used_group = static_cast<int>(used_group.size());
851 auto ptr_ordered_grad = gradients;
852 auto ptr_ordered_hess = hessians;
853 auto& ref_ordered_bins = *ordered_bins;
854 if (data_indices != nullptr && num_data < num_data_) {
855 if (!is_constant_hessian) {
856 #pragma omp parallel for schedule(static)
857 for (data_size_t i = 0; i < num_data; ++i) {
858 ordered_gradients[i] = gradients[data_indices[i]];
859 ordered_hessians[i] = hessians[data_indices[i]];
860 }
861 } else {
862 #pragma omp parallel for schedule(static)
863 for (data_size_t i = 0; i < num_data; ++i) {
864 ordered_gradients[i] = gradients[data_indices[i]];
865 }
866 }
867 ptr_ordered_grad = ordered_gradients;
868 ptr_ordered_hess = ordered_hessians;
869 if (!is_constant_hessian) {
870 OMP_INIT_EX();
871 #pragma omp parallel for schedule(static)
872 for (int gi = 0; gi < num_used_group; ++gi) {
873 OMP_LOOP_EX_BEGIN();
874 int group = used_group[gi];
875 // feature is not used
876 auto data_ptr = hist_data + group_bin_boundaries_[group];
877 const int num_bin = feature_groups_[group]->num_total_bin_;
878 std::memset(reinterpret_cast<void*>(data_ptr + 1), 0, (num_bin - 1) * sizeof(HistogramBinEntry));
879 // construct histograms for smaller leaf

Callers

nothing calls this directly

Calls 4

push_backMethod · 0.80
reserveMethod · 0.45
sizeMethod · 0.45
ConstructHistogramMethod · 0.45

Tested by

no test coverage detected