Normalize the weights of all the samples in the charset_map so they sum to 1. Returns the minimum assigned sample weight.
| 231 | // Normalize the weights of all the samples in the charset_map so they sum |
| 232 | // to 1. Returns the minimum assigned sample weight. |
| 233 | double SampleIterator::NormalizeSamples() { |
| 234 | double total_weight = 0.0; |
| 235 | int sample_count = 0; |
| 236 | for (Begin(); !AtEnd(); Next()) { |
| 237 | const TrainingSample& sample = GetSample(); |
| 238 | total_weight += sample.weight(); |
| 239 | ++sample_count; |
| 240 | } |
| 241 | // Normalize samples. |
| 242 | double min_assigned_sample_weight = 1.0; |
| 243 | if (total_weight > 0.0) { |
| 244 | for (Begin(); !AtEnd(); Next()) { |
| 245 | TrainingSample* sample = MutableSample(); |
| 246 | double weight = sample->weight() / total_weight; |
| 247 | if (weight < min_assigned_sample_weight) |
| 248 | min_assigned_sample_weight = weight; |
| 249 | sample->set_weight(weight); |
| 250 | } |
| 251 | } |
| 252 | return min_assigned_sample_weight; |
| 253 | } |
| 254 | |
| 255 | // Helper returns the current UnicharAndFont shape_entry. |
| 256 | const UnicharAndFonts* SampleIterator::GetShapeEntry() const { |
no test coverage detected