| 215 | } |
| 216 | |
| 217 | int BootstrapGini(int n, int s, const random::DistributionSampler& ds, |
| 218 | random::SimplePhilox* rand) { |
| 219 | std::vector<int> counts(s, 0); |
| 220 | for (int i = 0; i < n; i++) { |
| 221 | int j = ds.Sample(rand); |
| 222 | counts[j] += 1; |
| 223 | } |
| 224 | int g = 0; |
| 225 | for (int j = 0; j < s; j++) { |
| 226 | g += counts[j] * counts[j]; |
| 227 | } |
| 228 | // The true gini is 1 + (-g) / n^2 |
| 229 | return -g; |
| 230 | } |
| 231 | |
| 232 | // Populate *weights with the smoothed per-class frequencies needed to |
| 233 | // initialize a DistributionSampler. Returns the total number of samples |
no test coverage detected