40 KALDI_WARN <<
"Init() called on a non-empty object. Contents will be " 45 KALDI_WARN <<
"Init() called with number of pdfs = 0. Will do nothing.";
50 for (vector<DiagGmm*>::iterator itr =
densities_.begin(),
53 (*itr)->CopyFromDiagGmm(proto);
69 densities_.erase(densities_.begin() + pdf_index);
92 for (std::vector<DiagGmm*>::iterator itr =
densities_.begin(),
94 num_bad += (*itr)->ComputeGconsts();
97 KALDI_WARN <<
"Found " << num_bad <<
" Gaussian components.";
103 int32 target_components,
107 std::vector<int32> targets;
109 min_count, &targets);
117 << target_components <<
", power = " << power
118 <<
", perturb_factor = " << perturb_factor
119 <<
" and min_count = " << min_count
120 <<
", split #Gauss from " << gauss_at_start <<
" to " 126 int32 target_components,
130 std::vector<int32> targets;
132 power, min_count, &targets);
135 if (targets[
i] == 0) targets[
i] = 1;
141 << target_components <<
", power = " << power
142 <<
" and min_count = " << min_count
143 <<
", merged from " << gauss_at_start <<
" to " 156 for (
int32 i = 0;
i < num_pdfs;
i++) {
166 KALDI_WARN <<
"Trying to write empty AmDiagGmm object.";
168 WriteToken(out_stream, binary,
"<DIMENSION>");
172 for (std::vector<DiagGmm*>::const_iterator it =
densities_.begin(),
174 (*it)->Write(out_stream, binary);
179 if (ubm_num_gauss > intermediate_num_gauss)
180 KALDI_ERR <<
"Invalid parameters: --ubm-num_gauss=" << ubm_num_gauss
181 <<
" > --intermediate-num_gauss=" << intermediate_num_gauss;
182 if (ubm_num_gauss > max_am_gauss)
183 KALDI_ERR <<
"Invalid parameters: --ubm-num_gauss=" << ubm_num_gauss
184 <<
" > --max-am-gauss=" << max_am_gauss;
185 if (ubm_num_gauss <= 0)
186 KALDI_ERR <<
"Invalid parameters: --ubm-num_gauss=" << ubm_num_gauss;
187 if (cluster_varfloor <= 0)
188 KALDI_ERR <<
"Invalid parameters: --cluster-varfloor=" 190 if (reduce_state_factor <= 0 || reduce_state_factor > 1)
191 KALDI_ERR <<
"Invalid parameters: --reduce-state-factor=" 192 << reduce_state_factor;
201 KALDI_LOG <<
"ClusterGaussiansToUbm: first reducing num-gauss from " << am.
NumGauss()
211 <<
"; will not cluster further";
225 vector<Clusterable*> states;
226 states.reserve(num_pdfs);
229 KALDI_VLOG(1) <<
"Merging densities to 1 Gaussian per state.";
230 for (
int32 pdf_index = 0; pdf_index < num_pdfs; pdf_index++) {
231 KALDI_VLOG(3) <<
"Merging Gausians for state : " << pdf_index;
236 tmp_var.
AddVec2(1.0, tmp_mean);
240 BaseFloat this_weight = 1.0e-10 + state_occs(pdf_index);
241 tmp_mean.
Scale(this_weight);
242 tmp_var.
Scale(this_weight);
249 vector<int32> state_clusters;
250 KALDI_VLOG(1) <<
"Creating " << num_clust_states <<
" clusters of states.";
251 ClusterBottomUp(states, std::numeric_limits<BaseFloat>::max(), num_clust_states,
260 vector< vector<Clusterable*> > state_clust_gauss;
261 state_clust_gauss.resize(num_clust_states);
262 for (
int32 pdf_index = 0; pdf_index < num_pdfs; pdf_index++) {
263 int32 current_cluster = state_clusters[pdf_index];
265 gauss_index = 0; gauss_index < num_gauss; ++gauss_index) {
268 tmp_var.
AddVec2(1.0, tmp_mean);
271 BaseFloat this_weight = (1.0e-10 + state_occs(pdf_index)) *
273 tmp_mean.
Scale(this_weight);
274 tmp_var.
Scale(this_weight);
284 <<
" is more than num-gauss " << am.
NumGauss()
285 <<
", reducing it to " << am.
NumGauss();
292 <<
" is less than # of preclustered states " << num_clust_states
293 <<
", increasing it to " << num_clust_states;
300 vector< vector<Clusterable*> > gauss_clusters_out;
303 &gauss_clusters_out, NULL);
304 for (
int32 clust_index = 0; clust_index < num_clust_states; clust_index++)
309 <<
"into a single GMM for final merge step.";
314 int32 gauss_index = 0;
315 for (
int32 clust_index = 0; clust_index < num_clust_states; clust_index++) {
316 for (
int32 i = gauss_clusters_out[clust_index].size()-1;
i >=0; --
i) {
318 gauss_clusters_out[clust_index][
i]);
321 tmp_weights(gauss_index) = weight;
323 tmp_vec.
Scale(1.0 / weight);
326 tmp_vec.
Scale(1.0 / weight);
327 tmp_vec.
AddVec2(-1.0, tmp_means.
Row(gauss_index));
334 tmp_weights.
Scale(1.0/tmp_weights.
Sum());
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 CopyFromAmDiagGmm(const AmDiagGmm &other)
Copies the parameters from another model. Allocates necessary memory.
void AddPdf(const DiagGmm &gmm)
Adds a GMM to the model, and increments the total number of PDFs.
void CopyFromDiagGmm(const DiagGmm &diaggmm)
Copies from given DiagGmm.
void DeletePointers(std::vector< A *> *v)
Deletes any non-NULL pointers in the vector v, and sets the corresponding entries of v to NULL...
void RemovePdf(int32 pdf_index)
void SetInvVarsAndMeans(const MatrixBase< Real > &invvars, const MatrixBase< Real > &means)
Use SetInvVarsAndMeans if updating both means and (inverse) variances.
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) ...
int32 ComputeGconsts()
Sets the gconsts for all the PDFs.
void ReadBasicType(std::istream &is, bool binary, T *t)
ReadBasicType is the name of the read function for bool, integer types, and floating-point types...
void MergeByCount(const Vector< BaseFloat > &state_occs, int32 target_components, BaseFloat power, BaseFloat min_count)
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.
BaseFloat ClusterBottomUpCompartmentalized(const std::vector< std::vector< Clusterable *> > &points, BaseFloat thresh, int32 min_clust, std::vector< std::vector< Clusterable *> > *clusters_out, std::vector< std::vector< int32 > > *assignments_out)
This is a bottom-up clustering where the points are pre-clustered in a set of compartments, such that only points in the same compartment are clustered together.
void GetSplitTargets(const Vector< BaseFloat > &state_occs, int32 target_components, BaseFloat power, BaseFloat min_count, std::vector< int32 > *targets)
Get Gaussian-mixture or substate-mixture splitting targets, according to a power rule (e...
void AddVec2(const Real alpha, const VectorBase< Real > &v)
Add vector : *this = *this + alpha * rv^2 [element-wise squaring].
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
void ClusterGaussiansToUbm(const AmDiagGmm &am, const Vector< BaseFloat > &state_occs, UbmClusteringOptions opts, DiagGmm *ubm_out)
Clusters the Gaussians in an acoustic model to a single GMM with specified number of components...
void GetGaussianVariance(int32 pdf_index, int32 gauss, VectorBase< BaseFloat > *out) const
void ExpectToken(std::istream &is, bool binary, const char *token)
ExpectToken tries to read in the given token, and throws an exception on failure. ...
BaseFloat reduce_state_factor
BaseFloat ClusterBottomUp(const std::vector< Clusterable *> &points, BaseFloat max_merge_thresh, int32 min_clust, std::vector< Clusterable *> *clusters_out, std::vector< int32 > *assignments_out)
A bottom-up clustering algorithm.
std::vector< DiagGmm * > densities_
const Vector< BaseFloat > & weights() const
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
int32 NumGauss() const
Returns the number of mixture components in the GMM.
void Scale(Real alpha)
Multiplies all elements by this constant.
Real Sum() const
Returns sum of the elements.
void GetComponentVariance(int32 gauss, VectorBase< Real > *out) const
Accessor for single component variance.
DiagGmm & GetPdf(int32 pdf_index)
Accessors.
void InvertElements()
Inverts all the elements of the matrix.
A class representing a vector.
SubVector< double > x2_stats() const
#define KALDI_ASSERT(cond)
void Write(std::ostream &out_stream, bool binary) const
void GetGaussianMean(int32 pdf_index, int32 gauss, VectorBase< BaseFloat > *out) const
void CopyRowFromVec(const VectorBase< Real > &v, const MatrixIndexT row)
Copy vector into specific row of matrix.
Definition for Gaussian Mixture Model with diagonal covariances.
int32 intermediate_num_gauss
void WriteBasicType(std::ostream &os, bool binary, T t)
WriteBasicType is the name of the write function for bool, integer types, and floating-point types...
void SetWeights(const VectorBase< Real > &w)
Mutators for both float or double.
GaussClusterable wraps Gaussian statistics in a form accessible to generic clustering algorithms...
BaseFloat cluster_varfloor
void Init(const DiagGmm &proto, int32 num_pdfs)
Initializes with a single "prototype" GMM.
void Read(std::istream &in_stream, bool binary)
SubVector< double > x_stats() const
void SplitByCount(const Vector< BaseFloat > &state_occs, int32 target_components, float perturb_factor, BaseFloat power, BaseFloat min_count)