| 226 | } |
| 227 | |
| 228 | void Dataset::Construct( |
| 229 | std::vector<std::unique_ptr<BinMapper>>* bin_mappers, |
| 230 | int num_total_features, |
| 231 | const std::vector<std::vector<double>>& forced_bins, |
| 232 | int** sample_non_zero_indices, |
| 233 | const int* num_per_col, |
| 234 | int num_sample_col, |
| 235 | size_t total_sample_cnt, |
| 236 | const Config& io_config) { |
| 237 | num_total_features_ = num_total_features; |
| 238 | CHECK(num_total_features_ == static_cast<int>(bin_mappers->size())); |
| 239 | sparse_threshold_ = io_config.sparse_threshold; |
| 240 | // get num_features |
| 241 | std::vector<int> used_features; |
| 242 | auto& ref_bin_mappers = *bin_mappers; |
| 243 | for (int i = 0; i < static_cast<int>(bin_mappers->size()); ++i) { |
| 244 | if (ref_bin_mappers[i] != nullptr && !ref_bin_mappers[i]->is_trivial()) { |
| 245 | used_features.emplace_back(i); |
| 246 | } |
| 247 | } |
| 248 | if (used_features.empty()) { |
| 249 | Log::Warning("There are no meaningful features, as all feature values are constant."); |
| 250 | } |
| 251 | auto features_in_group = NoGroup(used_features); |
| 252 | |
| 253 | if (io_config.enable_bundle && !used_features.empty()) { |
| 254 | features_in_group = FastFeatureBundling(*bin_mappers, |
| 255 | sample_non_zero_indices, num_per_col, num_sample_col, total_sample_cnt, |
| 256 | used_features, io_config.max_conflict_rate, |
| 257 | num_data_, io_config.min_data_in_leaf, |
| 258 | sparse_threshold_, io_config.is_enable_sparse, io_config.device_type == std::string("gpu")); |
| 259 | } |
| 260 | |
| 261 | num_features_ = 0; |
| 262 | for (const auto& fs : features_in_group) { |
| 263 | num_features_ += static_cast<int>(fs.size()); |
| 264 | } |
| 265 | int cur_fidx = 0; |
| 266 | used_feature_map_ = std::vector<int>(num_total_features_, -1); |
| 267 | num_groups_ = static_cast<int>(features_in_group.size()); |
| 268 | real_feature_idx_.resize(num_features_); |
| 269 | feature2group_.resize(num_features_); |
| 270 | feature2subfeature_.resize(num_features_); |
| 271 | for (int i = 0; i < num_groups_; ++i) { |
| 272 | auto cur_features = features_in_group[i]; |
| 273 | int cur_cnt_features = static_cast<int>(cur_features.size()); |
| 274 | // get bin_mappers |
| 275 | std::vector<std::unique_ptr<BinMapper>> cur_bin_mappers; |
| 276 | for (int j = 0; j < cur_cnt_features; ++j) { |
| 277 | int real_fidx = cur_features[j]; |
| 278 | used_feature_map_[real_fidx] = cur_fidx; |
| 279 | real_feature_idx_[cur_fidx] = real_fidx; |
| 280 | feature2group_[cur_fidx] = i; |
| 281 | feature2subfeature_[cur_fidx] = j; |
| 282 | cur_bin_mappers.emplace_back(ref_bin_mappers[real_fidx].release()); |
| 283 | ++cur_fidx; |
| 284 | } |
| 285 | feature_groups_.emplace_back(std::unique_ptr<FeatureGroup>( |
no test coverage detected