27 int main(
int argc,
char *argv[]) {
29 using namespace kaldi;
34 "Initialize a full-covariance GMM from the accumulated stats.\n" 35 "This binary is similar to fgmm-global-est, but does not use " 36 "a preexisting model. See also fgmm-global-est.\n" 37 "Usage: fgmm-global-init-from-accs [options] <stats-in> " 38 "<number-of-components> <model-out>\n";
40 bool binary_write =
true;
42 po.
Register(
"binary", &binary_write,
"Write output in binary mode");
52 std::string stats_filename = po.
GetArg(1),
53 model_out_filename = po.
GetArg(3);
54 int32 num_components = atoi(po.
GetArg(2).c_str());
59 Input ki(stats_filename, &binary);
60 gmm_accs.Read(ki.
Stream(), binary,
true );
63 int32 num_gauss = gmm_accs.NumGauss(), dim = gmm_accs.Dim(),
64 tot_floored = 0, gauss_floored = 0, tot_low_occ = 0;
66 FullGmm fgmm(num_components, dim);
70 std::vector<SpMatrix<BaseFloat> > invcovars;
72 for (int32
i = 0;
i < num_components;
i++) {
89 mean.
Scale(1.0 / occ);
90 covar.
CopyFromSp(gmm_accs.covariance_accumulator()[
i]);
91 covar.
Scale(1.0 / occ);
102 tot_floored += floored;
106 invcovars.push_back(covar);
112 KALDI_LOG <<
"FullGmm has " << num_bad <<
" bad GConsts";
114 if (tot_floored > 0) {
115 KALDI_WARN << tot_floored <<
" variances floored in " << gauss_floored
118 if (tot_low_occ > 0) {
119 KALDI_WARN << tot_low_occ <<
" out of " << num_gauss
120 <<
" Gaussians had very low occupancy.";
125 KALDI_LOG <<
"Written model to " << model_out_filename;
126 }
catch(
const std::exception &e) {
127 std::cerr << e.what() <<
'\n';
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void SetWeights(const Vector< Real > &w)
Mutators for both float or double.
Packed symetric matrix class.
Configuration variables like variance floor, minimum occupancy, etc.
int32 ComputeGconsts()
Sets the gconsts.
Definition for Gaussian Mixture Model with full covariances.
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void InvertDouble(Real *logdet=NULL, Real *det_sign=NULL, bool inverse_needed=true)
void SetInvCovarsAndMeans(const std::vector< SpMatrix< Real > > &invcovars, const Matrix< Real > &means)
Use SetInvCovarsAndMeans if updating both means and (inverse) covariances.
BaseFloat variance_floor
Floor on eigenvalues of covariance matrices.
void CopyFromSp(const SpMatrix< Real > &other)
void CopyRowFromMat(const MatrixBase< Real > &M, MatrixIndexT row)
Extracts a row of the matrix M.
void Register(const std::string &name, bool *ptr, const std::string &doc)
int ApplyFloor(const SpMatrix< Real > &Floor, Real alpha=1.0, bool verbose=false)
Floors this symmetric matrix to the matrix alpha * Floor, where the matrix Floor is positive definite...
void AddVec2(const Real alpha, const VectorBase< OtherReal > &v)
rank-one update, this <– this + alpha v v'
int main(int argc, char *argv[])
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void Register(OptionsItf *opts)
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
Class for computing the maximum-likelihood estimates of the parameters of a Gaussian mixture model...
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.
Real Sum() const
Returns sum of the elements.
void SetRandn()
Set vector to random normally-distributed noise.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
A class representing a vector.
void CopyRowFromVec(const VectorBase< Real > &v, const MatrixIndexT row)
Copy vector into specific row of matrix.
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
BaseFloat max_condition
Maximum condition number of covariance matrices (apply floor to eigenvalues if they pass this)...
Real MaxAbsEig() const
Returns the maximum of the absolute values of any of the eigenvalues.
void AddDiagVec(const Real alpha, const VectorBase< OtherReal > &v)
diagonal update, this <– this + diag(v)