mle-full-gmm.cc
Go to the documentation of this file.
1 // gmm/mle-full-gmm.cc
2 
3 // Copyright 2009-2011 Jan Silovsky; Saarland University;
4 // Microsoft Corporation; Georg Stemmer
5 // Univ. Erlangen-Nuremberg, Korbinian Riedhammer
6 
7 // See ../../COPYING for clarification regarding multiple authors
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
17 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
18 // MERCHANTABLITY OR NON-INFRINGEMENT.
19 // See the Apache 2 License for the specific language governing permissions and
20 // limitations under the License.
21 
22 #include <string>
23 
24 #include "gmm/full-gmm.h"
25 #include "gmm/diag-gmm.h"
26 #include "gmm/mle-full-gmm.h"
27 
28 namespace kaldi {
29 
30 
32  : dim_(other.dim_), num_comp_(other.num_comp_),
33  flags_(other.flags_), occupancy_(other.occupancy_),
34  mean_accumulator_(other.mean_accumulator_),
35  covariance_accumulator_(other.covariance_accumulator_) {}
36 
37 void AccumFullGmm::Resize(int32 num_comp, int32 dim, GmmFlagsType flags) {
38  num_comp_ = num_comp;
39  dim_ = dim;
40  flags_ = AugmentGmmFlags(flags);
41  occupancy_.Resize(num_comp);
42  if (flags_ & kGmmMeans)
43  mean_accumulator_.Resize(num_comp, dim);
44  else
46 
47  if (flags_ & kGmmVariances)
48  ResizeVarAccumulator(num_comp, dim);
49  else
51 }
52 
54  KALDI_ASSERT(num_comp > 0 && dim > 0);
55  if (covariance_accumulator_.size() != static_cast<size_t>(num_comp))
56  covariance_accumulator_.resize(num_comp);
57  for (int32 i = 0; i < num_comp; i++) {
58  if (covariance_accumulator_[i].NumRows() != dim)
59  covariance_accumulator_[i].Resize(dim);
60  }
61 }
62 
64  if (flags & ~flags_)
65  KALDI_ERR << "Flags in argument do not match the active accumulators";
66 
67  if (flags & kGmmWeights)
69 
70  if (flags & kGmmMeans)
72 
73  if (flags & kGmmVariances) {
74  for (int32 i = 0, end = covariance_accumulator_.size(); i < end; i++)
76  }
77 }
78 
80  if (flags & ~flags_)
81  KALDI_ERR << "Flags in argument do not match the active accumulators";
82 
83  double d = static_cast<double>(f);
84  if (flags & kGmmWeights)
85  occupancy_.Scale(d);
86 
87  if (flags & kGmmMeans)
89 
90  if (flags & kGmmVariances) {
91  for (int32 i = 0, end = covariance_accumulator_.size(); i < end; i++)
93  }
94 }
95 
97  const VectorBase<BaseFloat> &data, int32 comp_index, BaseFloat weight) {
98  KALDI_ASSERT(data.Dim() == Dim());
99  double wt = static_cast<double>(weight);
100 
101  // accumulate
102  occupancy_(comp_index) += wt;
103  if (flags_ & kGmmMeans) {
104  Vector<double> data_d(data); // Copy with type-conversion
105  mean_accumulator_.Row(comp_index).AddVec(wt, data_d);
106  if (flags_ & kGmmVariances) {
107  covariance_accumulator_[comp_index].AddVec2(wt, data_d);
108  }
109  }
110 }
111 
113  const VectorBase<BaseFloat> &data,
114  const VectorBase<BaseFloat> &gauss_posteriors) {
115  KALDI_ASSERT(gauss_posteriors.Dim() == NumGauss());
116  KALDI_ASSERT(data.Dim() == Dim());
117  Vector<double> data_d(data.Dim());
118  data_d.CopyFromVec(data);
119  Vector<double> post_d(gauss_posteriors.Dim());
120  post_d.CopyFromVec(gauss_posteriors);
121 
122  occupancy_.AddVec(1.0, post_d);
123  if (flags_ & (kGmmMeans|kGmmVariances)) { // mean stats.
124  if (static_cast<int32>(post_d.Norm(0.0)*2.0) > post_d.Dim()) {
125  // If we're not very sparse... note: zero-norm is number of
126  // nonzero elements.
127  mean_accumulator_.AddVecVec(1.0, post_d, data_d);
128  } else {
129  for (int32 i = 0; i < post_d.Dim(); i++)
130  if (post_d(i) != 0.0)
131  mean_accumulator_.Row(i).AddVec(post_d(i), data_d);
132  }
133  if (flags_ & kGmmVariances) {
134  SpMatrix<double> data_sq_d(data_d.Dim());
135  data_sq_d.AddVec2(1.0, data_d);
136  for (int32 mix = 0; mix < NumGauss(); mix++)
137  if (post_d(mix) != 0.0)
138  covariance_accumulator_[mix].AddSp(post_d(mix), data_sq_d);
139  }
140  }
141 }
142 
144  const VectorBase<BaseFloat> &data, BaseFloat frame_posterior) {
145  KALDI_ASSERT(gmm.NumGauss() == NumGauss());
146  KALDI_ASSERT(gmm.Dim() == Dim());
147 
148  Vector<BaseFloat> component_posterior(NumGauss());
149 
150  BaseFloat log_like = gmm.ComponentPosteriors(data, &component_posterior);
151  component_posterior.Scale(frame_posterior);
152 
153  AccumulateFromPosteriors(data, component_posterior);
154  return log_like;
155 }
156 
158  const VectorBase<BaseFloat> &data, BaseFloat frame_posterior) {
159  KALDI_ASSERT(gmm.NumGauss() == NumGauss());
160  KALDI_ASSERT(gmm.Dim() == Dim());
161 
162  Vector<BaseFloat> component_posterior(NumGauss());
163 
164  BaseFloat log_like = gmm.ComponentPosteriors(data, &component_posterior);
165  component_posterior.Scale(frame_posterior);
166 
167  AccumulateFromPosteriors(data, component_posterior);
168  return log_like;
169 }
170 
171 void AccumFullGmm::Read(std::istream &in_stream, bool binary, bool add) {
172  int32 dimension, num_components;
173  GmmFlagsType flags;
174  std::string token;
175 
176  ExpectToken(in_stream, binary, "<GMMACCS>");
177  ExpectToken(in_stream, binary, "<VECSIZE>");
178  ReadBasicType(in_stream, binary, &dimension);
179  ExpectToken(in_stream, binary, "<NUMCOMPONENTS>");
180  ReadBasicType(in_stream, binary, &num_components);
181  KALDI_ASSERT(dimension > 0 && num_components > 0);
182  ExpectToken(in_stream, binary, "<FLAGS>");
183  ReadBasicType(in_stream, binary, &flags);
184 
185  if (add) {
186  if ((NumGauss() != 0 || Dim() != 0 || Flags() != 0)) {
187  if (num_components != NumGauss() || dimension != Dim()
188  || flags != Flags())
189  KALDI_ERR << "MlEstimatediagGmm::Read, dimension or flags mismatch, "
190  << NumGauss() << ", " << Dim() << ", "
191  << GmmFlagsToString(Flags()) << " vs. " << num_components << ", "
192  << dimension << ", " << flags;
193  } else {
194  Resize(num_components, dimension, flags);
195  }
196  } else {
197  Resize(num_components, dimension, flags);
198  }
199 
200  // these are needed for demangling the variances.
201  Vector<double> tmp_occs;
202  Matrix<double> tmp_means;
203 
204  ReadToken(in_stream, binary, &token);
205  while (token != "</GMMACCS>") {
206  if (token == "<OCCUPANCY>") {
207  tmp_occs.Read(in_stream, binary, false);
208  if (!add) occupancy_.SetZero();
209  occupancy_.AddVec(1.0, tmp_occs);
210  } else if (token == "<MEANACCS>") {
211  tmp_means.Read(in_stream, binary, false);
212  if (!add) mean_accumulator_.SetZero();
213  mean_accumulator_.AddMat(1.0, tmp_means);
214  } else if (token == "<FULLVARACCS>") {
215  for (int32 i = 0; i < num_components; i++) {
216  SpMatrix<double> tmp_acc;
217  tmp_acc.Read(in_stream, binary, add);
218  if (tmp_occs(i) != 0) tmp_acc.AddVec2(1.0 / tmp_occs(i), tmp_means.Row(
219  i));
220  if (!add) covariance_accumulator_[i].SetZero();
221  covariance_accumulator_[i].AddSp(1.0, tmp_acc);
222  }
223  } else {
224  KALDI_ERR << "Unexpected token '" << token << "' in model file ";
225  }
226  ReadToken(in_stream, binary, &token);
227  }
228 }
229 
230 void AccumFullGmm::Write(std::ostream &out_stream, bool binary) const {
231  WriteToken(out_stream, binary, "<GMMACCS>");
232  WriteToken(out_stream, binary, "<VECSIZE>");
233  WriteBasicType(out_stream, binary, dim_);
234  WriteToken(out_stream, binary, "<NUMCOMPONENTS>");
235  WriteBasicType(out_stream, binary, num_comp_);
236  WriteToken(out_stream, binary, "<FLAGS>");
237  WriteBasicType(out_stream, binary, flags_);
238 
239  Vector<BaseFloat> occupancy_bf(occupancy_);
240  WriteToken(out_stream, binary, "<OCCUPANCY>");
241  occupancy_bf.Write(out_stream, binary);
242  Matrix<BaseFloat> mean_accumulator_bf(mean_accumulator_);
243  WriteToken(out_stream, binary, "<MEANACCS>");
244  mean_accumulator_bf.Write(out_stream, binary);
245 
246  if (num_comp_ != 0) KALDI_ASSERT(((flags_ & kGmmVariances) != 0 )
247  == (covariance_accumulator_.size() != 0)); // sanity check.
248  if (covariance_accumulator_.size() != 0) {
249  WriteToken(out_stream, binary, "<FULLVARACCS>");
250  for (int32 i = 0; i < num_comp_; i++) {
252  if (occupancy_(i) != 0) tmp_acc.AddVec2(-1.0 / occupancy_(i),
254  SpMatrix<float> tmp_acc_bf(tmp_acc);
255  tmp_acc_bf.Write(out_stream, binary);
256  }
257  }
258  WriteToken(out_stream, binary, "</GMMACCS>");
259 }
260 
261 BaseFloat MlObjective(const FullGmm &gmm, const AccumFullGmm &fullgmm_acc) {
262  GmmFlagsType flags = fullgmm_acc.Flags();
263  Vector<BaseFloat> occ_bf(fullgmm_acc.occupancy());
264  Matrix<BaseFloat> mean_accs_bf(fullgmm_acc.mean_accumulator());
265  SpMatrix<BaseFloat> covar_accs_bf(gmm.Dim());
266 
267  BaseFloat obj = VecVec(occ_bf, gmm.gconsts());
268 
269  if (flags & kGmmMeans)
270  obj += TraceMatMat(mean_accs_bf, gmm.means_invcovars(), kTrans);
271 
272  if (flags & kGmmVariances) {
273  for (int32 i = 0; i < gmm.NumGauss(); i++) {
274  covar_accs_bf.CopyFromSp(fullgmm_acc.covariance_accumulator()[i]);
275  obj -= 0.5 * TraceSpSp(covar_accs_bf, gmm.inv_covars()[i]);
276  }
277  }
278 
279  return obj;
280 }
281 
283  const AccumFullGmm &fullgmm_acc,
284  GmmFlagsType flags,
285  FullGmm *gmm,
286  BaseFloat *obj_change_out,
287  BaseFloat *count_out) {
288  KALDI_ASSERT(gmm != NULL);
289 
290  if (flags & ~fullgmm_acc.Flags())
291  KALDI_ERR << "Flags in argument do not match the active accumulators";
292 
293  gmm->ComputeGconsts();
294  BaseFloat obj_old = MlObjective(*gmm, fullgmm_acc);
295 
296  // Korbinian: I removed checks that validate if the referenced gmm matches
297  // the accumulator, as this should be responsibility of the caller.
298  // Furthermore, the re-estimation of the normal representation is done
299  // regardless of the flags, but the transfer to the natural form is
300  // done with respect to the flags.
301 
302  int32 num_gauss = gmm->NumGauss();
303  double occ_sum = fullgmm_acc.occupancy().Sum();
304 
305  int32 tot_floored = 0, gauss_floored = 0;
306 
307  // allocate the gmm in normal representation
308  FullGmmNormal ngmm(*gmm);
309 
310  std::vector<int32> to_remove;
311  for (int32 i = 0; i < num_gauss; i++) {
312  double occ = fullgmm_acc.occupancy()(i);
313  double prob;
314  if (occ_sum > 0.0)
315  prob = occ / occ_sum;
316  else
317  prob = 1.0 / num_gauss;
318 
319  if (occ > static_cast<double> (config.min_gaussian_occupancy)
320  && prob > static_cast<double> (config.min_gaussian_weight)) {
321 
322  ngmm.weights_(i) = prob;
323 
324  // copy old mean for later normalizations
325  Vector<double> oldmean(ngmm.means_.Row(i));
326 
327  // update mean, then variance, as far as there are accumulators
328  if (fullgmm_acc.Flags() & (kGmmMeans|kGmmVariances)) {
329  Vector<double> mean(fullgmm_acc.mean_accumulator().Row(i));
330  mean.Scale(1.0 / occ);
331 
332  // transfer to estimate
333  ngmm.means_.CopyRowFromVec(mean, i);
334  }
335 
336  if (fullgmm_acc.Flags() & kGmmVariances) {
337  KALDI_ASSERT(fullgmm_acc.Flags() & kGmmMeans);
338  SpMatrix<double> covar(fullgmm_acc.covariance_accumulator()[i]);
339  covar.Scale(1.0 / occ);
340  covar.AddVec2(-1.0, ngmm.means_.Row(i)); // subtract squared means.
341  // if we intend to only update the variances, we need to compensate by
342  // adding the difference between the new and old mean
343  if (!(flags & kGmmMeans)) {
344  oldmean.AddVec(-1.0, ngmm.means_.Row(i));
345  covar.AddVec2(1.0, oldmean);
346  }
347 
348  // Now flooring etc. of variance's eigenvalues.
349  BaseFloat floor = std::max(static_cast<double>(config.variance_floor),
350  covar.MaxAbsEig() / config.max_condition);
351 
352  int32 floored = covar.ApplyFloor(floor);
353 
354  if (floored) {
355  tot_floored += floored;
356  gauss_floored++;
357  }
358 
359  // transfer to estimate
360  ngmm.vars_[i].CopyFromSp(covar);
361  }
362  } else { // Insufficient occupancy
363  if (config.remove_low_count_gaussians &&
364  static_cast<int32>(to_remove.size()) < num_gauss-1) {
365  KALDI_WARN << "Too little data - removing Gaussian (weight "
366  << std::fixed << prob
367  << ", occupation count " << std::fixed << fullgmm_acc.occupancy()(i)
368  << ", vector size " << gmm->Dim() << ")";
369  to_remove.push_back(i);
370  } else {
371  KALDI_WARN << "Gaussian has too little data but not removing it because"
372  << (config.remove_low_count_gaussians ?
373  " it is the last Gaussian: i = "
374  : " remove-low-count-gaussians == false: i = ") << i
375  << ", occ = " << fullgmm_acc.occupancy()(i) << ", weight = " << prob;
376  ngmm.weights_(i) =
377  std::max(prob, static_cast<double>(config.min_gaussian_weight));
378  }
379  }
380  }
381 
382  // copy to natural representation according to flags
383  ngmm.CopyToFullGmm(gmm, flags);
384 
385  gmm->ComputeGconsts();
386  BaseFloat obj_new = MlObjective(*gmm, fullgmm_acc);
387 
388  if (obj_change_out)
389  *obj_change_out = obj_new - obj_old;
390 
391  if (count_out)
392  *count_out = occ_sum;
393 
394  if (to_remove.size() > 0) {
395  gmm->RemoveComponents(to_remove, true /* renorm weights */);
396  gmm->ComputeGconsts();
397  }
398 
399  if (tot_floored > 0)
400  KALDI_WARN << tot_floored << " variances floored in " << gauss_floored
401  << " Gaussians.";
402 
403 }
404 
405 } // End namespace kaldi
void Write(std::ostream &out_stream, bool binary) const
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
int32 Dim() const
Returns the dimensionality of the Gaussian mean vectors.
Definition: diag-gmm.h:74
GmmFlagsType AugmentGmmFlags(GmmFlagsType f)
Returns "augmented" version of flags: e.g.
Definition: model-common.cc:52
void Write(std::ostream &out, bool binary) const
write to stream.
const std::vector< SpMatrix< BaseFloat > > & inv_covars() const
Definition: full-gmm.h:146
int32 NumGauss() const
Returns the number of mixture components.
Definition: mle-full-gmm.h:97
void Scale(Real c)
const std::vector< SpMatrix< double > > & covariance_accumulator() const
Definition: mle-full-gmm.h:129
void Read(std::istream &in, bool binary, bool add=false)
void Write(std::ostream &out, bool binary) const
std::vector< SpMatrix< double > > covariance_accumulator_
Definition: mle-full-gmm.h:138
BaseFloat ComponentPosteriors(const VectorBase< BaseFloat > &data, VectorBase< BaseFloat > *posterior) const
Computes the posterior probabilities of all Gaussian components given a data point.
Definition: full-gmm.cc:719
int32 Dim() const
Returns the dimensionality of the Gaussian mean vectors.
Definition: full-gmm.h:60
Definition for Gaussian Mixture Model with full covariances in normal mode: where the parameters are ...
Configuration variables like variance floor, minimum occupancy, etc.
Definition: mle-full-gmm.h:38
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...
Definition: io-funcs-inl.h:55
void ResizeVarAccumulator(int32 num_comp, int32 dim)
Definition: mle-full-gmm.cc:53
BaseFloat AccumulateFromDiag(const DiagGmm &gmm, const VectorBase< BaseFloat > &data, BaseFloat frame_posterior)
Accumulate for all components given a diagonal-covariance GMM.
int32 ComputeGconsts()
Sets the gconsts.
Definition: full-gmm.cc:92
Definition for Gaussian Mixture Model with full covariances.
Definition: full-gmm.h:40
void Write(std::ostream &Out, bool binary) const
Writes to C++ stream (option to write in binary).
BaseFloat MlObjective(const DiagGmm &gmm, const AccumDiagGmm &diag_gmm_acc)
Calc using the DiagGMM exponential form.
void AddMat(const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transA=kNoTrans)
*this += alpha * M [or M^T]
Vector< double > occupancy_
Definition: mle-full-gmm.h:136
int32 Dim() const
Returns the dimensionality of the feature vectors.
Definition: mle-full-gmm.h:99
kaldi::int32 int32
void ReadToken(std::istream &is, bool binary, std::string *str)
ReadToken gets the next token and puts it in str (exception on failure).
Definition: io-funcs.cc:154
uint16 GmmFlagsType
Bitwise OR of the above flags.
Definition: model-common.h:35
void SetZero(GmmFlagsType flags)
Definition: mle-full-gmm.cc:63
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
GmmFlagsType Flags() const
Accessors.
Definition: mle-full-gmm.h:126
const Vector< double > & occupancy() const
Definition: mle-full-gmm.h:127
BaseFloat variance_floor
Floor on eigenvalues of covariance matrices.
Definition: mle-full-gmm.h:44
GmmFlagsType flags_
Definition: mle-full-gmm.h:134
const Vector< BaseFloat > & gconsts() const
Const accessors.
Definition: full-gmm.h:143
std::vector< SpMatrix< double > > vars_
covariances
void Resize(int32 num_components, int32 dim, GmmFlagsType flags)
Allocates memory for accumulators.
Definition: mle-full-gmm.cc:37
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
void AddVec2(const Real alpha, const VectorBase< OtherReal > &v)
rank-one update, this <– this + alpha v v&#39;
Definition: sp-matrix.cc:946
void Read(std::istream &in, bool binary, bool add=false)
read from stream.
BaseFloat ComponentPosteriors(const VectorBase< BaseFloat > &data, Vector< BaseFloat > *posteriors) const
Computes the posterior probabilities of all Gaussian components given a data point.
Definition: diag-gmm.cc:601
float BaseFloat
Definition: kaldi-types.h:29
Vector< double > weights_
weights (not log).
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
void AccumulateFromPosteriors(const VectorBase< BaseFloat > &data, const VectorBase< BaseFloat > &gauss_posteriors)
Accumulate for all components, given the posteriors.
BaseFloat min_gaussian_weight
Minimum weight below which a Gaussian is removed.
Definition: mle-full-gmm.h:40
void RemoveComponents(const std::vector< int32 > &gauss, bool renorm_weights)
Removes multiple components from model; "gauss" must not have dups.
Definition: full-gmm.cc:745
void Scale(Real alpha)
Multiply each element with a scalar value.
void ExpectToken(std::istream &is, bool binary, const char *token)
ExpectToken tries to read in the given token, and throws an exception on failure. ...
Definition: io-funcs.cc:191
void MleFullGmmUpdate(const MleFullGmmOptions &config, const AccumFullGmm &fullgmm_acc, GmmFlagsType flags, FullGmm *gmm, BaseFloat *obj_change_out, BaseFloat *count_out)
for computing the maximum-likelihood estimates of the parameters of a Gaussian mixture model...
#define KALDI_ERR
Definition: kaldi-error.h:147
double TraceSpSp(const SpMatrix< double > &A, const SpMatrix< double > &B)
Definition: sp-matrix.cc:326
Class for computing the maximum-likelihood estimates of the parameters of a Gaussian mixture model...
Definition: mle-full-gmm.h:74
#define KALDI_WARN
Definition: kaldi-error.h:150
Real TraceMatMat(const MatrixBase< Real > &A, const MatrixBase< Real > &B, MatrixTransposeType trans)
We need to declare this here as it will be a friend function.
void CopyToFullGmm(FullGmm *fullgmm, GmmFlagsType flags=kGmmAll)
Copies to FullGmm.
int32 NumGauss() const
Returns the number of mixture components in the GMM.
Definition: full-gmm.h:58
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
Definition: io-funcs.cc:134
int32 NumGauss() const
Returns the number of mixture components in the GMM.
Definition: diag-gmm.h:72
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
void SetZero()
Sets matrix to zero.
void Scale(Real alpha)
Multiplies all elements by this constant.
const Matrix< double > & mean_accumulator() const
Definition: mle-full-gmm.h:128
Real Sum() const
Returns sum of the elements.
BaseFloat min_gaussian_occupancy
Minimum occupancy count below which a Gaussian is removed.
Definition: mle-full-gmm.h:42
void Read(std::istream &in_stream, bool binary, bool add)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void AddVecVec(const Real alpha, const VectorBase< OtherReal > &a, const VectorBase< OtherReal > &b)
*this += alpha * a * b^T
void CopyRowFromVec(const VectorBase< Real > &v, const MatrixIndexT row)
Copy vector into specific row of matrix.
Definition for Gaussian Mixture Model with diagonal covariances.
Definition: diag-gmm.h:42
std::string GmmFlagsToString(GmmFlagsType flags)
Convert GMM flags to string.
Definition: model-common.cc:43
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...
Definition: io-funcs-inl.h:34
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).
BaseFloat AccumulateFromFull(const FullGmm &gmm, const VectorBase< BaseFloat > &data, BaseFloat frame_posterior)
Accumulate for all components given a full-covariance GMM.
BaseFloat max_condition
Maximum condition number of covariance matrices (apply floor to eigenvalues if they pass this)...
Definition: mle-full-gmm.h:47
const Matrix< BaseFloat > & means_invcovars() const
Definition: full-gmm.h:145
Provides a vector abstraction class.
Definition: kaldi-vector.h:41
void SetZero()
Set vector to all zeros.
Matrix< double > means_
Means.
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37
void AddVec(const Real alpha, const VectorBase< OtherReal > &v)
Add vector : *this = *this + alpha * rv (with casting between floats and doubles) ...
Matrix< double > mean_accumulator_
Definition: mle-full-gmm.h:137
void Read(std::istream &in, bool binary, bool add=false)
Read function using C++ streams.
void Scale(BaseFloat f, GmmFlagsType flags)
Definition: mle-full-gmm.cc:79
void AccumulateForComponent(const VectorBase< BaseFloat > &data, int32 comp_index, BaseFloat weight)
Accumulate for a single component, given the posterior.
Definition: mle-full-gmm.cc:96