30 if (num_xforms == 0) {
40 vector< Matrix<BaseFloat> >::iterator xform_itr =
xform_matrices_.begin(),
42 for (; xform_itr != xform_itr_end; ++xform_itr) {
43 xform_itr->Resize(dim, dim+1);
50 vector< Matrix<BaseFloat> >::iterator xform_itr =
xform_matrices_.begin(),
52 for (; xform_itr != xform_itr_end; ++xform_itr) {
63 bclass_index < num_bclasses; ++bclass_index) {
67 const vector< pair<int32, int32> > &bclass =
69 for (vector< pair<int32, int32> >::const_iterator itr = bclass.begin(),
70 end = bclass.end(); itr != end; ++itr) {
73 extended_mean(
dim_) = 1.0;
94 extended_mean(
dim_) = 1.0;
96 for (
int32 gauss_index = 0; gauss_index < num_gauss; gauss_index++) {
99 if (xform_index > -1) {
121 vector< Matrix<BaseFloat> >::const_iterator xform_itr =
123 for (; xform_itr != xform_itr_end; ++xform_itr) {
125 xform_itr->Write(out, binary);
143 vector< Matrix<BaseFloat> >::iterator xform_itr =
xform_matrices_.begin(),
145 for (; xform_itr != xform_itr_end; ++xform_itr) {
147 xform_itr->Read(in, binary);
148 KALDI_ASSERT(xform_itr->NumRows() == (xform_itr->NumCols() - 1)
149 && xform_itr->NumRows() ==
dim_);
160 if (num_bclass == 0) {
162 baseclass_stats_.clear();
163 num_baseclasses_ = 0;
167 num_baseclasses_ = num_bclass;
169 baseclass_stats_.resize(num_baseclasses_);
170 for (vector<AffineXformStats*>::iterator it = baseclass_stats_.begin(),
171 end = baseclass_stats_.end(); it != end; ++it) {
179 for (vector<AffineXformStats*>::iterator it = baseclass_stats_.begin(),
180 end = baseclass_stats_.end(); it != end; ++it) {
192 posterior.
Scale(weight);
200 for (
int32 m = 0; m < num_comp; m++) {
208 extended_mean(
dim_) = 1.0;
210 mean_scatter.
AddVec2(1.0, extended_mean);
212 baseclass_stats_[bclass]->beta_ += posterior_d(m);
213 baseclass_stats_[bclass]->K_.AddVecVec(posterior_d(m), inv_var_x,
215 vector< SpMatrix<double> > &G = baseclass_stats_[bclass]->G_;
217 G[
d].AddSp((posterior_d(m) * pdf.
inv_vars()(m,
d)), mean_scatter);
230 double weight_d =
static_cast<double>(weight);
239 extended_mean(
dim_) = 1.0;
241 mean_scatter.
AddVec2(1.0, extended_mean);
243 baseclass_stats_[bclass]->beta_ += weight_d;
244 baseclass_stats_[bclass]->K_.AddVecVec(weight_d, inv_var_x, extended_mean);
245 vector< SpMatrix<double> > &G = baseclass_stats_[bclass]->G_;
247 G[
d].AddSp((weight_d * pdf.
inv_vars()(gauss_index,
d)), mean_scatter);
257 vector<AffineXformStats*>::const_iterator itr = baseclass_stats_.begin(),
258 end = baseclass_stats_.end();
259 for ( ; itr != end; ++itr)
260 (*itr)->Write(out, binary);
271 baseclass_stats_.resize(num_baseclasses_);
273 vector<AffineXformStats*>::iterator itr = baseclass_stats_.begin(),
274 end = baseclass_stats_.end();
275 for ( ; itr != end; ++itr) {
278 (*itr)->Read(in, binary, add);
286 int32 dim = G.size();
289 if (G[
d].Cond() > 1.0e+9) {
290 KALDI_WARN <<
"Dim " <<
d <<
": Badly conditioned stats. Setting MLLR " 291 <<
"transform to unit.";
303 tmp_out.
Row(d).AddSpVec(1.0, inv_g, K.
Row(d), 0.0);
317 obj -= 0.5 *
VecVec(xform_row_g, xform_d.
Row(
d));
330 vector<AffineXformStats*> regclass_stats;
331 vector<int32> base2regclass;
333 &base2regclass, ®class_stats);
337 out_mllr->
Init(regclass_stats.size(),
dim_);
338 for (
int32 rclass_index = 0, num_rclass = regclass_stats.size();
339 rclass_index < num_rclass; ++rclass_index) {
343 *(regclass_stats[rclass_index]));
345 regclass_stats[rclass_index]->G_, &xform_mat);
348 *(regclass_stats[rclass_index]));
349 KALDI_LOG <<
"MLLR: regclass " << (rclass_index)
350 <<
": Objective function impr per frame is " 351 << ((obj_new - obj_old)/regclass_stats[rclass_index]->beta_)
352 <<
" over " << regclass_stats[rclass_index]->beta_
354 KALDI_ASSERT(obj_new >= obj_old - (std::abs(obj_new)+std::abs(obj_old))*1.0e-05);
355 tot_t += regclass_stats[rclass_index]->beta_;
356 tot_auxf_impr += obj_new - obj_old;
364 out_mllr->
Init(num_baseclasses_,
dim_);
365 vector<int32> base2xforms(num_baseclasses_, -1);
366 for (
int32 bclass_index = 0; bclass_index < num_baseclasses_;
368 if (baseclass_stats_[bclass_index]->beta_ > opts.
min_count) {
369 base2xforms[bclass_index] = bclass_index;
372 *(baseclass_stats_[bclass_index]));
374 baseclass_stats_[bclass_index]->G_, &xform_mat);
377 *(baseclass_stats_[bclass_index]));
378 KALDI_LOG <<
"MLLR: base-class " << (bclass_index)
379 <<
": Auxiliary function impr per frame is " 380 << ((obj_new-obj_old)/baseclass_stats_[bclass_index]->beta_);
381 KALDI_ASSERT(obj_new >= obj_old - (std::abs(obj_new)+std::abs(obj_old))*1.0e-05);
382 tot_t += baseclass_stats_[bclass_index]->beta_;
383 tot_auxf_impr += obj_new - obj_old;
385 KALDI_WARN <<
"For baseclass " << (bclass_index) <<
" count = " 386 << (baseclass_stats_[bclass_index]->beta_) <<
" < " 387 << opts.
min_count <<
": not updating MLLR";
388 tot_t += baseclass_stats_[bclass_index]->beta_;
393 if (auxf_impr != NULL) *auxf_impr = tot_auxf_impr;
394 if (t != NULL) *t = tot_t;
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void AccumulateForGaussian(const RegressionTree ®tree, const AmDiagGmm &am, const VectorBase< BaseFloat > &data, int32 pdf_index, int32 gauss_index, BaseFloat weight)
Accumulate stats for a single Gaussian component in the model.
int32 Gauss2BaseclassId(size_t pdf_id, size_t gauss_id) const
void DeletePointers(std::vector< A *> *v)
Deletes any non-NULL pointers in the vector v, and sets the corresponding entries of v to NULL...
An MLLR mean transformation is an affine transformation of Gaussian means.
std::vector< Matrix< BaseFloat > > xform_matrices_
Transform matrices: size() = num_xforms_.
void Init(int32 num_xforms, int32 dim)
Allocates memory for transform matrix & bias vector.
int32 dim_
Dimension of feature vectors.
int32 ComputeGconsts()
Sets the gconsts for all the PDFs.
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
const std::vector< std::pair< int32, int32 > > & GetBaseclass(int32 bclass) const
Base class which provides matrix operations not involving resizing or allocation. ...
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 TransformModel(const RegressionTree ®tree, AmDiagGmm *am)
Apply the transform(s) to all the Gaussian means in the model.
Configuration variables for FMLLR transforms.
void GetComponentMean(int32 gauss, VectorBase< Real > *out) const
Accessor for single component mean.
bool use_regtree
If 'true', find transforms to generate using regression tree.
BaseFloat min_count
Minimum occupancy for computing a transform.
void set_bclass2xforms(const std::vector< int32 > &in)
std::vector< int32 > bclass2xforms_
For each baseclass index of which transform to use; -1 => no xform.
void AddSpVec(const Real alpha, const SpMatrix< Real > &M, const VectorBase< Real > &v, const Real beta)
Add symmetric positive definite matrix times vector: this <– beta*this + alpha*M*v.
void Init(int32 num_bclass, int32 dim)
void SetGaussianMean(int32 pdf_index, int32 gauss_index, const VectorBase< BaseFloat > &in)
Mutators.
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
void SetUnit()
Sets to zero, except ones along diagonal [for non-square matrices too].
bool GatherStats(const std::vector< AffineXformStats *> &stats_in, double min_count, std::vector< int32 > *regclasses_out, std::vector< AffineXformStats *> *stats_out) const
Parses the regression tree and finds the nodes whose occupancies (read from stats_in) are greater tha...
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
void Read(std::istream &in_stream, bool binary, bool add)
void AddVec2(const Real alpha, const VectorBase< OtherReal > &v)
rank-one update, this <– this + alpha v v'
BaseFloat ComponentPosteriors(const VectorBase< BaseFloat > &data, Vector< BaseFloat > *posteriors) const
Computes the posterior probabilities of all Gaussian components given a data point.
int32 NumBaseclasses() const
Accessors (const)
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
void ReadIntegerVector(std::istream &is, bool binary, std::vector< T > *v)
Function for reading STL vector of integer types.
void MulElements(const VectorBase< Real > &v)
Multiply element-by-element by another vector.
void SetParameters(const MatrixBase< BaseFloat > &mat, int32 regclass)
Mutators.
void ExpectToken(std::istream &is, bool binary, const char *token)
ExpectToken tries to read in the given token, and throws an exception on failure. ...
A regression tree is a clustering of Gaussian densities in an acoustic model, such that the group of ...
void SetUnit()
Initialize transform matrix to identity and bias vector to zero.
static void ComputeMllrMatrix(const Matrix< double > &K, const vector< SpMatrix< double > > &G, Matrix< BaseFloat > *out)
void Read(std::istream &in_stream, bool binary)
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 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.
void AddMatVec(const Real alpha, const MatrixBase< Real > &M, const MatrixTransposeType trans, const VectorBase< Real > &v, const Real beta)
Add matrix times vector : this <– beta*this + alpha*M*v.
void GetTransformedMeans(const RegressionTree ®tree, const AmDiagGmm &am, int32 pdf_index, MatrixBase< BaseFloat > *out) const
Get all the transformed means for a given pdf.
DiagGmm & GetPdf(int32 pdf_index)
Accessors.
int32 num_xforms_
Number of transforms == xform_matrices_.size()
A class representing a vector.
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void GetGaussianMean(int32 pdf_index, int32 gauss, VectorBase< BaseFloat > *out) const
void Write(std::ostream &out_stream, bool binary) const
Definition for Gaussian Mixture Model with diagonal covariances.
void WriteIntegerVector(std::ostream &os, bool binary, const std::vector< T > &v)
Function for writing STL vectors of integer types.
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...
static BaseFloat MllrAuxFunction(const Matrix< BaseFloat > &xform, const AffineXformStats &stats)
Provides a vector abstraction class.
BaseFloat AccumulateForGmm(const RegressionTree ®tree, const AmDiagGmm &am, const VectorBase< BaseFloat > &data, int32 pdf_index, BaseFloat weight)
Accumulate stats for a single GMM in the model; returns log likelihood.
void Update(const RegressionTree ®tree, const RegtreeMllrOptions &opts, RegtreeMllrDiagGmm *out_mllr, BaseFloat *auxf_impr, BaseFloat *t) const
void Invert(Real *logdet=NULL, Real *det_sign=NULL, bool inverse_needed=true)
matrix inverse.
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Sub-matrix representation.
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
void Write(std::ostream &out_stream, bool binary) const
const Matrix< BaseFloat > & inv_vars() const