33 size_t maxiterations =
RandInt(2, 5);
38 int32 maxcomponents = 10;
43 for (
size_t m = 0; m < nMix; m++) {
44 for (
size_t d= 0;
d < dim;
d++) {
54 size_t counter_num = 0, multiple = 200;
56 for (
size_t m = 0; m < nMix; m++) {
57 for (
size_t i = 0;
i < multiple;
i++) {
58 for (
size_t d = 0;
d < dim;
d++) {
60 std::sqrt(vars_f(m,
d));
68 size_t counter_den = 0;
70 for (
size_t m = 0; m < nMix; m++) {
71 for (
size_t i = 0;
i < multiple;
i++) {
72 for (
size_t d = 0;
d < dim;
d++) {
74 std::sqrt(vars_f(m,
d));
84 for (
size_t i = 0;
i < counter_num;
i++) {
86 mean_acc.
AddVec(1.0, featvec);
88 var_acc.
AddVec(1.0, featvec);
90 mean_acc.
Scale(1.0F/counter_num);
91 var_acc.
Scale(1.0F/counter_num);
92 var_acc.
AddVec2(-1.0, mean_acc);
97 std::ofstream of(
"tmpfeats");
105 for (
size_t d= 0;
d < dim;
d++) {
128 double tau = (r/8)%2 == 0 ? 100 : 0.0;
143 size_t iteration = 0;
144 double last_log_like_diff = NAN;
145 while (iteration < maxiterations) {
153 double loglike_num = 0.0;
154 double loglike_den = 0.0;
155 for (
size_t i = 0;
i < counter_num;
i++) {
161 for (
size_t i = 0;
i < counter_den;
i++) {
168 std::cout <<
"Loglikelihood Num before iteration " << iteration <<
" : " 169 << std::scientific << loglike_num <<
" number of components: " 172 std::cout <<
"Loglikelihood Den before iteration " << iteration <<
" : " 173 << std::scientific << loglike_den <<
" number of components: " 176 double loglike_diff = loglike_num - loglike_den;
178 KALDI_LOG <<
"Objective changed " << last_log_like_diff
179 <<
" to " << loglike_diff;
180 if (loglike_diff < last_log_like_diff)
184 last_log_like_diff = loglike_diff;
190 std::cout <<
"MEANX: " << gmm->
weights() <<
'\n';
194 gmm, &auxf_gauss, &count, &num_floored);
203 std::cout <<
"MEANY: " << gmm->
weights() <<
'\n';
206 if ((iteration % 3 == 1) && (gmm->
NumGauss() * 2 <= maxcomponents)) {
208 std::cout <<
"Ngauss, Ndim: " << gmm->
NumGauss() <<
" " << gmm->
Dim() <<
'\n';
222 for (
int i = 0;
i < 5;
i++) {
225 std::cout <<
"Test OK.\n";
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 SetInvVarsAndMeans(const MatrixBase< Real > &invvars, const MatrixBase< Real > &means)
Use SetInvVarsAndMeans if updating both means and (inverse) variances.
void Split(int32 target_components, float perturb_factor, std::vector< int32 > *history=NULL)
Split the components and remember the order in which the components were split.
void UpdateEbwWeightsDiagGmm(const AccumDiagGmm &num_stats, const AccumDiagGmm &den_stats, const EbwWeightOptions &opts, DiagGmm *gmm, BaseFloat *auxf_change_out, BaseFloat *count_out)
void Resize(int32 nMix, int32 dim)
Resizes arrays to this dim. Does not initialize data.
int32 ComputeGconsts()
Sets the gconsts.
float RandGauss(struct RandomState *state=NULL)
uint16 GmmFlagsType
Bitwise OR of the above flags.
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
void IsmoothStatsDiagGmm(const AccumDiagGmm &src_stats, double tau, AccumDiagGmm *dst_stats)
I-Smooth the stats. src_stats and dst_stats do not have to be different.
void CopyRowFromMat(const MatrixBase< Real > &M, MatrixIndexT row)
Extracts a row of the matrix M.
void UpdateEbwDiagGmm(const AccumDiagGmm &num_stats, const AccumDiagGmm &den_stats, GmmFlagsType flags, const EbwOptions &opts, DiagGmm *gmm, BaseFloat *auxf_change_out, BaseFloat *count_out, int32 *num_floored_out)
void AddVec2(const Real alpha, const VectorBase< Real > &v)
Add vector : *this = *this + alpha * rv^2 [element-wise squaring].
BaseFloat AccumulateFromDiag(const DiagGmm &gmm, const VectorBase< BaseFloat > &data, BaseFloat frame_posterior)
Accumulate for all components given a diagonal-covariance GMM.
const Vector< BaseFloat > & weights() const
int32 NumGauss() const
Returns the number of mixture components in the GMM.
void Scale(Real alpha)
Multiplies all elements by this constant.
void SetZero(GmmFlagsType flags)
int Rand(struct RandomState *state)
void UnitTestEstimateMmieDiagGmm()
void InvertElements()
Inverts all the elements of the matrix.
A class representing a vector.
void ApplyPow(Real power)
Take all elements of vector to a power.
Definition for Gaussian Mixture Model with diagonal covariances.
std::string GmmFlagsToString(GmmFlagsType flags)
Convert GMM flags to string.
void SetWeights(const VectorBase< Real > &w)
Mutators for both float or double.
void Resize(int32 num_gauss, int32 dim, GmmFlagsType flags)
Allocates memory for accumulators.
void AddVec(const Real alpha, const VectorBase< OtherReal > &v)
Add vector : *this = *this + alpha * rv (with casting between floats and doubles) ...
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)