| 20 | |
| 21 | template <typename TREELEARNER_T> |
| 22 | void VotingParallelTreeLearner<TREELEARNER_T>::Init(const Dataset* train_data, bool is_constant_hessian) { |
| 23 | TREELEARNER_T::Init(train_data, is_constant_hessian); |
| 24 | rank_ = Network::rank(); |
| 25 | num_machines_ = Network::num_machines(); |
| 26 | |
| 27 | // limit top k |
| 28 | if (top_k_ > this->num_features_) { |
| 29 | top_k_ = this->num_features_; |
| 30 | } |
| 31 | // get max bin |
| 32 | int max_bin = 0; |
| 33 | for (int i = 0; i < this->num_features_; ++i) { |
| 34 | if (max_bin < this->train_data_->FeatureNumBin(i)) { |
| 35 | max_bin = this->train_data_->FeatureNumBin(i); |
| 36 | } |
| 37 | } |
| 38 | // calculate buffer size |
| 39 | size_t buffer_size = 2 * top_k_ * std::max(max_bin * sizeof(HistogramBinEntry), sizeof(LightSplitInfo) * num_machines_); |
| 40 | // left and right on same time, so need double size |
| 41 | input_buffer_.resize(buffer_size); |
| 42 | output_buffer_.resize(buffer_size); |
| 43 | |
| 44 | smaller_is_feature_aggregated_.resize(this->num_features_); |
| 45 | larger_is_feature_aggregated_.resize(this->num_features_); |
| 46 | |
| 47 | block_start_.resize(num_machines_); |
| 48 | block_len_.resize(num_machines_); |
| 49 | |
| 50 | smaller_buffer_read_start_pos_.resize(this->num_features_); |
| 51 | larger_buffer_read_start_pos_.resize(this->num_features_); |
| 52 | global_data_count_in_leaf_.resize(this->config_->num_leaves); |
| 53 | |
| 54 | smaller_leaf_splits_global_.reset(new LeafSplits(this->train_data_->num_data())); |
| 55 | larger_leaf_splits_global_.reset(new LeafSplits(this->train_data_->num_data())); |
| 56 | |
| 57 | local_config_ = *this->config_; |
| 58 | local_config_.min_data_in_leaf /= num_machines_; |
| 59 | local_config_.min_sum_hessian_in_leaf /= num_machines_; |
| 60 | |
| 61 | this->histogram_pool_.ResetConfig(&local_config_); |
| 62 | |
| 63 | // initialize histograms for global |
| 64 | smaller_leaf_histogram_array_global_.reset(new FeatureHistogram[this->num_features_]); |
| 65 | larger_leaf_histogram_array_global_.reset(new FeatureHistogram[this->num_features_]); |
| 66 | auto num_total_bin = this->train_data_->NumTotalBin(); |
| 67 | smaller_leaf_histogram_data_.resize(num_total_bin); |
| 68 | larger_leaf_histogram_data_.resize(num_total_bin); |
| 69 | feature_metas_.resize(train_data->num_features()); |
| 70 | #pragma omp parallel for schedule(static) |
| 71 | for (int i = 0; i < train_data->num_features(); ++i) { |
| 72 | feature_metas_[i].num_bin = train_data->FeatureNumBin(i); |
| 73 | feature_metas_[i].default_bin = train_data->FeatureBinMapper(i)->GetDefaultBin(); |
| 74 | feature_metas_[i].missing_type = train_data->FeatureBinMapper(i)->missing_type(); |
| 75 | feature_metas_[i].monotone_type = train_data->FeatureMonotone(i); |
| 76 | feature_metas_[i].penalty = train_data->FeaturePenalte(i); |
| 77 | if (train_data->FeatureBinMapper(i)->GetDefaultBin() == 0) { |
| 78 | feature_metas_[i].offset = 1; |
| 79 | } else { |
no test coverage detected