28 int32 num_gauss = 5 + rand () % 4;
30 DiagGmm &gmm(*gmm_in);
31 gmm.Resize(num_gauss, dim);
32 Matrix<BaseFloat> inv_vars(num_gauss, dim),
33 means(num_gauss, dim);
34 Vector<BaseFloat> weights(num_gauss);
35 for (
int32 i = 0;
i < num_gauss;
i++) {
42 weights.Scale(1.0 / weights.Sum());
43 gmm.SetWeights(weights);
44 gmm.SetInvVarsAndMeans(inv_vars, means);
51 using namespace kaldi;
55 int32 npoints = dim*(dim+1)*5;
57 for (
int32 i = 0;
i < npoints;
i++) {
69 for (
int32 i = 0;
i < npoints;
i++) {
81 stats.
Update(opts, &cur_xform, &objf_change, &count);
87 stats.
Update(opts, &mat, &objf_change_tmp, &count_tmp);
92 KALDI_LOG <<
"Objf change on iter " <<
j <<
" is " << objf_change;
93 objf_change_tot += objf_change;
96 int32 num_params = dim*(dim+1);
97 BaseFloat expected_objf_change = 0.5 * num_params;
98 KALDI_LOG <<
"Expected objf change is: not much more than " << expected_objf_change
99 <<
", seen: " << objf_change_tot;
100 KALDI_ASSERT(objf_change_tot < 2.0 * expected_objf_change);
108 using namespace kaldi;
112 int32 npoints = dim*(dim+1)*5;
114 for (
int32 i = 0;
i < npoints;
i++) {
126 for (
int32 j = 0;
j < niters;
j++) {
128 for (
int32 i = 0;
i < npoints;
i++) {
141 stats.
Update(opts, &cur_xform, &objf_change, &count);
147 stats.
Update(opts, &mat, &objf_change_tmp, &count_tmp);
152 KALDI_LOG <<
"Objf change on iter " <<
j <<
" is " << objf_change;
153 objf_change_tot += objf_change;
156 int32 num_params = dim*2;
157 BaseFloat expected_objf_change = 0.5 * num_params;
158 KALDI_LOG <<
"Expected objf change is: not much more than " << expected_objf_change
159 <<
", seen: " << objf_change_tot;
160 KALDI_ASSERT(objf_change_tot < 2.0 * expected_objf_change);
168 using namespace kaldi;
172 int32 npoints = dim*(dim+1)*5;
174 for (
int32 i = 0;
i < npoints;
i++) {
186 for (
int32 j = 0;
j < niters;
j++) {
188 for (
int32 i = 0;
i < npoints;
i++) {
201 stats.
Update(opts, &cur_xform, &objf_change, &count);
207 stats.
Update(opts, &mat, &objf_change_tmp, &count_tmp);
212 KALDI_LOG <<
"Objf change on iter " <<
j <<
" is " << objf_change;
213 objf_change_tot += objf_change;
216 int32 num_params = dim;
217 BaseFloat expected_objf_change = 0.5 * num_params;
218 KALDI_LOG <<
"Expected objf change is: not much more than " << expected_objf_change
219 <<
", seen: " << objf_change_tot;
220 KALDI_ASSERT(objf_change_tot < 2.0 * expected_objf_change);
228 for (
int i = 0;
i < 2;
i++) {
233 std::cout <<
"Test OK.\n";
void ApplyModelTransformToStats(const MatrixBase< BaseFloat > &xform, AffineXformStats *stats)
ApplyModelTransformToStats takes a transform "xform", which must be diagonal (i.e.
void InitRandomGmm(DiagGmm *gmm_in)
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
int32 Dim() const
Returns the dimensionality of the Gaussian mean vectors.
void UnitTestFmllrDiagGmmDiagonal()
This does not work with multiple feature transforms.
void AccumulateFromPosteriors(const DiagGmm &gmm, const VectorBase< BaseFloat > &data, const VectorBase< BaseFloat > &posteriors)
Accumulate stats for a GMM, given supplied posteriors.
std::string update_type
"full", "diag", "offset", "none"
float RandGauss(struct RandomState *state=NULL)
void SetUnit()
Sets to zero, except ones along diagonal [for non-square matrices too].
void ApplyFeatureTransformToStats(const MatrixBase< BaseFloat > &xform, AffineXformStats *stats)
This function applies a feature-level transform to stats (useful for certain techniques based on fMLL...
void UnitTestFmllrDiagGmm()
BaseFloat ComponentPosteriors(const VectorBase< BaseFloat > &data, Vector< BaseFloat > *posteriors) const
Computes the posterior probabilities of all Gaussian components given a data point.
int32 NumGauss() const
Returns the number of mixture components in the GMM.
int Rand(struct RandomState *state)
A class representing a vector.
#define KALDI_ASSERT(cond)
Definition for Gaussian Mixture Model with diagonal covariances.
void Generate(VectorBase< BaseFloat > *output)
Generates a random data-point from this distribution.
void ApplyAffineTransform(const MatrixBase< BaseFloat > &xform, VectorBase< BaseFloat > *vec)
Applies the affine transform 'xform' to the vector 'vec' and overwrites the contents of 'vec'...
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).
void UnitTestFmllrDiagGmmOffset()
BaseFloat AccumulateForGmm(const DiagGmm &gmm, const VectorBase< BaseFloat > &data, BaseFloat weight)
Accumulate stats for a single GMM in the model; returns log likelihood.
void Update(const FmllrOptions &opts, MatrixBase< BaseFloat > *fmllr_mat, BaseFloat *objf_impr, BaseFloat *count)
Update.