mle-full-gmm.h
Go to the documentation of this file.
1 // gmm/mle-full-gmm.h
2 
3 // Copyright 2009-2011 Jan Silovsky; Saarland University;
4 // Microsoft Corporation;
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 #ifndef KALDI_GMM_MLE_FULL_GMM_H_
23 #define KALDI_GMM_MLE_FULL_GMM_H_
24 
25 #include <vector>
26 
27 #include "gmm/model-common.h"
28 #include "gmm/full-gmm.h"
29 #include "gmm/full-gmm-normal.h"
30 #include "gmm/mle-diag-gmm.h" // for AugmentGmmFlags()
31 
32 namespace kaldi {
33 
50  min_gaussian_weight = 1.0e-05;
51  min_gaussian_occupancy = 100.0;
52  variance_floor = 0.001;
53  max_condition = 1.0e+04;
54  remove_low_count_gaussians = true;
55  }
56  void Register(OptionsItf *opts) {
57  std::string module = "MleFullGmmOptions: ";
58  opts->Register("min-gaussian-weight", &min_gaussian_weight,
59  module+"Min Gaussian weight before we remove it.");
60  opts->Register("min-gaussian-occupancy", &min_gaussian_occupancy,
61  module+"Minimum count before we remove a Gaussian.");
62  opts->Register("variance-floor", &variance_floor,
63  module+"Minimum eigenvalue of covariance matrix.");
64  opts->Register("max-condition", &max_condition,
65  module+"Maximum condition number of covariance matrix (use it to floor).");
66  opts->Register("remove-low-count-gaussians", &remove_low_count_gaussians,
67  module+"If true, remove Gaussians that fall below the floors.");
68  }
69 };
70 
74 class AccumFullGmm {
75  public:
76  AccumFullGmm(): dim_(0), num_comp_(0), flags_(0) { }
77  AccumFullGmm(int32 num_comp, int32 dim, GmmFlagsType flags):
78  dim_(0), num_comp_(0), flags_(0) {
79  Resize(num_comp, dim, flags);
80  }
81  explicit AccumFullGmm(const FullGmm &gmm, GmmFlagsType flags) {
82  Resize(gmm, flags);
83  }
84  // provide copy constructor.
85  explicit AccumFullGmm(const AccumFullGmm &other);
86 
87  void Read(std::istream &in_stream, bool binary, bool add);
88  void Write(std::ostream &out_stream, bool binary) const;
89 
91  void Resize(int32 num_components, int32 dim, GmmFlagsType flags);
93  void Resize(const FullGmm &gmm, GmmFlagsType flags);
94 
95  void ResizeVarAccumulator(int32 num_comp, int32 dim);
97  int32 NumGauss() const { return num_comp_; }
99  int32 Dim() const { return dim_; }
100 
101  void SetZero(GmmFlagsType flags);
102 
103  void Scale(BaseFloat f, GmmFlagsType flags); // scale stats.
104 
106  void AccumulateForComponent(const VectorBase<BaseFloat> &data,
107  int32 comp_index, BaseFloat weight);
108 
110  void AccumulateFromPosteriors(const VectorBase<BaseFloat> &data,
111  const VectorBase<BaseFloat> &gauss_posteriors);
112 
115  BaseFloat AccumulateFromFull(const FullGmm &gmm,
116  const VectorBase<BaseFloat> &data,
117  BaseFloat frame_posterior);
118 
121  BaseFloat AccumulateFromDiag(const DiagGmm &gmm,
122  const VectorBase<BaseFloat> &data,
123  BaseFloat frame_posterior);
124 
126  GmmFlagsType Flags() const { return flags_; }
127  const Vector<double> &occupancy() const { return occupancy_; }
128  const Matrix<double> &mean_accumulator() const { return mean_accumulator_; }
129  const std::vector<SpMatrix<double> > &covariance_accumulator() const { return covariance_accumulator_; }
130 
131  private:
135 
138  std::vector<SpMatrix<double> > covariance_accumulator_;
139 };
140 
141 inline void AccumFullGmm::Resize(const FullGmm &gmm, GmmFlagsType flags) {
142  Resize(gmm.NumGauss(), gmm.Dim(), flags);
143 }
144 
147 void MleFullGmmUpdate(const MleFullGmmOptions &config,
148  const AccumFullGmm &fullgmm_acc,
149  GmmFlagsType flags,
150  FullGmm *gmm,
151  BaseFloat *obj_change_out,
152  BaseFloat *count_out);
153 
155 BaseFloat MlObjective(const FullGmm &gmm,
156  const AccumFullGmm &fullgmm_acc);
157 
158 } // End namespace kaldi
159 
160 #endif // KALDI_GMM_MLE_FULL_GMM_H_
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
AccumFullGmm(int32 num_comp, int32 dim, GmmFlagsType flags)
Definition: mle-full-gmm.h:77
int32 NumGauss() const
Returns the number of mixture components.
Definition: mle-full-gmm.h:97
const std::vector< SpMatrix< double > > & covariance_accumulator() const
Definition: mle-full-gmm.h:129
std::vector< SpMatrix< double > > covariance_accumulator_
Definition: mle-full-gmm.h:138
int32 Dim() const
Returns the dimensionality of the Gaussian mean vectors.
Definition: full-gmm.h:60
Configuration variables like variance floor, minimum occupancy, etc.
Definition: mle-full-gmm.h:38
Definition for Gaussian Mixture Model with full covariances.
Definition: full-gmm.h:40
BaseFloat MlObjective(const DiagGmm &gmm, const AccumDiagGmm &diag_gmm_acc)
Calc using the DiagGMM exponential form.
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
uint16 GmmFlagsType
Bitwise OR of the above flags.
Definition: model-common.h:35
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
virtual void Register(const std::string &name, bool *ptr, const std::string &doc)=0
void Resize(int32 num_components, int32 dim, GmmFlagsType flags)
Allocates memory for accumulators.
Definition: mle-full-gmm.cc:37
BaseFloat min_gaussian_weight
Minimum weight below which a Gaussian is removed.
Definition: mle-full-gmm.h:40
void Register(OptionsItf *opts)
Definition: mle-full-gmm.h:56
AccumFullGmm(const FullGmm &gmm, GmmFlagsType flags)
Definition: mle-full-gmm.h:81
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...
Class for computing the maximum-likelihood estimates of the parameters of a Gaussian mixture model...
Definition: mle-full-gmm.h:74
int32 NumGauss() const
Returns the number of mixture components in the GMM.
Definition: full-gmm.h:58
const Matrix< double > & mean_accumulator() const
Definition: mle-full-gmm.h:128
BaseFloat min_gaussian_occupancy
Minimum occupancy count below which a Gaussian is removed.
Definition: mle-full-gmm.h:42
Definition for Gaussian Mixture Model with diagonal covariances.
Definition: diag-gmm.h:42
BaseFloat max_condition
Maximum condition number of covariance matrices (apply floor to eigenvalues if they pass this)...
Definition: mle-full-gmm.h:47
Provides a vector abstraction class.
Definition: kaldi-vector.h:41
Matrix< double > mean_accumulator_
Definition: mle-full-gmm.h:137