| 76 | } |
| 77 | |
| 78 | void divideFeatureBlocks() { |
| 79 | // partition feature blocks |
| 80 | for (int i = 0; i < g_train_info_.slot_size(); ++i) { |
| 81 | auto info = g_train_info_.slot(i); |
| 82 | CHECK(info.has_id()); |
| 83 | if (info.id() == 0) continue; // it's the label |
| 84 | CHECK(info.has_nnz_ele()); |
| 85 | CHECK(info.has_nnz_ex()); |
| 86 | double nnz_per_row = (double)info.nnz_ele() / (double)info.nnz_ex(); |
| 87 | int n = 1; // number of blocks for a feature group |
| 88 | if (nnz_per_row > 1 + 1e-6) { |
| 89 | // only parititon feature group whose features are correlated |
| 90 | n = std::max((int)std::ceil(nnz_per_row * bcd_conf_.feature_block_ratio()), 1); |
| 91 | } |
| 92 | for (int i = 0; i < n; ++i) { |
| 93 | auto block = Range<Key>(info.min_key(), info.max_key()).evenDivide(n, i); |
| 94 | if (block.empty()) continue; |
| 95 | fea_blk_.push_back(std::make_pair(info.id(), block)); |
| 96 | } |
| 97 | } |
| 98 | LI << "Features are partitioned into " << fea_blk_.size() << " blocks"; |
| 99 | |
| 100 | // a simple block order |
| 101 | for (int i = 0; i < fea_blk_.size(); ++i) blk_order_.push_back(i); |
| 102 | |
| 103 | // blocks for important feature groups |
| 104 | std::vector<string> hit_blk; |
| 105 | for (int i = 0; i < bcd_conf_.prior_fea_group_size(); ++i) { |
| 106 | int grp_id = bcd_conf_.prior_fea_group(i); |
| 107 | std::vector<int> tmp; |
| 108 | for (int k = 0; k < fea_blk_.size(); ++k) { |
| 109 | if (fea_blk_[k].first == grp_id) tmp.push_back(k); |
| 110 | } |
| 111 | if (tmp.empty()) continue; |
| 112 | hit_blk.push_back(std::to_string(grp_id)); |
| 113 | for (int j = 0; j < bcd_conf_.num_iter_for_prior_fea_group(); ++j) { |
| 114 | if (bcd_conf_.random_feature_block_order()) { |
| 115 | std::random_shuffle(tmp.begin(), tmp.end()); |
| 116 | } |
| 117 | prior_blk_order_.insert(prior_blk_order_.end(), tmp.begin(), tmp.end()); |
| 118 | } |
| 119 | } |
| 120 | if (!hit_blk.empty()) LI << "Prior feature groups: " + join(hit_blk, ", "); |
| 121 | total_timer_.restart(); |
| 122 | } |
| 123 | |
| 124 | void saveModel(const DataConfig& data) { |
| 125 | Task task; |
nothing calls this directly
no test coverage detected