32 && src.
Dim() == dst_copy.
Dim());
34 num_mix = src_num_mix + dst_num_mix, dim = src.
Dim();
37 std::vector<SpMatrix<BaseFloat> > invcovars(num_mix);
38 for(
int32 i = 0;
i < dst_num_mix;
i++) {
39 invcovars[
i].Resize(dim);
42 for(
int32 i = 0;
i < src_num_mix;
i++) {
43 invcovars[
i+dst_num_mix].Resize(dim);
44 invcovars[
i+dst_num_mix].CopyFromSp(src.
inv_covars()[
i]);
55 dst_weight = dst_num_mix / static_cast<BaseFloat>(num_mix);
56 weights.
Range(0, dst_num_mix).AddVec(dst_weight, dst_copy.
weights());
57 weights.
Range(dst_num_mix, src_num_mix).AddVec(src_weight, src.
weights());
65 int main(
int argc,
char *argv[]) {
67 using namespace kaldi;
71 "Combine a number of GMMs into a larger GMM, with #Gauss = \n" 72 " sum(individual #Gauss)). Output full GMM, and a text file with\n" 73 " sizes of each individual GMM.\n" 74 "Usage: fgmm-global-merge [options] fgmm-out sizes-file-out fgmm-in1 fgmm-in2 ...\n";
78 po.
Register(
"binary", &binary,
"Write output in binary mode");
86 std::string fgmm_out_filename = po.
GetArg(1),
87 sizes_out_filename = po.
GetArg(2);
90 Output sizes_ko(sizes_out_filename,
false);
92 for (
int i = 3, max = po.
NumArgs();
i <= max;
i++) {
93 std::string stats_in_filename = po.
GetArg(
i);
95 Input ki(stats_in_filename, &binary_read);
106 sizes_ko.
Stream() <<
"\n";
110 KALDI_LOG <<
"Written merged GMM to " << fgmm_out_filename;
111 }
catch(
const std::exception &e) {
112 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.
const std::vector< SpMatrix< BaseFloat > > & inv_covars() const
int32 Dim() const
Returns the dimensionality of the Gaussian mean vectors.
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 Register(const std::string &name, bool *ptr, const std::string &doc)
void CopyFromFullGmm(const FullGmm &fullgmm)
Copies from given FullGmm.
void Resize(int32 nMix, int32 dim)
Resizes arrays to this dim. Does not initialize data.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void MergeFullGmm(const FullGmm &src, FullGmm *dst)
merges GMMs by appending Gaussians in "src" to "dst".
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.
int32 NumGauss() const
Returns the number of mixture components in the GMM.
const Vector< BaseFloat > & weights() const
void SetInvCovarsAndMeansInvCovars(const std::vector< SpMatrix< Real > > &invcovars, const Matrix< Real > &means_invcovars)
Use this if setting both, in the class's native format.
void Read(std::istream &is, bool binary)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
A class representing a vector.
#define KALDI_ASSERT(cond)
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
SubMatrix< Real > Range(const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Return a sub-part of matrix.
const Matrix< BaseFloat > & means_invcovars() const
int main(int argc, char *argv[])
SubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l)
Returns a sub-vector of a vector (a range of elements).