28 int main(
int argc,
char *argv[]) {
29 using namespace kaldi;
33 "Multiplies iVectors (on the left) by a supplied transformation matrix\n" 35 "Usage: ivector-transform [options] <matrix-in> <ivector-rspecifier>" 36 "<ivector-wspecifier>\n" 38 " ivector-transform transform.mat ark:ivectors.ark ark:transformed_ivectors.ark\n";
49 std::string matrix_rxfilename = po.
GetArg(1),
50 ivector_rspecifier = po.
GetArg(2),
51 ivector_wspecifier = po.
GetArg(3);
73 for (; !ivector_reader.
Done(); ivector_reader.
Next()) {
74 std::string key = ivector_reader.
Key();
82 transformed_ivector.CopyFromVec(constant_term);
83 transformed_ivector.AddMatVec(1.0, linear_term,
kNoTrans, ivector, 1.0);
85 sum.AddVec(1.0, transformed_ivector);
86 sumsq +=
VecVec(transformed_ivector, transformed_ivector);
87 ivector_writer.
Write(key, transformed_ivector);
91 KALDI_LOG <<
"Processed " << num_done <<
" iVectors.";
93 sum.Scale(1.0 / num_done);
96 variance = sumsq -
VecVec(sum, sum),
97 avg_len = sqrt(variance),
98 norm_length = avg_len / sqrt(transform.
NumRows());
99 KALDI_LOG <<
"Norm of mean was " << mean_length
100 <<
" (should be close to zero), length divided by sqrt(dim) was " 101 << norm_length <<
" (should probably be close to one)";
103 return (num_done != 0 ? 0 : 1);
104 }
catch(
const std::exception &e) {
105 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
A templated class for writing objects to an archive or script file; see The Table concept...
void Write(const std::string &key, const T &value) const
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
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...
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
MatrixIndexT Dim() const
Returns the dimension of the vector.
void AddMatVec(const Real alpha, const MatrixBase< Real > &M, const MatrixTransposeType trans, const VectorBase< Real > &v, const Real beta)
Add matrix times vector : this <– beta*this + alpha*M*v.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void CopyColFromMat(const MatrixBase< OtherReal > &M, MatrixIndexT col)
Extracts a column of the matrix M.
A class representing a vector.
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Sub-matrix representation.