Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When loading a binary file, take feature penalty from config if given there. #1881

Merged
merged 6 commits into from
Jan 16, 2019
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions src/io/dataset_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,21 +370,45 @@ Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* b
}
mem_ptr += sizeof(int) * (dataset->num_groups_);

const int8_t* tmp_ptr_monotone_type = reinterpret_cast<const int8_t*>(mem_ptr);
dataset->monotone_types_.clear();
for (int i = 0; i < dataset->num_features_; ++i) {
dataset->monotone_types_.push_back(tmp_ptr_monotone_type[i]);
if(!config_.monotone_constraints.empty()){
CHECK(dataset->num_total_features_ == config_.monotone_constraints.size());
dataset->monotone_types_.resize(dataset->num_features_);
for(int i = 0; i < dataset->num_total_features_; ++i){
int inner_fidx = dataset->InnerFeatureIndex(i);
if(inner_fidx >= 0) {
dataset->monotone_types_[inner_fidx] = config_.monotone_constraints[i];
StrikerRUS marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
else {
const int8_t* tmp_ptr_monotone_type = reinterpret_cast<const int8_t*>(mem_ptr);
dataset->monotone_types_.clear();
for (int i = 0; i < dataset->num_features_; ++i) {
dataset->monotone_types_.push_back(tmp_ptr_monotone_type[i]);
}
}
mem_ptr += sizeof(int8_t) * (dataset->num_features_);

if (ArrayArgs<int8_t>::CheckAllZero(dataset->monotone_types_)) {
dataset->monotone_types_.clear();
}

const double* tmp_ptr_feature_penalty = reinterpret_cast<const double*>(mem_ptr);
dataset->feature_penalty_.clear();
for (int i = 0; i < dataset->num_features_; ++i) {
dataset->feature_penalty_.push_back(tmp_ptr_feature_penalty[i]);
if(!config_.feature_contri.empty()){
CHECK(dataset->num_total_features_ == config_.feature_contri.size());
dataset->feature_penalty_.resize(dataset->num_features_);
for(int i = 0; i < dataset->num_total_features_; ++i){
int inner_fidx = dataset->InnerFeatureIndex(i);
if(inner_fidx >= 0) {
dataset->feature_penalty_[inner_fidx] = config_.feature_contri[i];
StrikerRUS marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
else {
const double* tmp_ptr_feature_penalty = reinterpret_cast<const double*>(mem_ptr);
dataset->feature_penalty_.clear();
for (int i = 0; i < dataset->num_features_; ++i) {
dataset->feature_penalty_.push_back(tmp_ptr_feature_penalty[i]);
}
}
mem_ptr += sizeof(double) * (dataset->num_features_);

Expand Down