29   using namespace kaldi;
    33         "Normalize length of iVectors to equal sqrt(feature-dimension)\n"    35         "Usage:  ivector-normalize-length [options] <ivector-rspecifier> "    36         "<ivector-wspecifier>\n"    38         " ivector-normalize-length ark:ivectors.ark ark:normalized_ivectors.ark\n";
    41     bool normalize = 
true;
    43     po.Register(
"normalize", &normalize,
    44                 "Set this to false to disable normalization");
    47     po.Register(
"scaleup", &scaleup,
    48                 "If 'true', the normalized iVector is scaled-up by 'sqrt(dim)'");
    52     if (po.NumArgs() != 2) {
    57     std::string ivector_rspecifier = po.GetArg(1),
    58         ivector_wspecifier = po.GetArg(2);
    63     double tot_ratio = 0.0, tot_ratio2 = 0.0;
    69     for (; !ivector_reader.Done(); ivector_reader.Next()) {
    70       std::string key = ivector_reader.Key();
    76       if (!scaleup) ratio = norm;
    78       KALDI_VLOG(2) << 
"Ratio for key " << key << 
" is " << ratio;
    82         if (normalize) ivector.
Scale(1.0 / ratio);
    84       ivector_writer.Write(key, ivector);
    86       tot_ratio2 += ratio * ratio;
    90     KALDI_LOG << 
"Processed " << num_done << 
" iVectors.";
    92       BaseFloat avg_ratio = tot_ratio / num_done,
    93           ratio_stddev = sqrt(tot_ratio2 / num_done - avg_ratio * avg_ratio);
    94       KALDI_LOG << 
"Average ratio of iVector to expected length was "    95                 << avg_ratio << 
", standard deviation was " << ratio_stddev;
    97     return (num_done != 0 ? 0 : 1);
    98   } 
catch(
const std::exception &e) {
    99     std::cerr << e.what();
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
 
A templated class for writing objects to an archive or script file; see The Table concept...
 
Real Norm(Real p) const
Compute the p-th norm of the vector. 
 
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
 
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
 
MatrixIndexT Dim() const
Returns the dimension of the vector. 
 
void Scale(Real alpha)
Multiplies all elements by this constant. 
 
A class representing a vector.