31 gmm.
Resize(num_gauss, dim);
33 means(num_gauss, dim);
35 for (
int32 i = 0;
i < num_gauss;
i++) {
60 for (
int32 i = 0;
i < npoints;
i++) {
69 for (
int32 i = 0;
i < npoints;
i++) {
74 objf_change_tot += objf_change;
78 BaseFloat expected_objf_change = 0.5 * num_params;
79 KALDI_LOG <<
"Expected objf change is: not much more than " 80 << expected_objf_change <<
", seen: " << objf_change_tot;
81 KALDI_ASSERT(objf_change_tot < 2.0 * expected_objf_change);
92 std::cout <<
"Testing NumGauss: " << nMix <<
", " <<
"Dim: " << dim
101 for (
size_t d = 0;
d < dim;
d++) {
105 float tot_weight = 0.0;
106 for (
size_t m = 0; m < nMix; m++) {
108 for (
size_t d= 0;
d < dim;
d++) {
112 tot_weight += weights(m);
116 for (
size_t m = 0; m < nMix; m++) {
117 weights(m) /= tot_weight;
118 for (
size_t d= 0;
d < dim;
d++) {
120 means(m,
d)) * (feat(
d) - means(m,
d)) / vars(m,
d));
122 loglikes(m) +=
Log(weights(m));
139 std::cout <<
"LogLike: " << loglike <<
'\n';
140 std::cout <<
"LogLike1: " << loglike1 <<
'\n';
170 std::vector<int32> indices;
172 indices.push_back(
i);
181 gmm3.SetWeights(weights_bak);
183 for (
size_t i = 0;
i < nMix;
i++) {
186 gmm3.SetComponentMean(
i, row);
188 gmm3.SetInvVars(invvars_bak);
189 gmm3.ComputeGconsts();
190 BaseFloat loglike_gmm3 = gmm3.LogLikelihood(feat);
203 Input ki(
"tmpf", &binary_in);
216 Input ki2(
"tmpfb", &binary_in);
229 means1.CopyFromMat(means.Range(0, 1, 0, dim));
230 vars1.CopyFromMat(vars.Range(0, 1, 0, dim));
239 gmm2.
Split(2, 0.001);
252 means1.CopyFromMat(means.Range(0, 1, 0, dim));
253 vars1.CopyFromMat(vars.Range(0, 1, 0, dim));
262 gmm2.
Split(2, 0.001);
275 means1.CopyFromMat(means.Range(0, 1, 0, dim));
276 vars1.CopyFromMat(vars.Range(0, 1, 0, dim));
284 std::vector<std::pair<BaseFloat, const DiagGmm*> > vec;
285 vec.push_back(std::make_pair(static_cast<BaseFloat>(0.4), (
const DiagGmm*)(&gmm1)));
286 vec.push_back(std::make_pair(static_cast<BaseFloat>(0.6), (
const DiagGmm*)(&gmm1)));
303 for (
int i = 0;
i < 2;
i++) {
307 std::cout <<
"Test OK.\n";
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 CopyFromDiagGmm(const DiagGmm &diaggmm)
Copies from given DiagGmm.
void Perturb(float perturb_factor)
Perturbs the component means with a random vector multiplied by the pertrub factor.
void SetInvVarsAndMeans(const MatrixBase< Real > &invvars, const MatrixBase< Real > &means)
Use SetInvVarsAndMeans if updating both means and (inverse) variances.
void Write(std::ostream &os, bool binary) const
void Merge(int32 target_components, std::vector< int32 > *history=NULL)
Merge the components and remember the order in which the components were merged (flat list of pairs) ...
void LogLikelihoodsPreselect(const VectorBase< BaseFloat > &data, const std::vector< int32 > &indices, Vector< BaseFloat > *loglikes) const
Outputs the per-component log-likelihoods of a subset of mixture components.
float RandUniform(struct RandomState *state=NULL)
Returns a random number strictly between 0 and 1.
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 MleDiagGmmUpdate(const MleDiagGmmOptions &config, const AccumDiagGmm &diag_gmm_acc, GmmFlagsType flags, DiagGmm *gmm, BaseFloat *obj_change_out, BaseFloat *count_out, int32 *floored_elements_out, int32 *floored_gaussians_out, int32 *removed_gaussians_out)
for computing the maximum-likelihood estimates of the parameters of a Gaussian mixture model...
void GetComponentMean(int32 gauss, VectorBase< Real > *out) const
Accessor for single component mean.
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)
void SetMeans(const MatrixBase< Real > &m)
Use SetMeans to update only the Gaussian means (and not variances)
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
Real LogSumExp(Real prune=-1.0) const
Returns log(sum(exp())) without exp overflow If prune > 0.0, ignores terms less than the max - prune...
void GetVars(Matrix< Real > *v) const
Accessor for covariances.
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
BaseFloat ComponentPosteriors(const VectorBase< BaseFloat > &data, Vector< BaseFloat > *posteriors) const
Computes the posterior probabilities of all Gaussian components given a data point.
BaseFloat AccumulateFromDiag(const DiagGmm &gmm, const VectorBase< BaseFloat > &data, BaseFloat frame_posterior)
Accumulate for all components given a diagonal-covariance GMM.
void UnitTestDiagGmmGenerate()
BaseFloat LogLikelihood(const VectorBase< BaseFloat > &data) const
Returns the log-likelihood of a data point (vector) given the GMM.
void GetMeans(Matrix< Real > *m) const
Accessor for means.
const Vector< BaseFloat > & weights() const
int32 NumGauss() const
Returns the number of mixture components in the GMM.
void SetZero()
Sets matrix to zero.
Configuration variables like variance floor, minimum occupancy, etc.
void Scale(Real alpha)
Multiplies all elements by this constant.
void LogLikelihoods(const VectorBase< BaseFloat > &data, Vector< BaseFloat > *loglikes) const
Outputs the per-component log-likelihoods.
int Rand(struct RandomState *state)
Real Sum() const
Returns sum of the elements.
void MergeKmeans(int32 target_components, ClusterKMeansOptions cfg=ClusterKMeansOptions())
void SetInvVars(const MatrixBase< Real > &v)
Set the (inverse) variances and recompute means_invvars_.
void InvertElements()
Inverts all the elements of the matrix.
void Read(std::istream &in, bool binary)
A class representing a vector.
#define KALDI_ASSERT(cond)
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition for Gaussian Mixture Model with diagonal covariances.
void Generate(VectorBase< BaseFloat > *output)
Generates a random data-point from this distribution.
void SetWeights(const VectorBase< Real > &w)
Mutators for both float or double.
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)