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

Method ConstructBinMappersFromTextData

src/io/dataset_loader.cpp:869–1046  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

867}
868
869void DatasetLoader::ConstructBinMappersFromTextData(int rank, int num_machines,
870 const std::vector<std::string>& sample_data,
871 const Parser* parser, Dataset* dataset) {
872 std::vector<std::vector<double>> sample_values;
873 std::vector<std::vector<int>> sample_indices;
874 std::vector<std::pair<int, double>> oneline_features;
875 double label;
876 for (int i = 0; i < static_cast<int>(sample_data.size()); ++i) {
877 oneline_features.clear();
878 // parse features
879 parser->ParseOneLine(sample_data[i].c_str(), &oneline_features, &label);
880 for (std::pair<int, double>& inner_data : oneline_features) {
881 if (static_cast<size_t>(inner_data.first) >= sample_values.size()) {
882 sample_values.resize(inner_data.first + 1);
883 sample_indices.resize(inner_data.first + 1);
884 }
885 if (std::fabs(inner_data.second) > kZeroThreshold || std::isnan(inner_data.second)) {
886 sample_values[inner_data.first].emplace_back(inner_data.second);
887 sample_indices[inner_data.first].emplace_back(i);
888 }
889 }
890 }
891
892 dataset->feature_groups_.clear();
893 dataset->num_total_features_ = std::max(static_cast<int>(sample_values.size()), parser->NumFeatures());
894 if (num_machines > 1) {
895 dataset->num_total_features_ = Network::GlobalSyncUpByMax(dataset->num_total_features_);
896 }
897 if (!feature_names_.empty()) {
898 CHECK(dataset->num_total_features_ == static_cast<int>(feature_names_.size()));
899 }
900
901 if (!config_.max_bin_by_feature.empty()) {
902 CHECK(static_cast<size_t>(dataset->num_total_features_) == config_.max_bin_by_feature.size());
903 CHECK(*(std::min_element(config_.max_bin_by_feature.begin(), config_.max_bin_by_feature.end())) > 1);
904 }
905
906 // get forced split
907 std::string forced_bins_path = config_.forcedbins_filename;
908 std::vector<std::vector<double>> forced_bin_bounds = DatasetLoader::GetForcedBins(forced_bins_path,
909 dataset->num_total_features_,
910 categorical_features_);
911
912 // check the range of label_idx, weight_idx and group_idx
913 CHECK(label_idx_ >= 0 && label_idx_ <= dataset->num_total_features_);
914 CHECK(weight_idx_ < 0 || weight_idx_ < dataset->num_total_features_);
915 CHECK(group_idx_ < 0 || group_idx_ < dataset->num_total_features_);
916
917 // fill feature_names_ if not header
918 if (feature_names_.empty()) {
919 for (int i = 0; i < dataset->num_total_features_; ++i) {
920 std::stringstream str_buf;
921 str_buf << "Column_" << i;
922 feature_names_.push_back(str_buf.str());
923 }
924 }
925 dataset->set_feature_names(feature_names_);
926 std::vector<std::unique_ptr<BinMapper>> bin_mappers(dataset->num_total_features_);

Callers

nothing calls this directly

Calls 15

min_elementFunction · 0.85
push_backMethod · 0.80
resetMethod · 0.80
dataMethod · 0.80
sizeMethod · 0.45
clearMethod · 0.45
ParseOneLineMethod · 0.45
resizeMethod · 0.45
NumFeaturesMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected