| 252 | } |
| 253 | |
| 254 | std::vector<double> FindBinWithZeroAsOneBin(const double* distinct_values, const int* counts, int num_distinct_values, |
| 255 | int max_bin, size_t total_sample_cnt, int min_data_in_bin) { |
| 256 | std::vector<double> bin_upper_bound; |
| 257 | int left_cnt_data = 0; |
| 258 | int cnt_zero = 0; |
| 259 | int right_cnt_data = 0; |
| 260 | for (int i = 0; i < num_distinct_values; ++i) { |
| 261 | if (distinct_values[i] <= -kZeroThreshold) { |
| 262 | left_cnt_data += counts[i]; |
| 263 | } else if (distinct_values[i] > kZeroThreshold) { |
| 264 | right_cnt_data += counts[i]; |
| 265 | } else { |
| 266 | cnt_zero += counts[i]; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | int left_cnt = -1; |
| 271 | for (int i = 0; i < num_distinct_values; ++i) { |
| 272 | if (distinct_values[i] > -kZeroThreshold) { |
| 273 | left_cnt = i; |
| 274 | break; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | if (left_cnt < 0) { |
| 279 | left_cnt = num_distinct_values; |
| 280 | } |
| 281 | |
| 282 | if ((left_cnt > 0) && (max_bin > 1)) { |
| 283 | int left_max_bin = static_cast<int>(static_cast<double>(left_cnt_data) / (total_sample_cnt - cnt_zero) * (max_bin - 1)); |
| 284 | left_max_bin = std::max(1, left_max_bin); |
| 285 | bin_upper_bound = GreedyFindBin(distinct_values, counts, left_cnt, left_max_bin, left_cnt_data, min_data_in_bin); |
| 286 | if (bin_upper_bound.size() > 0) { |
| 287 | bin_upper_bound.back() = -kZeroThreshold; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | int right_start = -1; |
| 292 | for (int i = left_cnt; i < num_distinct_values; ++i) { |
| 293 | if (distinct_values[i] > kZeroThreshold) { |
| 294 | right_start = i; |
| 295 | break; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | int right_max_bin = max_bin - 1 - static_cast<int>(bin_upper_bound.size()); |
| 300 | if (right_start >= 0 && right_max_bin > 0) { |
| 301 | auto right_bounds = GreedyFindBin(distinct_values + right_start, counts + right_start, |
| 302 | num_distinct_values - right_start, right_max_bin, right_cnt_data, min_data_in_bin); |
| 303 | bin_upper_bound.push_back(kZeroThreshold); |
| 304 | bin_upper_bound.insert(bin_upper_bound.end(), right_bounds.begin(), right_bounds.end()); |
| 305 | } else { |
| 306 | bin_upper_bound.push_back(std::numeric_limits<double>::infinity()); |
| 307 | } |
| 308 | CHECK(bin_upper_bound.size() <= static_cast<size_t>(max_bin)); |
| 309 | return bin_upper_bound; |
| 310 | } |
| 311 |
no test coverage detected