MCPcopy Create free account
hub / github.com/creatale/node-dv / NormalizeSamples

Method NormalizeSamples

deps/tesseract/classify/sampleiterator.cpp:233–253  ·  view source on GitHub ↗

Normalize the weights of all the samples in the charset_map so they sum to 1. Returns the minimum assigned sample weight.

Source from the content-addressed store, hash-verified

231// Normalize the weights of all the samples in the charset_map so they sum
232// to 1. Returns the minimum assigned sample weight.
233double 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.
256const UnicharAndFonts* SampleIterator::GetShapeEntry() const {

Callers 1

PostLoadCleanupMethod · 0.80

Calls 2

weightMethod · 0.80
set_weightMethod · 0.80

Tested by

no test coverage detected