src/training/common/sampleiterator.cpp
double SampleIterator::NormalizeSamples() {
  double total_weight = 0.0;
  int sample_count = 0;
  for (Begin(); !AtEnd(); Next()) {
    const TrainingSample &sample = GetSample();
    total_weight += sample.weight();
    ++sample_count;
  }
  // Normalize samples.
  double min_assigned_sample_weight = 1.0;
  if (total_weight > 0.0) {
    for (Begin(); !AtEnd(); Next()) {
      TrainingSample *sample = MutableSample();
      double weight = sample->weight() / total_weight;
      if (weight < min_assigned_sample_weight) {
        min_assigned_sample_weight = weight;
      }
      sample->set_weight(weight);
    }
  }
  return min_assigned_sample_weight;
}
// Normalize the weights of all the samples in the charset_map so they sum
// to 1. Returns the minimum assigned sample weight.
Normalize the weights of all the samples in the charset_map so they sum
to 1. Returns the minimum assigned sample weight.
Normalize the weights of all the samples in the charset_map so they sum to 1 . Returns the minimum assigned sample weight .
double SampleIterator::NormalizeSamples() {
  double total_weight = 0.0;
  int sample_count = 0;
  for (Begin(); !AtEnd(); Next()) {
    const TrainingSample &sample = GetSample();
    total_weight += sample.weight();
    ++sample_count;
  }
  double min_assigned_sample_weight = 1.0;
  if (total_weight > 0.0) {
    for (Begin(); !AtEnd(); Next()) {
      TrainingSample *sample = MutableSample();
      double weight = sample->weight() / total_weight;
      if (weight < min_assigned_sample_weight) {
        min_assigned_sample_weight = weight;
      }
      sample->set_weight(weight);
    }
  }
  return min_assigned_sample_weight;
}
double SampleIterator :: NormalizeSamples ( ) { double total_weight = 0.0 ; int sample_count = 0 ; for ( Begin ( ) ; ! AtEnd ( ) ; Next ( ) ) { const TrainingSample & sample = GetSample ( ) ; total_weight += sample . weight ( ) ; ++ sample_count ; } double min_assigned_sample_weight = 1.0 ; if ( total_weight > 0.0 ) { for ( Begin ( ) ; ! AtEnd ( ) ; Next ( ) ) { TrainingSample * sample = MutableSample ( ) ; double weight = sample -> weight ( ) / total_weight ; if ( weight < min_assigned_sample_weight ) { min_assigned_sample_weight = weight ; } sample -> set_weight ( weight ) ; } } return min_assigned_sample_weight ; }
Normalize the weights of all the samples in the charset_map so they sum
to 1.
Normalize the weights of all the samples in the charset_map so they sum to 1 .
// Normalize samples.