40 for (; !feat_reader.
Done(); feat_reader.
Next()) {
42 if (x_stats.
Dim() == 0) {
53 if (count == 0) {
KALDI_ERR <<
"No features were read!"; }
54 x_stats.
Scale(1.0/count);
55 x2_stats.
Scale(1.0/count);
56 x2_stats.
AddVec2(-1.0, x_stats);
57 if (x2_stats.
Min() <= 0.0)
58 KALDI_ERR <<
"Variance is zero or negative!";
70 int main(
int argc,
char *argv[]) {
71 using namespace kaldi;
73 using namespace kaldi;
77 "Initialize GMM, with Gaussians initialized to mean and variance\n" 78 "of some provided example data (or to 0,1 if not provided: in that\n" 79 "case, provide --dim option)\n" 80 "Usage: gmm-init-model-flat [options] <tree-in> <topo-file> <model-out> [<features-rspecifier>]\n" 82 " gmm-init-model-flat tree topo 1.mdl ark:feats.scp\n";
88 po.
Register(
"binary", &binary,
"Write output in binary mode");
89 po.
Register(
"dim", &dim,
"Dimension of model (this matters only if not providing features).");
99 tree_filename = po.
GetArg(1),
100 topo_filename = po.
GetArg(2),
101 model_out_filename = po.
GetArg(3),
115 dim = global_mean.
Dim();
117 global_inverse_var.
Resize(dim);
118 global_inverse_var.
Set(1.0);
122 int32 num_pdfs = ctx_dep.
NumPdfs();
129 inv_var.
Row(0).CopyFromVec(global_inverse_var);
131 mu.
Row(0).CopyFromVec(global_mean);
138 for (
int i = 0;
i < num_pdfs;
i++)
144 Output ko(model_out_filename, binary);
149 }
catch(
const std::exception &e) {
150 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void AddPdf(const DiagGmm &gmm)
Adds a GMM to the model, and increments the total number of PDFs.
void SetInvVarsAndMeans(const MatrixBase< Real > &invvars, const MatrixBase< Real > &means)
Use SetInvVarsAndMeans if updating both means and (inverse) variances.
A class for storing topology information for phones.
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].
void Resize(int32 nMix, int32 dim)
Resizes arrays to this dim. Does not initialize data.
int32 ComputeGconsts()
Sets the gconsts.
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
Real Min() const
Returns the minimum value of any element, or +infinity for the empty vector.
void Register(const std::string &name, bool *ptr, const std::string &doc)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
void AddVec2(const Real alpha, const VectorBase< Real > &v)
Add vector : *this = *this + alpha * rv^2 [element-wise squaring].
virtual int32 NumPdfs() const
NumPdfs() returns the number of acoustic pdfs (they are numbered 0.. NumPdfs()-1).
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
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 Scale(Real alpha)
Multiplies all elements by this constant.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void Write(std::ostream &os, bool binary) const
A class representing a vector.
void InvertElements()
Invert all elements.
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void Set(Real f)
Set all members of a vector to a specified value.
void Write(std::ostream &out_stream, bool binary) const
Definition for Gaussian Mixture Model with diagonal covariances.
void SetWeights(const VectorBase< Real > &w)
Mutators for both float or double.
int main(int argc, char *argv[])
void AddVec(const Real alpha, const VectorBase< OtherReal > &v)
Add vector : *this = *this + alpha * rv (with casting between floats and doubles) ...
void GetFeatureMeanAndVariance(const std::string &feat_rspecifier, Vector< BaseFloat > *inv_var_out, Vector< BaseFloat > *mean_out)
std::string GetOptArg(int param) const