| 153 | } |
| 154 | |
| 155 | std::vector<double> FindBinWithPredefinedBin(const double* distinct_values, const int* counts, |
| 156 | int num_distinct_values, int max_bin, |
| 157 | size_t total_sample_cnt, int min_data_in_bin, |
| 158 | const std::vector<double>& forced_upper_bounds) { |
| 159 | std::vector<double> bin_upper_bound; |
| 160 | |
| 161 | // get list of distinct values |
| 162 | int left_cnt_data = 0; |
| 163 | int cnt_zero = 0; |
| 164 | int right_cnt_data = 0; |
| 165 | for (int i = 0; i < num_distinct_values; ++i) { |
| 166 | if (distinct_values[i] <= -kZeroThreshold) { |
| 167 | left_cnt_data += counts[i]; |
| 168 | } else if (distinct_values[i] > kZeroThreshold) { |
| 169 | right_cnt_data += counts[i]; |
| 170 | } else { |
| 171 | cnt_zero += counts[i]; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | // get number of positive and negative distinct values |
| 176 | int left_cnt = -1; |
| 177 | for (int i = 0; i < num_distinct_values; ++i) { |
| 178 | if (distinct_values[i] > -kZeroThreshold) { |
| 179 | left_cnt = i; |
| 180 | break; |
| 181 | } |
| 182 | } |
| 183 | if (left_cnt < 0) { |
| 184 | left_cnt = num_distinct_values; |
| 185 | } |
| 186 | int right_start = -1; |
| 187 | for (int i = left_cnt; i < num_distinct_values; ++i) { |
| 188 | if (distinct_values[i] > kZeroThreshold) { |
| 189 | right_start = i; |
| 190 | break; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | // include zero bounds and infinity bound |
| 195 | if (max_bin == 2) { |
| 196 | if (left_cnt == 0) { |
| 197 | bin_upper_bound.push_back(kZeroThreshold); |
| 198 | } else { |
| 199 | bin_upper_bound.push_back(-kZeroThreshold); |
| 200 | } |
| 201 | } else if (max_bin >= 3) { |
| 202 | if (left_cnt > 0) { |
| 203 | bin_upper_bound.push_back(-kZeroThreshold); |
| 204 | } |
| 205 | if (right_start >= 0) { |
| 206 | bin_upper_bound.push_back(kZeroThreshold); |
| 207 | } |
| 208 | } |
| 209 | bin_upper_bound.push_back(std::numeric_limits<double>::infinity()); |
| 210 | |
| 211 | // add forced bounds, excluding zeros since we have already added zero bounds |
| 212 | int max_to_insert = max_bin - static_cast<int>(bin_upper_bound.size()); |
no test coverage detected