AmSgmm2 Class Reference

Class for definition of the subspace Gmm acoustic model. More...

#include <am-sgmm2.h>

Collaboration diagram for AmSgmm2:

Public Member Functions

 AmSgmm2 ()
 
void Read (std::istream &is, bool binary)
 
void Write (std::ostream &os, bool binary, SgmmWriteFlagsType write_params) const
 
void Check (bool show_properties=true)
 Checks the various components for correct sizes. More...
 
void InitializeFromFullGmm (const FullGmm &gmm, const std::vector< int32 > &pdf2group, int32 phn_subspace_dim, int32 spk_subspace_dim, bool speaker_dependent_weights, BaseFloat self_weight)
 Initializes the SGMM parameters from a full-covariance UBM. More...
 
void CopyGlobalsInitVecs (const AmSgmm2 &other, const std::vector< int32 > &pdf2group, BaseFloat self_weight)
 Copies the global parameters from the supplied model, but sets the state vectors to zero. More...
 
void CopyFromSgmm2 (const AmSgmm2 &other, bool copy_normalizers, bool copy_weights)
 Used to copy models (useful in update) More...
 
BaseFloat GaussianSelection (const Sgmm2GselectConfig &config, const VectorBase< BaseFloat > &data, std::vector< int32 > *gselect) const
 Computes the top-scoring Gaussian indices (used for pruning of later stages of computation). More...
 
void ComputePerFrameVars (const VectorBase< BaseFloat > &data, const std::vector< int32 > &gselect, const Sgmm2PerSpkDerivedVars &spk_vars, Sgmm2PerFrameDerivedVars *per_frame_vars) const
 This needs to be called with each new frame of data, prior to accumulation or likelihood evaluation: it computes various pre-computed quantities. More...
 
void ComputePerSpkDerivedVars (Sgmm2PerSpkDerivedVars *vars) const
 Computes the per-speaker derived vars; assumes vars->v_s is already set up. More...
 
BaseFloat LogLikelihood (const Sgmm2PerFrameDerivedVars &per_frame_vars, int32 j2, Sgmm2LikelihoodCache *cache, Sgmm2PerSpkDerivedVars *spk_vars, BaseFloat log_prune=0.0) const
 This does a likelihood computation for a given state using the pre-selected Gaussian components (in per_frame_vars). More...
 
BaseFloat ComponentPosteriors (const Sgmm2PerFrameDerivedVars &per_frame_vars, int32 j2, Sgmm2PerSpkDerivedVars *spk_vars, Matrix< BaseFloat > *post) const
 Similar to LogLikelihood() function above, but also computes the posterior probabilities for the pre-selected Gaussian components and all substates. More...
 
void SplitSubstates (const Vector< BaseFloat > &state_occupancies, const Sgmm2SplitSubstatesConfig &config)
 Increases the total number of substates based on the state occupancies. More...
 
void IncreasePhoneSpaceDim (int32 target_dim, const Matrix< BaseFloat > &norm_xform)
 Functions for increasing the phonetic and speaker space dimensions. More...
 
void IncreaseSpkSpaceDim (int32 target_dim, const Matrix< BaseFloat > &norm_xform, bool speaker_dependent_weights)
 Increase the subspace dimension for speakers. More...
 
void ComputeDerivedVars ()
 Computes (and initializes if necessary) derived vars... More...
 
void ComputeNormalizers ()
 Computes the data-independent terms in the log-likelihood computation for each Gaussian component and all substates. More...
 
void ComputeWeights ()
 Computes the weights w_jmi_, which is needed for likelihood evaluation with SSGMMs. More...
 
void ComputeFmllrPreXform (const Vector< BaseFloat > &pdf_occs, Matrix< BaseFloat > *xform, Matrix< BaseFloat > *inv_xform, Vector< BaseFloat > *diag_mean_scatter) const
 Computes the LDA-like pre-transform and its inverse as well as the eigenvalues of the scatter of the means used in FMLLR estimation. More...
 
int32 NumPdfs () const
 Various model dimensions. More...
 
int32 NumGroups () const
 
int32 Pdf2Group (int32 j2) const
 
int32 NumSubstatesForPdf (int32 j2) const
 
int32 NumSubstatesForGroup (int32 j1) const
 
int32 NumGauss () const
 
int32 PhoneSpaceDim () const
 
int32 SpkSpaceDim () const
 
int32 FeatureDim () const
 
bool HasSpeakerDependentWeights () const
 True if doing SSGMM. More...
 
bool HasSpeakerSpace () const
 
void RemoveSpeakerSpace ()
 
BaseFloat GetDjms (int32 j1, int32 m, Sgmm2PerSpkDerivedVars *spk_vars) const
 
const FullGmmfull_ubm () const
 Accessors. More...
 
const DiagGmmdiag_ubm () const
 
template<typename Real >
void GetInvCovars (int32 gauss_index, SpMatrix< Real > *out) const
 Templated accessors (used to accumulate in different precision) More...
 
template<typename Real >
void GetSubstateMean (int32 j1, int32 m, int32 i, VectorBase< Real > *mean_out) const
 
template<typename Real >
void GetNtransSigmaInv (std::vector< Matrix< Real > > *out) const
 
template<typename Real >
void GetSubstateSpeakerMean (int32 j1, int32 substate, int32 gauss, const Sgmm2PerSpkDerivedVars &spk, VectorBase< Real > *mean_out) const
 
template<typename Real >
void GetVarScaledSubstateSpeakerMean (int32 j1, int32 substate, int32 gauss, const Sgmm2PerSpkDerivedVars &spk, VectorBase< Real > *mean_out) const
 
template<class Real >
void ComputeH (std::vector< SpMatrix< Real > > *H_i) const
 Computes quantities H = M_i Sigma_i^{-1} M_i^T. More...
 

Protected Attributes

std::vector< int32pdf2group_
 
std::vector< std::vector< int32 > > group2pdf_
 
DiagGmm diag_ubm_
 These contain the "background" model associated with the subspace GMM. More...
 
FullGmm full_ubm_
 
std::vector< SpMatrix< BaseFloat > > SigmaInv_
 Globally shared parameters of the subspace GMM. More...
 
std::vector< Matrix< BaseFloat > > M_
 Phonetic-subspace projections. Dimension is [I][D][S]. More...
 
std::vector< Matrix< BaseFloat > > N_
 Speaker-subspace projections. Dimension is [I][D][T]. More...
 
Matrix< BaseFloatw_
 Phonetic-subspace weight projection vectors. Dimension is [I][S]. More...
 
Matrix< BaseFloatu_
 [SSGMM] Speaker-subspace weight projection vectors. Dimension is [I][T] More...
 
std::vector< Matrix< BaseFloat > > v_
 The parameters in a particular SGMM state. More...
 
std::vector< Vector< BaseFloat > > c_
 c_{jm}, mixture weights. Dimension is [J2][#mix] More...
 
std::vector< Matrix< BaseFloat > > n_
 n_{jim}, per-Gaussian normalizer. Dimension is [J1][I][#mix] More...
 
std::vector< Matrix< BaseFloat > > w_jmi_
 [SSGMM] w_{jmi}, dimension is [J1][#mix][I]. Computed from w_ and v_. More...
 
std::vector< Matrix< BaseFloat > > M_prior_
 
SpMatrix< BaseFloatrow_cov_inv_
 
SpMatrix< BaseFloatcol_cov_inv_
 

Private Member Functions

void ComputeGammaI (const Vector< BaseFloat > &state_occupancies, Vector< BaseFloat > *gamma_i) const
 Computes quasi-occupancies gamma_i from the state-level occupancies, assuming model correctness. More...
 
void SplitSubstatesInGroup (const Vector< BaseFloat > &pdf_occupancies, const Sgmm2SplitSubstatesConfig &opts, const SpMatrix< BaseFloat > &sqrt_H_sm, int32 j1, int32 M)
 Called inside SplitSubstates(); splits substates of one group. More...
 
void ComputeNormalizersInternal (int32 num_threads, int32 thread, int32 *entropy_count, double *entropy_sum)
 Compute a subset of normalizers; used in multi-threaded implementation. More...
 
void ComponentLogLikes (const Sgmm2PerFrameDerivedVars &per_frame_vars, int32 j1, Sgmm2PerSpkDerivedVars *spk_vars, Matrix< BaseFloat > *loglikes) const
 The code below is called internally from LogLikelihood() and ComponentPosteriors(). More...
 
void InitializeMw (int32 phn_subspace_dim, const Matrix< BaseFloat > &norm_xform)
 Initializes the matrices M_ and w_. More...
 
void InitializeNu (int32 spk_subspace_dim, const Matrix< BaseFloat > &norm_xform, bool speaker_dependent_weights)
 Initializes the matrices N_ and [if speaker_dependent_weights==true] u_. More...
 
void InitializeVecsAndSubstateWeights (BaseFloat self_weight)
 
void InitializeCovars ()
 initializes the within-class covariances. More...
 
void ComputeHsmFromModel (const std::vector< SpMatrix< BaseFloat > > &H, const Vector< BaseFloat > &state_occupancies, SpMatrix< BaseFloat > *H_sm, BaseFloat max_cond) const
 
void ComputePdfMappings ()
 
 KALDI_DISALLOW_COPY_AND_ASSIGN (AmSgmm2)
 maps from each pdf (index j2) to the corresponding group of pdfs (index j1) for SCTM. More...
 

Friends

class ComputeNormalizersClass
 
class Sgmm2Project
 
class EbwAmSgmm2Updater
 
class MleAmSgmm2Accs
 
class MleAmSgmm2Updater
 
class MleSgmm2SpeakerAccs
 
class AmSgmm2Functions
 
class Sgmm2Feature
 

Detailed Description

Class for definition of the subspace Gmm acoustic model.

Definition at line 231 of file am-sgmm2.h.

Constructor & Destructor Documentation

◆ AmSgmm2()

AmSgmm2 ( )
inline

Definition at line 233 of file am-sgmm2.h.

233 {}

Member Function Documentation

◆ Check()

void Check ( bool  show_properties = true)

Checks the various components for correct sizes.

With wrong sizes, assertion failure occurs. When the argument is set to true, dimensions of the various components are printed.

Definition at line 276 of file am-sgmm2.cc.

References rnnlm::i, KALDI_ASSERT, and KALDI_LOG.

Referenced by TestSgmm2IO(), and TestSgmm2Substates().

276  {
277  int32 J1 = NumGroups(),
278  J2 = NumPdfs(),
279  num_gauss = NumGauss(),
280  feat_dim = FeatureDim(),
281  phn_dim = PhoneSpaceDim(),
282  spk_dim = SpkSpaceDim();
283 
284  if (show_properties)
285  KALDI_LOG << "AmSgmm2: #pdfs = " << J2 << ", #pdf-groups = "
286  << J1 << ", #Gaussians = "
287  << num_gauss << ", feature dim = " << feat_dim
288  << ", phone-space dim =" << phn_dim
289  << ", speaker-space dim =" << spk_dim;
290  KALDI_ASSERT(J1 > 0 && num_gauss > 0 && feat_dim > 0 && phn_dim > 0
291  && J2 > 0 && J2 >= J1);
292 
293  std::ostringstream debug_str;
294 
295  // First check the diagonal-covariance UBM.
296  KALDI_ASSERT(diag_ubm_.NumGauss() == num_gauss);
297  KALDI_ASSERT(diag_ubm_.Dim() == feat_dim);
298 
299  // Check the full-covariance UBM.
300  KALDI_ASSERT(full_ubm_.NumGauss() == num_gauss);
301  KALDI_ASSERT(full_ubm_.Dim() == feat_dim);
302 
303  // Check the globally-shared covariance matrices.
304  KALDI_ASSERT(SigmaInv_.size() == static_cast<size_t>(num_gauss));
305  for (int32 i = 0; i < num_gauss; i++) {
306  KALDI_ASSERT(SigmaInv_[i].NumRows() == feat_dim &&
307  SigmaInv_[i](0, 0) > 0.0); // or it wouldn't be +ve definite.
308  }
309 
310  if (spk_dim != 0) {
311  KALDI_ASSERT(N_.size() == static_cast<size_t>(num_gauss));
312  for (int32 i = 0; i < num_gauss; i++)
313  KALDI_ASSERT(N_[i].NumRows() == feat_dim && N_[i].NumCols() == spk_dim);
314  if (u_.NumRows() == 0) {
315  debug_str << "Speaker-weight projections: no.";
316  } else {
317  KALDI_ASSERT(u_.NumRows() == num_gauss && u_.NumCols() == spk_dim);
318  debug_str << "Speaker-weight projections: yes.";
319  }
320  } else {
321  KALDI_ASSERT(N_.size() == 0 && u_.NumRows() == 0);
322  }
323 
324  KALDI_ASSERT(M_.size() == static_cast<size_t>(num_gauss));
325  for (int32 i = 0; i < num_gauss; i++) {
326  KALDI_ASSERT(M_[i].NumRows() == feat_dim && M_[i].NumCols() == phn_dim);
327  }
328 
329  KALDI_ASSERT(w_.NumRows() == num_gauss && w_.NumCols() == phn_dim);
330 
331  { // check v, c.
332  KALDI_ASSERT(v_.size() == static_cast<size_t>(J1) &&
333  c_.size() == static_cast<size_t>(J2));
334  int32 nSubstatesTot = 0;
335  for (int32 j1 = 0; j1 < J1; j1++) {
336  int32 M_j = NumSubstatesForGroup(j1);
337  nSubstatesTot += M_j;
338  KALDI_ASSERT(M_j > 0 && v_[j1].NumRows() == M_j &&
339  v_[j1].NumCols() == phn_dim);
340  }
341  debug_str << "Substates: "<< (nSubstatesTot) << ". ";
342  int32 nSubstateWeights = 0;
343  for (int32 j2 = 0; j2 < J2; j2++) {
344  int32 j1 = Pdf2Group(j2);
345  int32 M = NumSubstatesForPdf(j2);
347  nSubstateWeights += M;
348  }
349  KALDI_ASSERT(nSubstateWeights >= nSubstatesTot);
350  debug_str << "SubstateWeights: "<< (nSubstateWeights) << ". ";
351  }
352 
353  // check normalizers.
354  if (n_.size() == 0) {
355  debug_str << "Normalizers: no. ";
356  } else {
357  debug_str << "Normalizers: yes. ";
358  KALDI_ASSERT(n_.size() == static_cast<size_t>(J1));
359  for (int32 j1 = 0; j1 < J1; j1++) {
360  KALDI_ASSERT(n_[j1].NumRows() == num_gauss &&
361  n_[j1].NumCols() == NumSubstatesForGroup(j1));
362  }
363  }
364 
365  // check w_jmi_.
366  if (w_jmi_.size() == 0) {
367  debug_str << "Computed weights: no. ";
368  } else {
369  debug_str << "Computed weights: yes. ";
370  KALDI_ASSERT(w_jmi_.size() == static_cast<size_t>(J1));
371  for (int32 j1 = 0; j1 < J1; j1++) {
372  KALDI_ASSERT(w_jmi_[j1].NumRows() == NumSubstatesForGroup(j1) &&
373  w_jmi_[j1].NumCols() == num_gauss);
374  }
375  }
376 
377  if (show_properties)
378  KALDI_LOG << "Subspace GMM model properties: " << debug_str.str();
379 }
int32 Dim() const
Returns the dimensionality of the Gaussian mean vectors.
Definition: diag-gmm.h:74
Matrix< BaseFloat > u_
[SSGMM] Speaker-subspace weight projection vectors. Dimension is [I][T]
Definition: am-sgmm2.h:431
int32 Dim() const
Returns the dimensionality of the Gaussian mean vectors.
Definition: full-gmm.h:60
std::vector< Vector< BaseFloat > > c_
c_{jm}, mixture weights. Dimension is [J2][#mix]
Definition: am-sgmm2.h:438
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
Matrix< BaseFloat > w_
Phonetic-subspace weight projection vectors. Dimension is [I][S].
Definition: am-sgmm2.h:429
kaldi::int32 int32
DiagGmm diag_ubm_
These contain the "background" model associated with the subspace GMM.
Definition: am-sgmm2.h:413
std::vector< Matrix< BaseFloat > > n_
n_{jim}, per-Gaussian normalizer. Dimension is [J1][I][#mix]
Definition: am-sgmm2.h:440
std::vector< Matrix< BaseFloat > > N_
Speaker-subspace projections. Dimension is [I][D][T].
Definition: am-sgmm2.h:427
int32 PhoneSpaceDim() const
Definition: am-sgmm2.h:361
std::vector< Matrix< BaseFloat > > v_
The parameters in a particular SGMM state.
Definition: am-sgmm2.h:436
std::vector< Matrix< BaseFloat > > M_
Phonetic-subspace projections. Dimension is [I][D][S].
Definition: am-sgmm2.h:425
int32 FeatureDim() const
Definition: am-sgmm2.h:363
int32 NumSubstatesForPdf(int32 j2) const
Definition: am-sgmm2.h:354
int32 NumGroups() const
Definition: am-sgmm2.h:351
std::vector< SpMatrix< BaseFloat > > SigmaInv_
Globally shared parameters of the subspace GMM.
Definition: am-sgmm2.h:423
int32 Pdf2Group(int32 j2) const
Definition: am-sgmm2.cc:196
FullGmm full_ubm_
Definition: am-sgmm2.h:414
int32 NumPdfs() const
Various model dimensions.
Definition: am-sgmm2.h:350
int32 NumGauss() const
Returns the number of mixture components in the GMM.
Definition: full-gmm.h:58
int32 NumGauss() const
Returns the number of mixture components in the GMM.
Definition: diag-gmm.h:72
int32 NumGauss() const
Definition: am-sgmm2.h:360
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
int32 SpkSpaceDim() const
Definition: am-sgmm2.h:362
#define KALDI_LOG
Definition: kaldi-error.h:153
int32 NumSubstatesForGroup(int32 j1) const
Definition: am-sgmm2.h:357
std::vector< Matrix< BaseFloat > > w_jmi_
[SSGMM] w_{jmi}, dimension is [J1][#mix][I]. Computed from w_ and v_.
Definition: am-sgmm2.h:442

◆ ComponentLogLikes()

void ComponentLogLikes ( const Sgmm2PerFrameDerivedVars per_frame_vars,
int32  j1,
Sgmm2PerSpkDerivedVars spk_vars,
Matrix< BaseFloat > *  loglikes 
) const
inlineprivate

The code below is called internally from LogLikelihood() and ComponentPosteriors().

It computes the per-Gaussian log-likelihods given each sub-state of the state. Note: the mixture weights are not included at this point.

Definition at line 476 of file am-sgmm2.cc.

References VectorBase< Real >::Add(), VectorBase< Real >::AddMatVec(), VectorBase< Real >::AddVec(), MatrixBase< Real >::AddVecToRows(), VectorBase< Real >::ApplyLog(), Sgmm2PerSpkDerivedVars::b_is, VectorBase< Real >::Dim(), Sgmm2PerFrameDerivedVars::gselect, rnnlm::i, KALDI_ASSERT, kaldi::kNoTrans, Sgmm2PerSpkDerivedVars::log_d_jms, Sgmm2PerFrameDerivedVars::nti, Vector< Real >::Resize(), Matrix< Real >::Resize(), MatrixBase< Real >::Row(), Sgmm2PerSpkDerivedVars::v_s, and Sgmm2PerFrameDerivedVars::zti.

479  {
480  const vector<int32> &gselect = per_frame_vars.gselect;
481  int32 num_gselect = gselect.size(), num_substates = v_[j1].NumRows();
482 
483  // Eq.(37): log p(x(t), m, i|j) [indexed by j, ki]
484  // Although the extra memory allocation of storing this as a
485  // matrix might seem unnecessary, we save time in the LogSumExp()
486  // via more effective pruning.
487  loglikes->Resize(num_gselect, num_substates);
488  bool speaker_dep_weights =
489  (spk_vars->v_s.Dim() != 0 && HasSpeakerDependentWeights());
490  if (speaker_dep_weights) {
491  KALDI_ASSERT(static_cast<int32>(spk_vars->log_d_jms.size()) == NumGroups());
492  KALDI_ASSERT(static_cast<int32>(w_jmi_.size()) == NumGroups() ||
493  "You need to call ComputeWeights().");
494  }
495  for (int32 ki = 0; ki < num_gselect; ki++) {
496  SubVector<BaseFloat> logp_xi(*loglikes, ki);
497  int32 i = gselect[ki];
498  // for all substates, compute z_{i}^T v_{jm}
499  logp_xi.AddMatVec(1.0, v_[j1], kNoTrans, per_frame_vars.zti.Row(ki), 0.0);
500  logp_xi.AddVec(1.0, n_[j1].Row(i)); // for all substates, add n_{jim}
501  logp_xi.Add(per_frame_vars.nti(ki)); // for all substates, add n_{i}(t)
502  }
503  if (speaker_dep_weights) { // [SSGMM]
504  Vector<BaseFloat> &log_d = spk_vars->log_d_jms[j1];
505  if (log_d.Dim() == 0) { // have not yet cached this quantity.
506  log_d.Resize(num_substates);
507  log_d.AddMatVec(1.0, w_jmi_[j1], kNoTrans, spk_vars->b_is, 0.0);
508  log_d.ApplyLog();
509  }
510  loglikes->AddVecToRows(-1.0, log_d); // [SSGMM] this is the term
511  // - log d_{jm}^{(s)} in the likelihood function [eq. 25 in
512  // the techreport]
513  }
514 }
kaldi::int32 int32
std::vector< Matrix< BaseFloat > > n_
n_{jim}, per-Gaussian normalizer. Dimension is [J1][I][#mix]
Definition: am-sgmm2.h:440
std::vector< Matrix< BaseFloat > > v_
The parameters in a particular SGMM state.
Definition: am-sgmm2.h:436
int32 NumGroups() const
Definition: am-sgmm2.h:351
void AddVecToRows(const Real alpha, const VectorBase< OtherReal > &v)
[each row of *this] += alpha * v
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
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).
bool HasSpeakerDependentWeights() const
True if doing SSGMM.
Definition: am-sgmm2.h:366
std::vector< Matrix< BaseFloat > > w_jmi_
[SSGMM] w_{jmi}, dimension is [J1][#mix][I]. Computed from w_ and v_.
Definition: am-sgmm2.h:442

◆ ComponentPosteriors()

BaseFloat ComponentPosteriors ( const Sgmm2PerFrameDerivedVars per_frame_vars,
int32  j2,
Sgmm2PerSpkDerivedVars spk_vars,
Matrix< BaseFloat > *  post 
) const

Similar to LogLikelihood() function above, but also computes the posterior probabilities for the pre-selected Gaussian components and all substates.

This one doesn't use caching to share computation for the groups of pdfs. [it's less necessary, as most of the time we're doing this from alignments, or lattices that are quite sparse, so we save little by sharing this.]

Definition at line 574 of file am-sgmm2.cc.

References MatrixBase< Real >::Add(), MatrixBase< Real >::ApplyExp(), KALDI_ASSERT, kaldi::Log(), MatrixBase< Real >::Max(), MatrixBase< Real >::MulColsVec(), MatrixBase< Real >::Scale(), and MatrixBase< Real >::Sum().

Referenced by FmllrSgmm2Accs::Accumulate(), MleAmSgmm2Accs::Accumulate(), MleSgmm2SpeakerAccs::Accumulate(), kaldi::AccumulateForUtterance(), and main().

577  {
578  KALDI_ASSERT(j2 < NumPdfs() && post != NULL);
579  int32 j1 = pdf2group_[j2];
580  ComponentLogLikes(per_frame_vars, j1, spk_vars, post); // now
581  // post is a matrix of log-likelihoods indexed by [gaussian-selection index]
582  // [sub-state index]. It doesn't include the sub-state weights,
583  // though.
584  BaseFloat loglike = post->Max();
585  post->Add(-loglike); // get it to nicer numeric range.
586  post->ApplyExp(); // so we're dealing with likelihoods (with an arbitrary offset
587  // "loglike" removed to make it in a nice numeric range)
588  post->MulColsVec(c_[j2]); // include the sub-state weights.
589 
590  BaseFloat tot_like = post->Sum();
591  KALDI_ASSERT(tot_like != 0.0); // note: not valid to have zero weights.
592  loglike += Log(tot_like);
593  post->Scale(1.0 / tot_like); // so "post" now sums to one, and "loglike"
594  // contains the correct log-likelihood of the data given the pdf.
595 
596  return loglike;
597 }
void Add(const Real alpha)
Add a scalar to each element.
std::vector< int32 > pdf2group_
Definition: am-sgmm2.h:409
std::vector< Vector< BaseFloat > > c_
c_{jm}, mixture weights. Dimension is [J2][#mix]
Definition: am-sgmm2.h:438
Real Max() const
Returns maximum element of matrix.
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
double Log(double x)
Definition: kaldi-math.h:100
void ComponentLogLikes(const Sgmm2PerFrameDerivedVars &per_frame_vars, int32 j1, Sgmm2PerSpkDerivedVars *spk_vars, Matrix< BaseFloat > *loglikes) const
The code below is called internally from LogLikelihood() and ComponentPosteriors().
Definition: am-sgmm2.cc:476
void Scale(Real alpha)
Multiply each element with a scalar value.
int32 NumPdfs() const
Various model dimensions.
Definition: am-sgmm2.h:350
Real Sum() const
Returns sum of all elements in matrix.
void MulColsVec(const VectorBase< Real > &scale)
Equivalent to (*this) = (*this) * diag(scale).
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ComputeDerivedVars()

void ComputeDerivedVars ( )

Computes (and initializes if necessary) derived vars...

for now this is just the normalizers "n" and the diagonal UBM, and if we have the "u" matrix set up, also the w_jmi_ quantities.

Definition at line 810 of file am-sgmm2.cc.

Referenced by main(), TestSgmm2AccsIO(), and UnitTestEstimateSgmm2().

810  {
811  if (n_.empty()) ComputeNormalizers();
813  || diag_ubm_.Dim() != full_ubm_.Dim()) {
815  }
816  if (w_jmi_.empty() && HasSpeakerDependentWeights())
817  ComputeWeights();
818 }
int32 Dim() const
Returns the dimensionality of the Gaussian mean vectors.
Definition: diag-gmm.h:74
void ComputeWeights()
Computes the weights w_jmi_, which is needed for likelihood evaluation with SSGMMs.
Definition: am-sgmm2.cc:796
int32 Dim() const
Returns the dimensionality of the Gaussian mean vectors.
Definition: full-gmm.h:60
DiagGmm diag_ubm_
These contain the "background" model associated with the subspace GMM.
Definition: am-sgmm2.h:413
std::vector< Matrix< BaseFloat > > n_
n_{jim}, per-Gaussian normalizer. Dimension is [J1][I][#mix]
Definition: am-sgmm2.h:440
FullGmm full_ubm_
Definition: am-sgmm2.h:414
int32 NumGauss() const
Returns the number of mixture components in the GMM.
Definition: full-gmm.h:58
int32 NumGauss() const
Returns the number of mixture components in the GMM.
Definition: diag-gmm.h:72
void CopyFromFullGmm(const FullGmm &fullgmm)
Copies from given FullGmm.
Definition: diag-gmm.cc:92
void ComputeNormalizers()
Computes the data-independent terms in the log-likelihood computation for each Gaussian component and...
Definition: am-sgmm2.cc:857
bool HasSpeakerDependentWeights() const
True if doing SSGMM.
Definition: am-sgmm2.h:366
std::vector< Matrix< BaseFloat > > w_jmi_
[SSGMM] w_{jmi}, dimension is [J1][#mix][I]. Computed from w_ and v_.
Definition: am-sgmm2.h:442

◆ ComputeFmllrPreXform()

void ComputeFmllrPreXform ( const Vector< BaseFloat > &  pdf_occs,
Matrix< BaseFloat > *  xform,
Matrix< BaseFloat > *  inv_xform,
Vector< BaseFloat > *  diag_mean_scatter 
) const

Computes the LDA-like pre-transform and its inverse as well as the eigenvalues of the scatter of the means used in FMLLR estimation.

Definition at line 965 of file am-sgmm2.cc.

References SpMatrix< Real >::AddMat2Sp(), MatrixBase< Real >::AddMatMat(), VectorBase< Real >::AddMatVec(), VectorBase< Real >::AddVec(), SpMatrix< Real >::AddVec2(), VectorBase< Real >::ApplyFloor(), VectorBase< Real >::ApplySoftMax(), TpMatrix< Real >::Cholesky(), MatrixBase< Real >::CopyFromMat(), MatrixBase< Real >::CopyFromTp(), VectorBase< Real >::Dim(), SpMatrix< Real >::Eig(), rnnlm::i, TpMatrix< Real >::InvertDouble(), SpMatrix< Real >::InvertDouble(), SpMatrix< Real >::IsDiagonal(), SpMatrix< Real >::IsUnit(), KALDI_ASSERT, KALDI_WARN, kaldi::kNoTrans, kaldi::kSetZero, kaldi::kTrans, kaldi::kUndefined, rnnlm::n, MatrixBase< Real >::Range(), Vector< Real >::Resize(), Matrix< Real >::Resize(), MatrixBase< Real >::Row(), VectorBase< Real >::Scale(), MatrixBase< Real >::SetUnit(), and VectorBase< Real >::Sum().

Referenced by Sgmm2FmllrGlobalParams::Init(), main(), TestSgmm2FmllrAccsIO(), TestSgmm2FmllrSubspace(), and TestSgmm2PreXform().

968  {
969  int32 num_pdfs = NumPdfs(),
970  num_gauss = NumGauss(),
971  dim = FeatureDim();
972  KALDI_ASSERT(state_occs.Dim() == num_pdfs);
973 
974  BaseFloat total_occ = state_occs.Sum();
975 
976  // Degenerate case: unlikely to ever happen.
977  if (total_occ == 0) {
978  KALDI_WARN << "Zero probability (computing transform). Using unit "
979  << "pre-transform";
980  xform->Resize(dim, dim + 1, kUndefined);
981  xform->SetUnit();
982  inv_xform->Resize(dim, dim + 1, kUndefined);
983  inv_xform->SetUnit();
984  diag_mean_scatter->Resize(dim, kSetZero);
985  return;
986  }
987 
988  // Convert state occupancies to posteriors; Eq. (B.1)
989  Vector<BaseFloat> state_posteriors(state_occs);
990  state_posteriors.Scale(1/total_occ);
991 
992  Vector<BaseFloat> mu_jmi(dim), global_mean(dim);
993  SpMatrix<BaseFloat> within_class_covar(dim), between_class_covar(dim);
994  Vector<BaseFloat> gauss_weight(num_gauss); // weights for within-class vars.
995  Vector<BaseFloat> w_jm(num_gauss);
996  for (int32 j1 = 0; j1 < NumGroups(); j1++) {
997  const std::vector<int32> &pdfs = group2pdf_[j1];
998  int32 M = NumSubstatesForGroup(j1);
999  Vector<BaseFloat> substate_weight(M); // total weight for each substate.
1000  for (size_t i = 0; i < pdfs.size(); i++) {
1001  int32 j2 = pdfs[i];
1002  substate_weight.AddVec(state_posteriors(j2), c_[j2]);
1003  }
1004  for (int32 m = 0; m < M; m++) {
1005  BaseFloat this_substate_weight = substate_weight(m);
1006  // Eq. (7): w_jm = softmax([w_{1}^T ... w_{D}^T] * v_{jm})
1007  w_jm.AddMatVec(1.0, w_, kNoTrans, v_[j1].Row(m), 0.0);
1008  w_jm.ApplySoftMax();
1009 
1010  for (int32 i = 0; i < num_gauss; i++) {
1011  BaseFloat weight = this_substate_weight * w_jm(i);
1012  mu_jmi.AddMatVec(1.0, M_[i], kNoTrans, v_[j1].Row(m), 0.0); // Eq. (6)
1013  // Eq. (B.3): \mu_avg = \sum_{jmi} p(j) c_{jm} w_{jmi} \mu_{jmi}
1014  global_mean.AddVec(weight, mu_jmi);
1015  // \Sigma_B = \sum_{jmi} p(j) c_{jm} w_{jmi} \mu_{jmi} \mu_{jmi}^T
1016  between_class_covar.AddVec2(weight, mu_jmi); // Eq. (B.4)
1017  gauss_weight(i) += weight;
1018  }
1019  }
1020  }
1021  between_class_covar.AddVec2(-1.0, global_mean); // Eq. (B.4)
1022 
1023  for (int32 i = 0; i < num_gauss; i++) {
1024  SpMatrix<BaseFloat> Sigma(SigmaInv_[i]);
1025  Sigma.InvertDouble();
1026  // Eq. (B.2): \Sigma_W = \sum_{jmi} p(j) c_{jm} w_{jmi} \Sigma_i
1027  within_class_covar.AddSp(gauss_weight(i), Sigma);
1028  }
1029 
1030  TpMatrix<BaseFloat> tmpL(dim);
1031  Matrix<BaseFloat> tmpLInvFull(dim, dim);
1032  tmpL.Cholesky(within_class_covar); // \Sigma_W = L L^T
1033  tmpL.InvertDouble(); // L^{-1}
1034  tmpLInvFull.CopyFromTp(tmpL); // get as full matrix.
1035 
1036  // B := L^{-1} * \Sigma_B * L^{-T}
1037  SpMatrix<BaseFloat> tmpB(dim);
1038  tmpB.AddMat2Sp(1.0, tmpLInvFull, kNoTrans, between_class_covar, 0.0);
1039 
1040  Matrix<BaseFloat> U(dim, dim);
1041  diag_mean_scatter->Resize(dim);
1042  xform->Resize(dim, dim + 1);
1043  inv_xform->Resize(dim, dim + 1);
1044 
1045  tmpB.Eig(diag_mean_scatter, &U); // Eq. (B.5): B = U D V^T
1046 
1047  int32 n;
1048  diag_mean_scatter->ApplyFloor(1.0e-04, &n);
1049  if (n != 0)
1050  KALDI_WARN << "Floored " << n << " elements of the mean-scatter matrix.";
1051 
1052  // Eq. (B.6): A_{pre} = U^T * L^{-1}
1053  SubMatrix<BaseFloat> Apre(*xform, 0, dim, 0, dim);
1054  Apre.AddMatMat(1.0, U, kTrans, tmpLInvFull, kNoTrans, 0.0);
1055 
1056 #ifdef KALDI_PARANOID
1057  {
1058  SpMatrix<BaseFloat> tmp(dim);
1059  tmp.AddMat2Sp(1.0, Apre, kNoTrans, within_class_covar, 0.0);
1060  KALDI_ASSERT(tmp.IsUnit(0.01));
1061  }
1062  {
1063  SpMatrix<BaseFloat> tmp(dim);
1064  tmp.AddMat2Sp(1.0, Apre, kNoTrans, between_class_covar, 0.0);
1065  KALDI_ASSERT(tmp.IsDiagonal(0.01));
1066  }
1067 #endif
1068 
1069  // Eq. (B.7): b_{pre} = - A_{pre} \mu_{avg}
1070  Vector<BaseFloat> b_pre(dim);
1071  b_pre.AddMatVec(-1.0, Apre, kNoTrans, global_mean, 0.0);
1072  for (int32 r = 0; r < dim; r++) {
1073  xform->Row(r)(dim) = b_pre(r); // W_{pre} = [ A_{pre}, b_{pre} ]
1074  }
1075 
1076  // Eq. (B.8) & (B.9): W_{inv} = [ A_{pre}^{-1}, \mu_{avg} ]
1077  inv_xform->CopyFromMat(*xform);
1078  inv_xform->Range(0, dim, 0, dim).InvertDouble();
1079  for (int32 r = 0; r < dim; r++)
1080  inv_xform->Row(r)(dim) = global_mean(r);
1081 } // End of ComputePreXform()
std::vector< Vector< BaseFloat > > c_
c_{jm}, mixture weights. Dimension is [J2][#mix]
Definition: am-sgmm2.h:438
Matrix< BaseFloat > w_
Phonetic-subspace weight projection vectors. Dimension is [I][S].
Definition: am-sgmm2.h:429
kaldi::int32 int32
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].
std::vector< Matrix< BaseFloat > > v_
The parameters in a particular SGMM state.
Definition: am-sgmm2.h:436
std::vector< Matrix< BaseFloat > > M_
Phonetic-subspace projections. Dimension is [I][D][S].
Definition: am-sgmm2.h:425
int32 FeatureDim() const
Definition: am-sgmm2.h:363
int32 NumGroups() const
Definition: am-sgmm2.h:351
float BaseFloat
Definition: kaldi-types.h:29
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
std::vector< SpMatrix< BaseFloat > > SigmaInv_
Globally shared parameters of the subspace GMM.
Definition: am-sgmm2.h:423
struct rnnlm::@11::@12 n
int32 NumPdfs() const
Various model dimensions.
Definition: am-sgmm2.h:350
#define KALDI_WARN
Definition: kaldi-error.h:150
int32 NumGauss() const
Definition: am-sgmm2.h:360
std::vector< std::vector< int32 > > group2pdf_
Definition: am-sgmm2.h:410
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
SubMatrix< Real > Range(const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Return a sub-part of matrix.
Definition: kaldi-matrix.h:202
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).
int32 NumSubstatesForGroup(int32 j1) const
Definition: am-sgmm2.h:357

◆ ComputeGammaI()

void ComputeGammaI ( const Vector< BaseFloat > &  state_occupancies,
Vector< BaseFloat > *  gamma_i 
) const
private

Computes quasi-occupancies gamma_i from the state-level occupancies, assuming model correctness.

Definition at line 50 of file am-sgmm2.cc.

References VectorBase< Real >::AddVec(), VectorBase< Real >::Dim(), rnnlm::i, KALDI_ASSERT, kaldi::kNoTrans, and Vector< Real >::Resize().

51  {
52  KALDI_ASSERT(state_occupancies.Dim() == NumPdfs());
53  Vector<BaseFloat> w_jm(NumGauss());
54  gamma_i->Resize(NumGauss());
55  for (int32 j1 = 0; j1 < NumGroups(); j1++) {
57  const std::vector<int32> &pdfs = group2pdf_[j1];
58  Vector<BaseFloat> substate_weight(M); // total weight for each substate.
59  for (size_t i = 0; i < pdfs.size(); i++) {
60  int32 j2 = pdfs[i];
61  substate_weight.AddVec(state_occupancies(j2), c_[j2]);
62  }
63  for (int32 m = 0; m < M; m++) {
64  w_jm.AddMatVec(1.0, w_, kNoTrans, v_[j1].Row(m), 0.0);
65  w_jm.ApplySoftMax();
66  gamma_i->AddVec(substate_weight(m), w_jm);
67  }
68  }
69 }
std::vector< Vector< BaseFloat > > c_
c_{jm}, mixture weights. Dimension is [J2][#mix]
Definition: am-sgmm2.h:438
Matrix< BaseFloat > w_
Phonetic-subspace weight projection vectors. Dimension is [I][S].
Definition: am-sgmm2.h:429
kaldi::int32 int32
std::vector< Matrix< BaseFloat > > v_
The parameters in a particular SGMM state.
Definition: am-sgmm2.h:436
int32 NumGroups() const
Definition: am-sgmm2.h:351
int32 NumPdfs() const
Various model dimensions.
Definition: am-sgmm2.h:350
int32 NumGauss() const
Definition: am-sgmm2.h:360
std::vector< std::vector< int32 > > group2pdf_
Definition: am-sgmm2.h:410
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
int32 NumSubstatesForGroup(int32 j1) const
Definition: am-sgmm2.h:357

◆ ComputeH()

template void ComputeH ( std::vector< SpMatrix< Real > > *  H_i) const

Computes quantities H = M_i Sigma_i^{-1} M_i^T.

Definition at line 1107 of file am-sgmm2.cc.

References SpMatrix< Real >::AddMat2Sp(), rnnlm::i, KALDI_ASSERT, and kaldi::kTrans.

Referenced by EbwAmSgmm2Updater::Update(), and MleAmSgmm2Updater::Update().

1107  {
1108  KALDI_ASSERT(NumGauss() != 0);
1109  (*H_i).resize(NumGauss());
1110  SpMatrix<BaseFloat> H_i_tmp(PhoneSpaceDim());
1111  for (int32 i = 0; i < NumGauss(); i++) {
1112  (*H_i)[i].Resize(PhoneSpaceDim());
1113  H_i_tmp.AddMat2Sp(1.0, M_[i], kTrans, SigmaInv_[i], 0.0);
1114  (*H_i)[i].CopyFromSp(H_i_tmp);
1115  }
1116 }
kaldi::int32 int32
int32 PhoneSpaceDim() const
Definition: am-sgmm2.h:361
std::vector< Matrix< BaseFloat > > M_
Phonetic-subspace projections. Dimension is [I][D][S].
Definition: am-sgmm2.h:425
std::vector< SpMatrix< BaseFloat > > SigmaInv_
Globally shared parameters of the subspace GMM.
Definition: am-sgmm2.h:423
int32 NumGauss() const
Definition: am-sgmm2.h:360
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ComputeHsmFromModel()

void ComputeHsmFromModel ( const std::vector< SpMatrix< BaseFloat > > &  H,
const Vector< BaseFloat > &  state_occupancies,
SpMatrix< BaseFloat > *  H_sm,
BaseFloat  max_cond 
) const
private

Definition at line 1260 of file am-sgmm2.cc.

References SpMatrix< Real >::AddSp(), VectorBase< Real >::Dim(), rnnlm::i, KALDI_ASSERT, KALDI_LOG, KALDI_WARN, SpMatrix< Real >::LimitCondDouble(), SpMatrix< Real >::Resize(), PackedMatrix< Real >::Scale(), PackedMatrix< Real >::SetUnit(), and PackedMatrix< Real >::SetZero().

1264  {
1265  int32 num_gauss = NumGauss();
1266  BaseFloat tot_sum = 0.0;
1267  KALDI_ASSERT(state_occupancies.Dim() == NumPdfs());
1268  Vector<BaseFloat> w_jm(num_gauss);
1269  H_sm->Resize(PhoneSpaceDim());
1270  H_sm->SetZero();
1271  Vector<BaseFloat> gamma_i;
1272  ComputeGammaI(state_occupancies, &gamma_i);
1273 
1274  BaseFloat sum = 0.0;
1275  for (int32 i = 0; i < num_gauss; i++) {
1276  if (gamma_i(i) > 0) {
1277  H_sm->AddSp(gamma_i(i), H[i]);
1278  sum += gamma_i(i);
1279  }
1280  }
1281  if (sum == 0.0) {
1282  KALDI_WARN << "Sum of counts is zero. ";
1283  // set to unit matrix--arbitrary non-singular matrix.. won't ever matter.
1284  H_sm->SetUnit();
1285  } else {
1286  H_sm->Scale(1.0 / sum);
1287  int32 tmp = H_sm->LimitCondDouble(max_cond);
1288  if (tmp > 0) {
1289  KALDI_WARN << "Limited " << (tmp) << " eigenvalues of H_sm";
1290  }
1291  }
1292  tot_sum += sum;
1293 
1294  KALDI_LOG << "total count is " << tot_sum;
1295 }
kaldi::int32 int32
int32 PhoneSpaceDim() const
Definition: am-sgmm2.h:361
float BaseFloat
Definition: kaldi-types.h:29
int32 NumPdfs() const
Various model dimensions.
Definition: am-sgmm2.h:350
#define KALDI_WARN
Definition: kaldi-error.h:150
int32 NumGauss() const
Definition: am-sgmm2.h:360
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void ComputeGammaI(const Vector< BaseFloat > &state_occupancies, Vector< BaseFloat > *gamma_i) const
Computes quasi-occupancies gamma_i from the state-level occupancies, assuming model correctness...
Definition: am-sgmm2.cc:50
#define KALDI_LOG
Definition: kaldi-error.h:153

◆ ComputeNormalizers()

void ComputeNormalizers ( )

Computes the data-independent terms in the log-likelihood computation for each Gaussian component and all substates.

Eq. (31)

Definition at line 857 of file am-sgmm2.cc.

References kaldi::Exp(), KALDI_LOG, and kaldi::RunMultiThreaded().

Referenced by main(), TestSgmm2Fmllr(), TestSgmm2Init(), TestSgmm2Substates(), UnitTestEstimateSgmm2(), UnitTestSgmm2(), and EbwAmSgmm2Updater::Update().

857  {
858  KALDI_LOG << "Computing normalizers";
859  n_.resize(NumPdfs());
860  int32 entropy_count = 0;
861  double entropy_sum = 0.0;
862  ComputeNormalizersClass c(this, &entropy_count, &entropy_sum);
863  RunMultiThreaded(c);
864 
865  KALDI_LOG << "Entropy of weights in substates is "
866  << (entropy_sum / entropy_count) << " over " << entropy_count
867  << " substates, equivalent to perplexity of "
868  << (Exp(entropy_sum /entropy_count));
869  KALDI_LOG << "Done computing normalizers";
870 }
double Exp(double x)
Definition: kaldi-math.h:83
kaldi::int32 int32
std::vector< Matrix< BaseFloat > > n_
n_{jim}, per-Gaussian normalizer. Dimension is [J1][I][#mix]
Definition: am-sgmm2.h:440
void RunMultiThreaded(const C &c_in)
Here, class C should inherit from MultiThreadable.
Definition: kaldi-thread.h:151
int32 NumPdfs() const
Various model dimensions.
Definition: am-sgmm2.h:350
#define KALDI_LOG
Definition: kaldi-error.h:153
friend class ComputeNormalizersClass
Definition: am-sgmm2.h:500

◆ ComputeNormalizersInternal()

void ComputeNormalizersInternal ( int32  num_threads,
int32  thread,
int32 entropy_count,
double *  entropy_sum 
)
private

Compute a subset of normalizers; used in multi-threaded implementation.

Definition at line 873 of file am-sgmm2.cc.

References MatrixBase< Real >::AddMatMat(), MatrixBase< Real >::AddMatSp(), kaldi::Exp(), rnnlm::i, KALDI_ISFINITE, KALDI_LOG, KALDI_WARN, kaldi::kNoTrans, kaldi::kTrans, kaldi::Log(), M_PI, MatrixBase< Real >::Row(), and kaldi::VecVec().

875  {
876 
877  BaseFloat DLog2pi = FeatureDim() * Log(2 * M_PI);
878  Vector<BaseFloat> log_det_Sigma(NumGauss());
879 
880  for (int32 i = 0; i < NumGauss(); i++) {
881  try {
882  log_det_Sigma(i) = - SigmaInv_[i].LogPosDefDet();
883  } catch(...) {
884  if (thread == 0) // just for one thread, print errors [else, duplicates]
885  KALDI_WARN << "Covariance is not positive definite, setting to unit";
886  SigmaInv_[i].SetUnit();
887  log_det_Sigma(i) = 0.0;
888  }
889  }
890 
891  int32 J1 = NumGroups();
892 
893  int block_size = (NumPdfs() + num_threads-1) / num_threads;
894  int j_start = thread * block_size, j_end = std::min(J1, j_start + block_size);
895 
896  int32 I = NumGauss();
897  for (int32 j1 = j_start; j1 < j_end; j1++) {
898  int32 M = NumSubstatesForGroup(j1);
899  Matrix<BaseFloat> log_w_jm(M, I);
900  n_[j1].Resize(I, M);
901  Matrix<BaseFloat> mu_jmi(M, FeatureDim());
902  Matrix<BaseFloat> SigmaInv_mu(M, FeatureDim());
903 
904  // (in logs): w_jm = softmax([w_{k1}^T ... w_{kD}^T] * v_{jkm}) eq.(7)
905  log_w_jm.AddMatMat(1.0, v_[j1], kNoTrans, w_, kTrans, 0.0);
906  for (int32 m = 0; m < M; m++) {
907  log_w_jm.Row(m).Add(-1.0 * log_w_jm.Row(m).LogSumExp());
908  { // DIAGNOSTIC CODE
909  (*entropy_count)++;
910  for (int32 i = 0; i < NumGauss(); i++) {
911  (*entropy_sum) -= log_w_jm(m, i) * Exp(log_w_jm(m, i));
912  }
913  }
914  }
915 
916  for (int32 i = 0; i < I; i++) {
917  // mu_jmi = M_{i} * v_{jm}
918  mu_jmi.AddMatMat(1.0, v_[j1], kNoTrans, M_[i], kTrans, 0.0);
919  SigmaInv_mu.AddMatSp(1.0, mu_jmi, kNoTrans, SigmaInv_[i], 0.0);
920 
921  for (int32 m = 0; m < M; m++) {
922  // mu_{jmi} * \Sigma_{i}^{-1} * mu_{jmi}
923  BaseFloat mu_SigmaInv_mu = VecVec(mu_jmi.Row(m), SigmaInv_mu.Row(m));
924  // Previously had:
925  // BaseFloat logc = log(c_[j](m));
926  // but because of STCM aspect, we can't include the sub-state mixture weights
927  // at this point [included later on.]
928 
929  // eq.(31)
930  n_[j1](i, m) = log_w_jm(m, i) - 0.5 * (log_det_Sigma(i) + DLog2pi
931  + mu_SigmaInv_mu);
932  { // Mainly diagnostic code. Not necessary.
933  BaseFloat tmp = n_[j1](i, m);
934  if (!KALDI_ISFINITE(tmp)) { // NaN or inf
935  KALDI_LOG << "Warning: normalizer for j1 = " << j1 << ", m = " << m
936  << ", i = " << i << " is infinite or NaN " << tmp << "= "
937  << log_w_jm(m, i) << "+"
938  << (-0.5 * log_det_Sigma(i)) << "+" << (-0.5 * DLog2pi)
939  << "+" << (mu_SigmaInv_mu) << ", setting to finite.";
940  n_[j1](i, m) = -1.0e+40; // future work(arnab): get rid of magic number
941  }
942  }
943  }
944  }
945  }
946 }
double Exp(double x)
Definition: kaldi-math.h:83
#define M_PI
Definition: kaldi-math.h:44
Matrix< BaseFloat > w_
Phonetic-subspace weight projection vectors. Dimension is [I][S].
Definition: am-sgmm2.h:429
#define KALDI_ISFINITE(x)
Definition: kaldi-math.h:74
kaldi::int32 int32
std::vector< Matrix< BaseFloat > > n_
n_{jim}, per-Gaussian normalizer. Dimension is [J1][I][#mix]
Definition: am-sgmm2.h:440
std::vector< Matrix< BaseFloat > > v_
The parameters in a particular SGMM state.
Definition: am-sgmm2.h:436
std::vector< Matrix< BaseFloat > > M_
Phonetic-subspace projections. Dimension is [I][D][S].
Definition: am-sgmm2.h:425
int32 FeatureDim() const
Definition: am-sgmm2.h:363
int32 NumGroups() const
Definition: am-sgmm2.h:351
float BaseFloat
Definition: kaldi-types.h:29
std::vector< SpMatrix< BaseFloat > > SigmaInv_
Globally shared parameters of the subspace GMM.
Definition: am-sgmm2.h:423
double Log(double x)
Definition: kaldi-math.h:100
int32 NumPdfs() const
Various model dimensions.
Definition: am-sgmm2.h:350
#define KALDI_WARN
Definition: kaldi-error.h:150
int32 NumGauss() const
Definition: am-sgmm2.h:360
#define KALDI_LOG
Definition: kaldi-error.h:153
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37
int32 NumSubstatesForGroup(int32 j1) const
Definition: am-sgmm2.h:357

◆ ComputePdfMappings()

void ComputePdfMappings ( )
private

Definition at line 72 of file am-sgmm2.cc.

References KALDI_ASSERT, and KALDI_WARN.

72  {
73  if (pdf2group_.empty()) {
74  KALDI_WARN << "ComputePdfMappings(): no pdf2group_ map, assuming you "
75  "are reading in old model.";
76  KALDI_ASSERT(v_.size() != 0);
77  pdf2group_.resize(v_.size());
78  for (int32 j2 = 0; j2 < static_cast<int32>(pdf2group_.size()); j2++)
79  pdf2group_[j2] = j2;
80  }
81  group2pdf_.clear();
82  for (int32 j2 = 0; j2 < static_cast<int32>(pdf2group_.size()); j2++) {
83  int32 j1 = pdf2group_[j2];
84  if (group2pdf_.size() <= j1) group2pdf_.resize(j1+1);
85  group2pdf_[j1].push_back(j2);
86  }
87 }
std::vector< int32 > pdf2group_
Definition: am-sgmm2.h:409
kaldi::int32 int32
std::vector< Matrix< BaseFloat > > v_
The parameters in a particular SGMM state.
Definition: am-sgmm2.h:436
#define KALDI_WARN
Definition: kaldi-error.h:150
std::vector< std::vector< int32 > > group2pdf_
Definition: am-sgmm2.h:410
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ComputePerFrameVars()

void ComputePerFrameVars ( const VectorBase< BaseFloat > &  data,
const std::vector< int32 > &  gselect,
const Sgmm2PerSpkDerivedVars spk_vars,
Sgmm2PerFrameDerivedVars per_frame_vars 
) const

This needs to be called with each new frame of data, prior to accumulation or likelihood evaluation: it computes various pre-computed quantities.

Definition at line 442 of file am-sgmm2.cc.

References VectorBase< Real >::AddSpVec(), Sgmm2PerFrameDerivedVars::gselect, rnnlm::i, KALDI_ASSERT, kaldi::kTrans, Sgmm2PerSpkDerivedVars::log_b_is, Sgmm2PerFrameDerivedVars::nti, Sgmm2PerSpkDerivedVars::o_s, Sgmm2PerFrameDerivedVars::Resize(), MatrixBase< Real >::Row(), Sgmm2PerSpkDerivedVars::v_s, kaldi::VecVec(), Sgmm2PerFrameDerivedVars::xt, Sgmm2PerFrameDerivedVars::xti, and Sgmm2PerFrameDerivedVars::zti.

Referenced by kaldi::AccumulateForUtterance(), DecodableAmSgmm2::LogLikelihoodForPdf(), main(), TestSgmm2AccsIO(), TestSgmm2FmllrAccsIO(), TestSgmm2FmllrSubspace(), TestSgmm2IncreaseDim(), TestSgmm2Init(), TestSgmm2IO(), and TestSgmm2Substates().

445  {
446  KALDI_ASSERT(!n_.empty() && "ComputeNormalizers() must be called.");
447 
448  per_frame_vars->Resize(gselect.size(), FeatureDim(), PhoneSpaceDim());
449 
450  per_frame_vars->gselect = gselect;
451  per_frame_vars->xt.CopyFromVec(data);
452 
453  for (int32 ki = 0, last = gselect.size(); ki < last; ki++) {
454  int32 i = gselect[ki];
455  per_frame_vars->xti.Row(ki).CopyFromVec(per_frame_vars->xt);
456  if (spk_vars.v_s.Dim() != 0)
457  per_frame_vars->xti.Row(ki).AddVec(-1.0, spk_vars.o_s.Row(i));
458  }
459  Vector<BaseFloat> SigmaInv_xt(FeatureDim());
460 
461  bool speaker_dep_weights =
462  (spk_vars.v_s.Dim() != 0 && HasSpeakerDependentWeights());
463  for (int32 ki = 0, last = gselect.size(); ki < last; ki++) {
464  int32 i = gselect[ki];
465  BaseFloat ssgmm_term = (speaker_dep_weights ? spk_vars.log_b_is(i) : 0.0);
466  SigmaInv_xt.AddSpVec(1.0, SigmaInv_[i], per_frame_vars->xti.Row(ki), 0.0);
467  // Eq (35): z_{i}(t) = M_{i}^{T} \Sigma_{i}^{-1} x_{i}(t)
468  per_frame_vars->zti.Row(ki).AddMatVec(1.0, M_[i], kTrans, SigmaInv_xt, 0.0);
469  // Eq.(36): n_{i}(t) = -0.5 x_{i}^{T} \Sigma_{i}^{-1} x_{i}(t)
470  per_frame_vars->nti(ki) = -0.5 * VecVec(per_frame_vars->xti.Row(ki),
471  SigmaInv_xt) + ssgmm_term;
472  }
473 }
kaldi::int32 int32
std::vector< Matrix< BaseFloat > > n_
n_{jim}, per-Gaussian normalizer. Dimension is [J1][I][#mix]
Definition: am-sgmm2.h:440
int32 PhoneSpaceDim() const
Definition: am-sgmm2.h:361
std::vector< Matrix< BaseFloat > > M_
Phonetic-subspace projections. Dimension is [I][D][S].
Definition: am-sgmm2.h:425
int32 FeatureDim() const
Definition: am-sgmm2.h:363
float BaseFloat
Definition: kaldi-types.h:29
std::vector< SpMatrix< BaseFloat > > SigmaInv_
Globally shared parameters of the subspace GMM.
Definition: am-sgmm2.h:423
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
bool HasSpeakerDependentWeights() const
True if doing SSGMM.
Definition: am-sgmm2.h:366
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37

◆ ComputePerSpkDerivedVars()

void ComputePerSpkDerivedVars ( Sgmm2PerSpkDerivedVars vars) const

Computes the per-speaker derived vars; assumes vars->v_s is already set up.

Definition at line 1369 of file am-sgmm2.cc.

References Sgmm2PerSpkDerivedVars::b_is, Sgmm2PerSpkDerivedVars::Clear(), rnnlm::i, KALDI_ASSERT, KALDI_WARN, kaldi::kNoTrans, Sgmm2PerSpkDerivedVars::log_b_is, Sgmm2PerSpkDerivedVars::log_d_jms, Sgmm2PerSpkDerivedVars::o_s, Matrix< Real >::Resize(), MatrixBase< Real >::Row(), and Sgmm2PerSpkDerivedVars::v_s.

Referenced by main(), and kaldi::ProcessUtterance().

1369  {
1370  KALDI_ASSERT(vars != NULL);
1371  if (vars->v_s.Dim() != 0) {
1372  KALDI_ASSERT(vars->v_s.Dim() == SpkSpaceDim());
1373  vars->o_s.Resize(NumGauss(), FeatureDim());
1374  int32 num_gauss = NumGauss();
1375  // first compute the o_i^{(s)} quantities.
1376  for (int32 i = 0; i < num_gauss; i++) {
1377  // Eqn. (32): o_i^{(s)} = N_i v^{(s)}
1378  vars->o_s.Row(i).AddMatVec(1.0, N_[i], kNoTrans, vars->v_s, 0.0);
1379  }
1380  // the rest relates to the SSGMM. We only need to to this
1381  // if we're using speaker-dependent weights.
1383  vars->log_d_jms.clear();
1384  vars->log_d_jms.resize(NumGroups());
1385  vars->log_b_is.Resize(NumGauss());
1386  vars->log_b_is.AddMatVec(1.0, u_, kNoTrans, vars->v_s, 0.0);
1387  vars->b_is.Resize(NumGauss());
1388  vars->b_is.CopyFromVec(vars->log_b_is);
1389  vars->b_is.ApplyExp();
1390  for (int32 i = 0; i < vars->b_is.Dim(); i++) {
1391  if (vars->b_is(i) - vars->b_is(i) != 0.0) { // NaN.
1392  vars->b_is(i) = 1.0;
1393  KALDI_WARN << "Set NaN in b_is to 1.0";
1394  }
1395  }
1396  } else {
1397  vars->b_is.Resize(0);
1398  vars->log_b_is.Resize(0);
1399  vars->log_d_jms.resize(0);
1400  }
1401  } else {
1402  vars->Clear(); // make sure everything is cleared.
1403  }
1404 }
Matrix< BaseFloat > u_
[SSGMM] Speaker-subspace weight projection vectors. Dimension is [I][T]
Definition: am-sgmm2.h:431
kaldi::int32 int32
std::vector< Matrix< BaseFloat > > N_
Speaker-subspace projections. Dimension is [I][D][T].
Definition: am-sgmm2.h:427
int32 FeatureDim() const
Definition: am-sgmm2.h:363
int32 NumGroups() const
Definition: am-sgmm2.h:351
#define KALDI_WARN
Definition: kaldi-error.h:150
int32 NumGauss() const
Definition: am-sgmm2.h:360
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
bool HasSpeakerDependentWeights() const
True if doing SSGMM.
Definition: am-sgmm2.h:366
int32 SpkSpaceDim() const
Definition: am-sgmm2.h:362

◆ ComputeWeights()

void ComputeWeights ( )

Computes the weights w_jmi_, which is needed for likelihood evaluation with SSGMMs.

Definition at line 796 of file am-sgmm2.cc.

References rnnlm::i, kaldi::kNoTrans, and kaldi::kTrans.

Referenced by TestSgmm2Init(), and TestSgmm2Substates().

796  {
797  int32 J1 = NumGroups();
798  w_jmi_.resize(J1);
799  int32 i = NumGauss();
800  for (int32 j1 = 0; j1 < J1; j1++) {
801  int32 M = NumSubstatesForGroup(j1);
802  w_jmi_[j1].Resize(M, i);
803  w_jmi_[j1].AddMatMat(1.0, v_[j1], kNoTrans, w_, kTrans, 0.0);
804  // now w_jmi_ contains un-normalized log weights.
805  for (int32 m = 0; m < M; m++)
806  w_jmi_[j1].Row(m).ApplySoftMax(); // get the actual weights.
807  }
808 }
Matrix< BaseFloat > w_
Phonetic-subspace weight projection vectors. Dimension is [I][S].
Definition: am-sgmm2.h:429
kaldi::int32 int32
std::vector< Matrix< BaseFloat > > v_
The parameters in a particular SGMM state.
Definition: am-sgmm2.h:436
int32 NumGroups() const
Definition: am-sgmm2.h:351
int32 NumGauss() const
Definition: am-sgmm2.h:360
int32 NumSubstatesForGroup(int32 j1) const
Definition: am-sgmm2.h:357
std::vector< Matrix< BaseFloat > > w_jmi_
[SSGMM] w_{jmi}, dimension is [J1][#mix][I]. Computed from w_ and v_.
Definition: am-sgmm2.h:442

◆ CopyFromSgmm2()

void CopyFromSgmm2 ( const AmSgmm2 other,
bool  copy_normalizers,
bool  copy_weights 
)

Used to copy models (useful in update)

Definition at line 415 of file am-sgmm2.cc.

References AmSgmm2::c_, AmSgmm2::diag_ubm_, AmSgmm2::full_ubm_, AmSgmm2::group2pdf_, KALDI_LOG, AmSgmm2::M_, AmSgmm2::N_, AmSgmm2::n_, AmSgmm2::pdf2group_, AmSgmm2::SigmaInv_, AmSgmm2::u_, AmSgmm2::v_, AmSgmm2::w_, and AmSgmm2::w_jmi_.

Referenced by TestSgmm2AccsIO(), TestSgmm2Init(), and TestSgmm2Substates().

417  {
418  KALDI_LOG << "Copying AmSgmm2";
419  pdf2group_ = other.pdf2group_;
420  group2pdf_ = other.group2pdf_;
421 
422  // Copy background GMMs
423  diag_ubm_.CopyFromDiagGmm(other.diag_ubm_);
424  full_ubm_.CopyFromFullGmm(other.full_ubm_);
425 
426  // Copy global params
427  SigmaInv_ = other.SigmaInv_;
428  M_ = other.M_;
429  w_ = other.w_;
430  N_ = other.N_;
431  u_ = other.u_;
432 
433  // Copy state-specific params, but only copy normalizers if requested.
434  v_ = other.v_;
435  c_ = other.c_;
436  if (copy_normalizers) n_ = other.n_;
437  if (copy_weights) w_jmi_ = other.w_jmi_;
438 
439  KALDI_LOG << "Done.";
440 }
void CopyFromDiagGmm(const DiagGmm &diaggmm)
Copies from given DiagGmm.
Definition: diag-gmm.cc:83
Matrix< BaseFloat > u_
[SSGMM] Speaker-subspace weight projection vectors. Dimension is [I][T]
Definition: am-sgmm2.h:431
std::vector< int32 > pdf2group_
Definition: am-sgmm2.h:409
std::vector< Vector< BaseFloat > > c_
c_{jm}, mixture weights. Dimension is [J2][#mix]
Definition: am-sgmm2.h:438
Matrix< BaseFloat > w_
Phonetic-subspace weight projection vectors. Dimension is [I][S].
Definition: am-sgmm2.h:429
DiagGmm diag_ubm_
These contain the "background" model associated with the subspace GMM.
Definition: am-sgmm2.h:413
std::vector< Matrix< BaseFloat > > n_
n_{jim}, per-Gaussian normalizer. Dimension is [J1][I][#mix]
Definition: am-sgmm2.h:440
std::vector< Matrix< BaseFloat > > N_
Speaker-subspace projections. Dimension is [I][D][T].
Definition: am-sgmm2.h:427
std::vector< Matrix< BaseFloat > > v_
The parameters in a particular SGMM state.
Definition: am-sgmm2.h:436
std::vector< Matrix< BaseFloat > > M_
Phonetic-subspace projections. Dimension is [I][D][S].
Definition: am-sgmm2.h:425
void CopyFromFullGmm(const FullGmm &fullgmm)
Copies from given FullGmm.
Definition: full-gmm.cc:65
std::vector< SpMatrix< BaseFloat > > SigmaInv_
Globally shared parameters of the subspace GMM.
Definition: am-sgmm2.h:423
FullGmm full_ubm_
Definition: am-sgmm2.h:414
std::vector< std::vector< int32 > > group2pdf_
Definition: am-sgmm2.h:410
#define KALDI_LOG
Definition: kaldi-error.h:153
std::vector< Matrix< BaseFloat > > w_jmi_
[SSGMM] w_{jmi}, dimension is [J1][#mix][I]. Computed from w_ and v_.
Definition: am-sgmm2.h:442

◆ CopyGlobalsInitVecs()

void CopyGlobalsInitVecs ( const AmSgmm2 other,
const std::vector< int32 > &  pdf2group,
BaseFloat  self_weight 
)

Copies the global parameters from the supplied model, but sets the state vectors to zero.

Definition at line 1183 of file am-sgmm2.cc.

References AmSgmm2::diag_ubm_, AmSgmm2::full_ubm_, KALDI_LOG, AmSgmm2::M_, AmSgmm2::N_, AmSgmm2::SigmaInv_, AmSgmm2::u_, and AmSgmm2::w_.

Referenced by main().

1185  {
1186  KALDI_LOG << "Initializing model";
1187  pdf2group_ = pdf2group;
1189 
1190  // Copy background GMMs
1191  diag_ubm_.CopyFromDiagGmm(other.diag_ubm_);
1192  full_ubm_.CopyFromFullGmm(other.full_ubm_);
1193 
1194  // Copy global params
1195  SigmaInv_ = other.SigmaInv_;
1196 
1197  M_ = other.M_;
1198  w_ = other.w_;
1199  u_ = other.u_;
1200  N_ = other.N_;
1201 
1202  InitializeVecsAndSubstateWeights(self_weight);
1203 }
void CopyFromDiagGmm(const DiagGmm &diaggmm)
Copies from given DiagGmm.
Definition: diag-gmm.cc:83
Matrix< BaseFloat > u_
[SSGMM] Speaker-subspace weight projection vectors. Dimension is [I][T]
Definition: am-sgmm2.h:431
std::vector< int32 > pdf2group_
Definition: am-sgmm2.h:409
Matrix< BaseFloat > w_
Phonetic-subspace weight projection vectors. Dimension is [I][S].
Definition: am-sgmm2.h:429
DiagGmm diag_ubm_
These contain the "background" model associated with the subspace GMM.
Definition: am-sgmm2.h:413
std::vector< Matrix< BaseFloat > > N_
Speaker-subspace projections. Dimension is [I][D][T].
Definition: am-sgmm2.h:427
void InitializeVecsAndSubstateWeights(BaseFloat self_weight)
Definition: am-sgmm2.cc:1207
std::vector< Matrix< BaseFloat > > M_
Phonetic-subspace projections. Dimension is [I][D][S].
Definition: am-sgmm2.h:425
void CopyFromFullGmm(const FullGmm &fullgmm)
Copies from given FullGmm.
Definition: full-gmm.cc:65
std::vector< SpMatrix< BaseFloat > > SigmaInv_
Globally shared parameters of the subspace GMM.
Definition: am-sgmm2.h:423
FullGmm full_ubm_
Definition: am-sgmm2.h:414
void ComputePdfMappings()
Definition: am-sgmm2.cc:72
#define KALDI_LOG
Definition: kaldi-error.h:153

◆ diag_ubm()

const DiagGmm& diag_ubm ( ) const
inline

Definition at line 379 of file am-sgmm2.h.

References rnnlm::i.

379 { return diag_ubm_; }
DiagGmm diag_ubm_
These contain the "background" model associated with the subspace GMM.
Definition: am-sgmm2.h:413

◆ FeatureDim()

◆ full_ubm()

const FullGmm& full_ubm ( ) const
inline

Accessors.

Definition at line 378 of file am-sgmm2.h.

Referenced by Sgmm2Project::ComputeProjection(), main(), TestSgmm2IncreaseDim(), and TestSgmm2Init().

378 { return full_ubm_; }
FullGmm full_ubm_
Definition: am-sgmm2.h:414

◆ GaussianSelection()

BaseFloat GaussianSelection ( const Sgmm2GselectConfig config,
const VectorBase< BaseFloat > &  data,
std::vector< int32 > *  gselect 
) const

Computes the top-scoring Gaussian indices (used for pruning of later stages of computation).

Returns frame log-likelihood given selected Gaussians from full UBM.

Definition at line 1406 of file am-sgmm2.cc.

References VectorBase< Real >::Data(), Sgmm2GselectConfig::diag_gmm_nbest, VectorBase< Real >::Dim(), Sgmm2GselectConfig::full_gmm_nbest, rnnlm::i, and KALDI_ASSERT.

Referenced by main(), TestSgmm2AccsIO(), TestSgmm2FmllrAccsIO(), TestSgmm2FmllrSubspace(), TestSgmm2IncreaseDim(), TestSgmm2Init(), TestSgmm2IO(), and TestSgmm2Substates().

1408  {
1409  KALDI_ASSERT(diag_ubm_.NumGauss() != 0 &&
1411  diag_ubm_.Dim() == data.Dim());
1412  KALDI_ASSERT(config.diag_gmm_nbest > 0 && config.full_gmm_nbest > 0 &&
1413  config.full_gmm_nbest < config.diag_gmm_nbest);
1414  int32 num_gauss = diag_ubm_.NumGauss();
1415 
1416  std::vector< std::pair<BaseFloat, int32> > pruned_pairs;
1417  if (config.diag_gmm_nbest < num_gauss) { Vector<BaseFloat> loglikes(num_gauss);
1418  diag_ubm_.LogLikelihoods(data, &loglikes);
1419  Vector<BaseFloat> loglikes_copy(loglikes);
1420  BaseFloat *ptr = loglikes_copy.Data();
1421  std::nth_element(ptr, ptr+num_gauss-config.diag_gmm_nbest, ptr+num_gauss);
1422  BaseFloat thresh = ptr[num_gauss-config.diag_gmm_nbest];
1423  for (int32 g = 0; g < num_gauss; g++)
1424  if (loglikes(g) >= thresh) // met threshold for diagonal phase.
1425  pruned_pairs.push_back(
1426  std::make_pair(full_ubm_.ComponentLogLikelihood(data, g), g));
1427  } else {
1428  Vector<BaseFloat> loglikes(num_gauss);
1429  full_ubm_.LogLikelihoods(data, &loglikes);
1430  for (int32 g = 0; g < num_gauss; g++)
1431  pruned_pairs.push_back(std::make_pair(loglikes(g), g));
1432  }
1433  KALDI_ASSERT(!pruned_pairs.empty());
1434  if (pruned_pairs.size() > static_cast<size_t>(config.full_gmm_nbest)) {
1435  std::nth_element(pruned_pairs.begin(),
1436  pruned_pairs.end() - config.full_gmm_nbest,
1437  pruned_pairs.end());
1438  pruned_pairs.erase(pruned_pairs.begin(),
1439  pruned_pairs.end() - config.full_gmm_nbest);
1440  }
1441  Vector<BaseFloat> loglikes_tmp(pruned_pairs.size()); // for return value.
1442  KALDI_ASSERT(gselect != NULL);
1443  gselect->resize(pruned_pairs.size());
1444  // Make sure pruned Gaussians appear from best to worst.
1445  std::sort(pruned_pairs.begin(), pruned_pairs.end(),
1446  std::greater< std::pair<BaseFloat, int32> >());
1447  for (size_t i = 0; i < pruned_pairs.size(); i++) {
1448  loglikes_tmp(i) = pruned_pairs[i].first;
1449  (*gselect)[i] = pruned_pairs[i].second;
1450  }
1451  return loglikes_tmp.LogSumExp();
1452 }
int32 Dim() const
Returns the dimensionality of the Gaussian mean vectors.
Definition: diag-gmm.h:74
kaldi::int32 int32
DiagGmm diag_ubm_
These contain the "background" model associated with the subspace GMM.
Definition: am-sgmm2.h:413
float BaseFloat
Definition: kaldi-types.h:29
FullGmm full_ubm_
Definition: am-sgmm2.h:414
int32 NumGauss() const
Returns the number of mixture components in the GMM.
Definition: full-gmm.h:58
int32 NumGauss() const
Returns the number of mixture components in the GMM.
Definition: diag-gmm.h:72
void LogLikelihoods(const VectorBase< BaseFloat > &data, Vector< BaseFloat > *loglikes) const
Outputs the per-component log-likelihoods.
Definition: diag-gmm.cc:528
BaseFloat ComponentLogLikelihood(const VectorBase< BaseFloat > &data, int32 comp_id) const
Computes the contribution log-likelihood of a data point from a single Gaussian component.
Definition: full-gmm.cc:562
void LogLikelihoods(const VectorBase< BaseFloat > &data, Vector< BaseFloat > *loglikes) const
Outputs the per-component contributions to the log-likelihood.
Definition: full-gmm.cc:591
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ GetDjms()

BaseFloat GetDjms ( int32  j1,
int32  m,
Sgmm2PerSpkDerivedVars spk_vars 
) const

Definition at line 948 of file am-sgmm2.cc.

References Sgmm2PerSpkDerivedVars::b_is, kaldi::Exp(), KALDI_ASSERT, kaldi::kNoTrans, and Sgmm2PerSpkDerivedVars::log_d_jms.

Referenced by MleAmSgmm2Accs::AccumulateFromPosteriors(), and MleSgmm2SpeakerAccs::AccumulateFromPosteriors().

949  {
950  // This relates to SSGMMs (speaker-dependent weights).
951  if (spk_vars->log_d_jms.empty()) return -1; // this would be
952  // because we don't have speaker-dependent weights ("u" not set up).
953 
954  KALDI_ASSERT(!w_jmi_.empty() && "You need to call ComputeWeights() on SGMM.");
955  Vector<BaseFloat> &log_d = spk_vars->log_d_jms[j1];
956  if (log_d.Dim() == 0) {
957  log_d.Resize(NumSubstatesForGroup(j1));
958  log_d.AddMatVec(1.0, w_jmi_[j1], kNoTrans, spk_vars->b_is, 0.0);
959  log_d.ApplyLog();
960  }
961  return Exp(log_d(m));
962 }
double Exp(double x)
Definition: kaldi-math.h:83
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
int32 NumSubstatesForGroup(int32 j1) const
Definition: am-sgmm2.h:357
std::vector< Matrix< BaseFloat > > w_jmi_
[SSGMM] w_{jmi}, dimension is [J1][#mix][I]. Computed from w_ and v_.
Definition: am-sgmm2.h:442

◆ GetInvCovars()

void GetInvCovars ( int32  gauss_index,
SpMatrix< Real > *  out 
) const
inline

Templated accessors (used to accumulate in different precision)

Definition at line 511 of file am-sgmm2.h.

References SpMatrix< Real >::CopyFromSp(), kaldi::kUndefined, and SpMatrix< Real >::Resize().

Referenced by kaldi::CalcFmllrStepSize(), and FmllrSgmm2Accs::FmllrObjGradient().

512  {
513  out->Resize(SigmaInv_[gauss_index].NumRows(), kUndefined);
514  out->CopyFromSp(SigmaInv_[gauss_index]);
515 }
std::vector< SpMatrix< BaseFloat > > SigmaInv_
Globally shared parameters of the subspace GMM.
Definition: am-sgmm2.h:423

◆ GetNtransSigmaInv()

template void GetNtransSigmaInv ( std::vector< Matrix< Real > > *  out) const

Definition at line 1084 of file am-sgmm2.cc.

References MatrixBase< Real >::CopyFromMat(), MatrixBase< Real >::CopyFromSp(), rnnlm::i, KALDI_ASSERT, kaldi::kNoTrans, and kaldi::kTrans.

Referenced by MleSgmm2SpeakerAccs::MleSgmm2SpeakerAccs().

1084  {
1085  KALDI_ASSERT(SpkSpaceDim() > 0 &&
1086  "Cannot compute N^{T} \\Sigma_{i}^{-1} without speaker projections.");
1087  out->resize(NumGauss());
1088  Matrix<Real> tmpcov(FeatureDim(), FeatureDim());
1089  Matrix<Real> tmp_n(FeatureDim(), SpkSpaceDim());
1090  for (int32 i = 0; i < NumGauss(); i++) {
1091  tmpcov.CopyFromSp(SigmaInv_[i]);
1092  tmp_n.CopyFromMat(N_[i]);
1093  (*out)[i].Resize(SpkSpaceDim(), FeatureDim());
1094  (*out)[i].AddMatMat(1.0, tmp_n, kTrans, tmpcov, kNoTrans, 0.0);
1095  }
1096 }
kaldi::int32 int32
std::vector< Matrix< BaseFloat > > N_
Speaker-subspace projections. Dimension is [I][D][T].
Definition: am-sgmm2.h:427
int32 FeatureDim() const
Definition: am-sgmm2.h:363
std::vector< SpMatrix< BaseFloat > > SigmaInv_
Globally shared parameters of the subspace GMM.
Definition: am-sgmm2.h:423
int32 NumGauss() const
Definition: am-sgmm2.h:360
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
int32 SpkSpaceDim() const
Definition: am-sgmm2.h:362

◆ GetSubstateMean()

void GetSubstateMean ( int32  j1,
int32  m,
int32  i,
VectorBase< Real > *  mean_out 
) const
inline

Definition at line 519 of file am-sgmm2.h.

References VectorBase< Real >::CopyFromVec(), VectorBase< Real >::Dim(), KALDI_ASSERT, and kaldi::kNoTrans.

Referenced by MleAmSgmm2Accs::AccumulateFromPosteriors(), and MleSgmm2SpeakerAccs::AccumulateFromPosteriors().

520  {
521  KALDI_ASSERT(mean_out != NULL);
523  && i < NumGauss());
524  KALDI_ASSERT(mean_out->Dim() == FeatureDim());
525  Vector<BaseFloat> mean_tmp(FeatureDim());
526  mean_tmp.AddMatVec(1.0, M_[i], kNoTrans, v_[j1].Row(m), 0.0);
527  mean_out->CopyFromVec(mean_tmp);
528 }
std::vector< Matrix< BaseFloat > > v_
The parameters in a particular SGMM state.
Definition: am-sgmm2.h:436
std::vector< Matrix< BaseFloat > > M_
Phonetic-subspace projections. Dimension is [I][D][S].
Definition: am-sgmm2.h:425
int32 FeatureDim() const
Definition: am-sgmm2.h:363
int32 NumGroups() const
Definition: am-sgmm2.h:351
int32 NumGauss() const
Definition: am-sgmm2.h:360
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
int32 NumSubstatesForGroup(int32 j1) const
Definition: am-sgmm2.h:357

◆ GetSubstateSpeakerMean()

void GetSubstateSpeakerMean ( int32  j1,
int32  substate,
int32  gauss,
const Sgmm2PerSpkDerivedVars spk,
VectorBase< Real > *  mean_out 
) const
inline

Definition at line 532 of file am-sgmm2.h.

References VectorBase< Real >::AddVec(), Sgmm2PerSpkDerivedVars::o_s, MatrixBase< Real >::Row(), and Sgmm2PerSpkDerivedVars::v_s.

534  {
535  GetSubstateMean(j1, m, i, mean_out);
536  if (spk.v_s.Dim() != 0) // have speaker adaptation...
537  mean_out->AddVec(1.0, spk.o_s.Row(i));
538 }
void GetSubstateMean(int32 j1, int32 m, int32 i, VectorBase< Real > *mean_out) const
Definition: am-sgmm2.h:519

◆ GetVarScaledSubstateSpeakerMean()

void GetVarScaledSubstateSpeakerMean ( int32  j1,
int32  substate,
int32  gauss,
const Sgmm2PerSpkDerivedVars spk,
VectorBase< Real > *  mean_out 
) const

Definition at line 541 of file am-sgmm2.h.

References kaldi::ComputeFeatureNormalizingTransform(), VectorBase< Real >::CopyFromVec(), and VectorBase< Real >::Dim().

Referenced by FmllrSgmm2Accs::AccumulateFromPosteriors().

543  {
544  Vector<BaseFloat> tmp_mean(mean_out->Dim()), tmp_mean2(mean_out->Dim());
545  GetSubstateSpeakerMean(j1, m, i, spk, &tmp_mean);
546  tmp_mean2.AddSpVec(1.0, SigmaInv_[i], tmp_mean, 0.0);
547  mean_out->CopyFromVec(tmp_mean2);
548 }
void GetSubstateSpeakerMean(int32 j1, int32 substate, int32 gauss, const Sgmm2PerSpkDerivedVars &spk, VectorBase< Real > *mean_out) const
Definition: am-sgmm2.h:532
std::vector< SpMatrix< BaseFloat > > SigmaInv_
Globally shared parameters of the subspace GMM.
Definition: am-sgmm2.h:423

◆ HasSpeakerDependentWeights()

bool HasSpeakerDependentWeights ( ) const
inline

True if doing SSGMM.

Definition at line 366 of file am-sgmm2.h.

Referenced by main(), MleSgmm2SpeakerAccs::MleSgmm2SpeakerAccs(), MleAmSgmm2Accs::ResizeAccumulators(), and EbwAmSgmm2Updater::UpdateW().

366 { return (u_.NumRows() != 0); }
Matrix< BaseFloat > u_
[SSGMM] Speaker-subspace weight projection vectors. Dimension is [I][T]
Definition: am-sgmm2.h:431
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ HasSpeakerSpace()

bool HasSpeakerSpace ( ) const
inline

Definition at line 368 of file am-sgmm2.h.

Referenced by main().

368 { return (!N_.empty()); }
std::vector< Matrix< BaseFloat > > N_
Speaker-subspace projections. Dimension is [I][D][T].
Definition: am-sgmm2.h:427

◆ IncreasePhoneSpaceDim()

void IncreasePhoneSpaceDim ( int32  target_dim,
const Matrix< BaseFloat > &  norm_xform 
)

Functions for increasing the phonetic and speaker space dimensions.

The argument norm_xform is a LDA-like feature normalizing transform, computed by the ComputeFeatureNormalizingTransform function.

Definition at line 699 of file am-sgmm2.cc.

References MatrixBase< Real >::CopyFromMat(), rnnlm::i, KALDI_ASSERT, KALDI_ERR, KALDI_LOG, KALDI_WARN, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), MatrixBase< Real >::Range(), and Matrix< Real >::Resize().

Referenced by main().

700  {
701  KALDI_ASSERT(!M_.empty());
702  int32 initial_dim = PhoneSpaceDim(),
703  feat_dim = FeatureDim();
704  KALDI_ASSERT(norm_xform.NumRows() == feat_dim);
705 
706  if (target_dim < initial_dim)
707  KALDI_ERR << "You asked to increase phn dim to a value lower than the "
708  << " current dimension, " << target_dim << " < " << initial_dim;
709 
710  if (target_dim > initial_dim + feat_dim) {
711  KALDI_WARN << "Cannot increase phone subspace dimensionality from "
712  << initial_dim << " to " << target_dim << ", increasing to "
713  << initial_dim + feat_dim;
714  target_dim = initial_dim + feat_dim;
715  }
716 
717  if (initial_dim < target_dim) {
718  Matrix<BaseFloat> tmp_M(feat_dim, initial_dim);
719  for (int32 i = 0; i < NumGauss(); i++) {
720  tmp_M.CopyFromMat(M_[i]);
721  M_[i].Resize(feat_dim, target_dim);
722  M_[i].Range(0, feat_dim, 0, tmp_M.NumCols()).CopyFromMat(tmp_M);
723  M_[i].Range(0, feat_dim, tmp_M.NumCols(),
724  target_dim - tmp_M.NumCols()).CopyFromMat(norm_xform.Range(0,
725  feat_dim, 0, target_dim-tmp_M.NumCols()));
726  }
727  Matrix<BaseFloat> tmp_w = w_;
728  w_.Resize(tmp_w.NumRows(), target_dim);
729  w_.Range(0, tmp_w.NumRows(), 0, tmp_w.NumCols()).CopyFromMat(tmp_w);
730 
731  for (int32 j1 = 0; j1 < NumGroups(); j1++) {
732  // Resize phonetic-subspce vectors.
733  Matrix<BaseFloat> tmp_v_j = v_[j1];
734  v_[j1].Resize(tmp_v_j.NumRows(), target_dim);
735  v_[j1].Range(0, tmp_v_j.NumRows(), 0, tmp_v_j.NumCols()).CopyFromMat(
736  tmp_v_j);
737  }
738  KALDI_LOG << "Phone subspace dimensionality increased from " <<
739  initial_dim << " to " << target_dim;
740  } else {
741  KALDI_LOG << "Phone subspace dimensionality unchanged, since target " <<
742  "dimension (" << target_dim << ") <= initial dimansion (" <<
743  initial_dim << ")";
744  }
745 }
Matrix< BaseFloat > w_
Phonetic-subspace weight projection vectors. Dimension is [I][S].
Definition: am-sgmm2.h:429
kaldi::int32 int32
int32 PhoneSpaceDim() const
Definition: am-sgmm2.h:361
std::vector< Matrix< BaseFloat > > v_
The parameters in a particular SGMM state.
Definition: am-sgmm2.h:436
std::vector< Matrix< BaseFloat > > M_
Phonetic-subspace projections. Dimension is [I][D][S].
Definition: am-sgmm2.h:425
int32 FeatureDim() const
Definition: am-sgmm2.h:363
int32 NumGroups() const
Definition: am-sgmm2.h:351
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
int32 NumGauss() const
Definition: am-sgmm2.h:360
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
SubMatrix< Real > Range(const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Return a sub-part of matrix.
Definition: kaldi-matrix.h:202
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).
#define KALDI_LOG
Definition: kaldi-error.h:153

◆ IncreaseSpkSpaceDim()

void IncreaseSpkSpaceDim ( int32  target_dim,
const Matrix< BaseFloat > &  norm_xform,
bool  speaker_dependent_weights 
)

Increase the subspace dimension for speakers.

The boolean "speaker_dependent_weights" argument (for SSGMM) only makes a difference if increasing the subspace dimension from zero.

Definition at line 747 of file am-sgmm2.cc.

References MatrixBase< Real >::CopyFromMat(), rnnlm::i, KALDI_ASSERT, KALDI_ERR, KALDI_LOG, KALDI_WARN, kaldi::kCopyData, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and MatrixBase< Real >::Range().

Referenced by main().

749  {
750  int32 initial_dim = SpkSpaceDim(),
751  feat_dim = FeatureDim();
752  KALDI_ASSERT(norm_xform.NumRows() == feat_dim);
753 
754  if (N_.size() == 0)
755  N_.resize(NumGauss());
756 
757  if (target_dim < initial_dim)
758  KALDI_ERR << "You asked to increase spk dim to a value lower than the "
759  << " current dimension, " << target_dim << " < " << initial_dim;
760 
761  if (target_dim > initial_dim + feat_dim) {
762  KALDI_WARN << "Cannot increase speaker subspace dimensionality from "
763  << initial_dim << " to " << target_dim << ", increasing to "
764  << initial_dim + feat_dim;
765  target_dim = initial_dim + feat_dim;
766  }
767 
768  if (initial_dim < target_dim) {
769  int32 dim_change = target_dim - initial_dim;
770  Matrix<BaseFloat> tmp_N((initial_dim != 0) ? feat_dim : 0,
771  initial_dim);
772  for (int32 i = 0; i < NumGauss(); i++) {
773  if (initial_dim != 0) tmp_N.CopyFromMat(N_[i]);
774  N_[i].Resize(feat_dim, target_dim);
775  if (initial_dim != 0) {
776  N_[i].Range(0, feat_dim, 0, tmp_N.NumCols()).CopyFromMat(tmp_N);
777  }
778  N_[i].Range(0, feat_dim, tmp_N.NumCols(), dim_change).CopyFromMat(
779  norm_xform.Range(0, feat_dim, 0, dim_change));
780  }
781  // if we already have speaker-dependent weights or we are increasing
782  // spk-dim from zero and are asked to add them...
783  if (u_.NumRows() != 0 || (initial_dim == 0 && speaker_dependent_weights))
784  u_.Resize(NumGauss(), target_dim, kCopyData); // extend dim of u_i's
785  KALDI_LOG << "Speaker subspace dimensionality increased from " <<
786  initial_dim << " to " << target_dim;
787  if (initial_dim == 0 && speaker_dependent_weights)
788  KALDI_LOG << "Added parameters u for speaker-dependent weights.";
789  } else {
790  KALDI_LOG << "Speaker subspace dimensionality unchanged, since target " <<
791  "dimension (" << target_dim << ") <= initial dimansion (" <<
792  initial_dim << ")";
793  }
794 }
Matrix< BaseFloat > u_
[SSGMM] Speaker-subspace weight projection vectors. Dimension is [I][T]
Definition: am-sgmm2.h:431
kaldi::int32 int32
std::vector< Matrix< BaseFloat > > N_
Speaker-subspace projections. Dimension is [I][D][T].
Definition: am-sgmm2.h:427
int32 FeatureDim() const
Definition: am-sgmm2.h:363
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
int32 NumGauss() const
Definition: am-sgmm2.h:360
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
SubMatrix< Real > Range(const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Return a sub-part of matrix.
Definition: kaldi-matrix.h:202
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).
int32 SpkSpaceDim() const
Definition: am-sgmm2.h:362
#define KALDI_LOG
Definition: kaldi-error.h:153

◆ InitializeCovars()

void InitializeCovars ( )
private

initializes the within-class covariances.

Definition at line 1248 of file am-sgmm2.cc.

References rnnlm::i.

1248  {
1249  std::vector< SpMatrix<BaseFloat> > &inv_covars(full_ubm_.inv_covars());
1250  int32 num_gauss = full_ubm_.NumGauss();
1251  int32 dim = full_ubm_.Dim();
1252  SigmaInv_.resize(num_gauss);
1253  for (int32 i = 0; i < num_gauss; i++) {
1254  SigmaInv_[i].Resize(dim);
1255  SigmaInv_[i].CopyFromSp(inv_covars[i]);
1256  }
1257 }
const std::vector< SpMatrix< BaseFloat > > & inv_covars() const
Definition: full-gmm.h:146
int32 Dim() const
Returns the dimensionality of the Gaussian mean vectors.
Definition: full-gmm.h:60
kaldi::int32 int32
std::vector< SpMatrix< BaseFloat > > SigmaInv_
Globally shared parameters of the subspace GMM.
Definition: am-sgmm2.h:423
FullGmm full_ubm_
Definition: am-sgmm2.h:414
int32 NumGauss() const
Returns the number of mixture components in the GMM.
Definition: full-gmm.h:58

◆ InitializeFromFullGmm()

void InitializeFromFullGmm ( const FullGmm gmm,
const std::vector< int32 > &  pdf2group,
int32  phn_subspace_dim,
int32  spk_subspace_dim,
bool  speaker_dependent_weights,
BaseFloat  self_weight 
)

Initializes the SGMM parameters from a full-covariance UBM.

The state2group vector maps from a state to the corresponding cluster of states [i.e. j2 to j1]. For conventionally structured systems (no 2-level tree), this can just be [ 0 1 ... n-1 ].

Definition at line 381 of file am-sgmm2.cc.

References kaldi::ComputeFeatureNormalizingTransform(), FullGmm::Dim(), KALDI_ASSERT, KALDI_LOG, and KALDI_WARN.

Referenced by main(), TestSgmm2Fmllr(), TestSgmm2Init(), UnitTestEstimateSgmm2(), and UnitTestSgmm2().

386  {
387  pdf2group_ = pdf2group;
389  full_ubm_.CopyFromFullGmm(full_gmm);
390  diag_ubm_.CopyFromFullGmm(full_gmm);
391  if (phn_subspace_dim < 1 || phn_subspace_dim > full_gmm.Dim() + 1) {
392  KALDI_WARN << "Initial phone-subspace dimension must be >= 1, value is "
393  << phn_subspace_dim << "; setting to " << full_gmm.Dim() + 1;
394  phn_subspace_dim = full_gmm.Dim() + 1;
395  }
396  KALDI_ASSERT(spk_subspace_dim >= 0);
397 
398  w_.Resize(0, 0);
399  N_.clear();
400  c_.clear();
401  v_.clear();
402  SigmaInv_.clear();
403 
404  KALDI_LOG << "Initializing model";
405  Matrix<BaseFloat> norm_xform;
406  ComputeFeatureNormalizingTransform(full_gmm, &norm_xform);
407  InitializeMw(phn_subspace_dim, norm_xform);
408  if (spk_subspace_dim > 0)
409  InitializeNu(spk_subspace_dim, norm_xform, speaker_dependent_weights);
411  KALDI_LOG << "Initializing variances";
413 }
std::vector< int32 > pdf2group_
Definition: am-sgmm2.h:409
std::vector< Vector< BaseFloat > > c_
c_{jm}, mixture weights. Dimension is [J2][#mix]
Definition: am-sgmm2.h:438
Matrix< BaseFloat > w_
Phonetic-subspace weight projection vectors. Dimension is [I][S].
Definition: am-sgmm2.h:429
DiagGmm diag_ubm_
These contain the "background" model associated with the subspace GMM.
Definition: am-sgmm2.h:413
std::vector< Matrix< BaseFloat > > N_
Speaker-subspace projections. Dimension is [I][D][T].
Definition: am-sgmm2.h:427
std::vector< Matrix< BaseFloat > > v_
The parameters in a particular SGMM state.
Definition: am-sgmm2.h:436
void InitializeCovars()
initializes the within-class covariances.
Definition: am-sgmm2.cc:1248
void InitializeVecsAndSubstateWeights(BaseFloat self_weight)
Definition: am-sgmm2.cc:1207
void CopyFromFullGmm(const FullGmm &fullgmm)
Copies from given FullGmm.
Definition: full-gmm.cc:65
std::vector< SpMatrix< BaseFloat > > SigmaInv_
Globally shared parameters of the subspace GMM.
Definition: am-sgmm2.h:423
FullGmm full_ubm_
Definition: am-sgmm2.h:414
#define KALDI_WARN
Definition: kaldi-error.h:150
void InitializeNu(int32 spk_subspace_dim, const Matrix< BaseFloat > &norm_xform, bool speaker_dependent_weights)
Initializes the matrices N_ and [if speaker_dependent_weights==true] u_.
Definition: am-sgmm2.cc:1155
void ComputePdfMappings()
Definition: am-sgmm2.cc:72
void CopyFromFullGmm(const FullGmm &fullgmm)
Copies from given FullGmm.
Definition: diag-gmm.cc:92
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
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).
void ComputeFeatureNormalizingTransform(const FullGmm &gmm, Matrix< BaseFloat > *xform)
Computes the inverse of an LDA transform (without dimensionality reduction) The computed transform is...
Definition: am-sgmm2.cc:1297
#define KALDI_LOG
Definition: kaldi-error.h:153
void InitializeMw(int32 phn_subspace_dim, const Matrix< BaseFloat > &norm_xform)
Initializes the matrices M_ and w_.
Definition: am-sgmm2.cc:1126

◆ InitializeMw()

void InitializeMw ( int32  phn_subspace_dim,
const Matrix< BaseFloat > &  norm_xform 
)
private

Initializes the matrices M_ and w_.

Definition at line 1126 of file am-sgmm2.cc.

References MatrixBase< Real >::CopyColFromVec(), rnnlm::i, KALDI_ASSERT, kaldi::kNoTrans, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), MatrixBase< Real >::Range(), and Matrix< Real >::Resize().

1127  {
1128  int32 ddim = full_ubm_.Dim();
1129  KALDI_ASSERT(phn_subspace_dim <= ddim + 1);
1130  KALDI_ASSERT(phn_subspace_dim <= norm_xform.NumCols() + 1);
1131  KALDI_ASSERT(ddim <= norm_xform.NumRows());
1132 
1133  Vector<BaseFloat> mean(ddim);
1134  int32 num_gauss = full_ubm_.NumGauss();
1135  w_.Resize(num_gauss, phn_subspace_dim);
1136  M_.resize(num_gauss);
1137  for (int32 i = 0; i < num_gauss; i++) {
1138  full_ubm_.GetComponentMean(i, &mean);
1139  Matrix<BaseFloat> &thisM(M_[i]);
1140  thisM.Resize(ddim, phn_subspace_dim);
1141  // Eq. (27): M_{i} = [ \bar{\mu}_{i} (J)_{1:D, 1:(S-1)}]
1142  thisM.CopyColFromVec(mean, 0);
1143  int32 nonrandom_dim = std::min(phn_subspace_dim - 1, ddim),
1144  random_dim = phn_subspace_dim - 1 - nonrandom_dim;
1145  thisM.Range(0, ddim, 1, nonrandom_dim).CopyFromMat(
1146  norm_xform.Range(0, ddim, 0, nonrandom_dim), kNoTrans);
1147  // The following extension to the original paper allows us to
1148  // initialize the model with a larger dimension of phone-subspace vector.
1149  if (random_dim > 0)
1150  thisM.Range(0, ddim, nonrandom_dim + 1, random_dim).SetRandn();
1151  }
1152 }
int32 Dim() const
Returns the dimensionality of the Gaussian mean vectors.
Definition: full-gmm.h:60
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
Matrix< BaseFloat > w_
Phonetic-subspace weight projection vectors. Dimension is [I][S].
Definition: am-sgmm2.h:429
kaldi::int32 int32
std::vector< Matrix< BaseFloat > > M_
Phonetic-subspace projections. Dimension is [I][D][S].
Definition: am-sgmm2.h:425
FullGmm full_ubm_
Definition: am-sgmm2.h:414
int32 NumGauss() const
Returns the number of mixture components in the GMM.
Definition: full-gmm.h:58
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
SubMatrix< Real > Range(const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Return a sub-part of matrix.
Definition: kaldi-matrix.h:202
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).
void GetComponentMean(int32 gauss, VectorBase< Real > *out) const
Accessor for component mean.
Definition: full-gmm-inl.h:151

◆ InitializeNu()

void InitializeNu ( int32  spk_subspace_dim,
const Matrix< BaseFloat > &  norm_xform,
bool  speaker_dependent_weights 
)
private

Initializes the matrices N_ and [if speaker_dependent_weights==true] u_.

Definition at line 1155 of file am-sgmm2.cc.

References rnnlm::i, kaldi::kNoTrans, and MatrixBase< Real >::Range().

1157  {
1158  int32 ddim = full_ubm_.Dim();
1159 
1160  int32 num_gauss = full_ubm_.NumGauss();
1161  N_.resize(num_gauss);
1162  for (int32 i = 0; i < num_gauss; i++) {
1163  N_[i].Resize(ddim, spk_subspace_dim);
1164  // Eq. (28): N_{i} = [ (J)_{1:D, 1:T)}]
1165 
1166  int32 nonrandom_dim = std::min(spk_subspace_dim, ddim),
1167  random_dim = spk_subspace_dim - nonrandom_dim;
1168 
1169  N_[i].Range(0, ddim, 0, nonrandom_dim).
1170  CopyFromMat(norm_xform.Range(0, ddim, 0, nonrandom_dim), kNoTrans);
1171  // The following extension to the original paper allows us to
1172  // initialize the model with a larger dimension of speaker-subspace vector.
1173  if (random_dim > 0)
1174  N_[i].Range(0, ddim, nonrandom_dim, random_dim).SetRandn();
1175  }
1176  if (speaker_dependent_weights) {
1177  u_.Resize(num_gauss, spk_subspace_dim); // will set to zero.
1178  } else {
1179  u_.Resize(0, 0);
1180  }
1181 }
Matrix< BaseFloat > u_
[SSGMM] Speaker-subspace weight projection vectors. Dimension is [I][T]
Definition: am-sgmm2.h:431
int32 Dim() const
Returns the dimensionality of the Gaussian mean vectors.
Definition: full-gmm.h:60
kaldi::int32 int32
std::vector< Matrix< BaseFloat > > N_
Speaker-subspace projections. Dimension is [I][D][T].
Definition: am-sgmm2.h:427
FullGmm full_ubm_
Definition: am-sgmm2.h:414
int32 NumGauss() const
Returns the number of mixture components in the GMM.
Definition: full-gmm.h:58
SubMatrix< Real > Range(const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Return a sub-part of matrix.
Definition: kaldi-matrix.h:202
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).

◆ InitializeVecsAndSubstateWeights()

void InitializeVecsAndSubstateWeights ( BaseFloat  self_weight)
private

Definition at line 1207 of file am-sgmm2.cc.

References KALDI_ASSERT.

1207  {
1208  int32 J1 = NumGroups(), J2 = NumPdfs();
1209  KALDI_ASSERT(J1 > 0 && J2 >= J1);
1210  int32 phn_subspace_dim = PhoneSpaceDim();
1211  KALDI_ASSERT(phn_subspace_dim > 0 && "Initialize M and w first.");
1212 
1213  v_.resize(J1);
1214  if (self_weight == 1.0) {
1215  for (int32 j1 = 0; j1 < J1; j1++) {
1216  v_[j1].Resize(1, phn_subspace_dim);
1217  v_[j1](0, 0) = 1.0; // Eq. (26): v_{j1} = [1 0 0 ... 0]
1218  }
1219  c_.resize(J2);
1220  for (int32 j2 = 0; j2 < J2; j2++) {
1221  c_[j2].Resize(1);
1222  c_[j2](0) = 1.0; // Eq. (25): c_{j1} = 1.0
1223  }
1224  } else {
1225  for (int32 j1 = 0; j1 < J1; j1++) {
1226  int32 npdfs = group2pdf_[j1].size();
1227  v_[j1].Resize(npdfs, phn_subspace_dim);
1228  for (int32 m = 0; m < npdfs; m++)
1229  v_[j1](m, 0) = 1.0; // Eq. (26): v_{j1} = [1 0 0 ... 0]
1230  }
1231  c_.resize(J2);
1232  for (int32 j2 = 0; j2 < J2; j2++) {
1233  int32 j1 = pdf2group_[j2], npdfs = group2pdf_[j1].size();
1234  c_[j2].Resize(npdfs);
1235  if (npdfs == 1) c_[j2].Set(1.0);
1236  else {
1237  // note: just avoid NaNs if npdfs-1... value won't matter.
1238  double other_weight = (1.0 - self_weight) / std::max((1-npdfs), 1);
1239  c_[j2].Set(other_weight);
1240  for (int32 k = 0; k < npdfs; k++)
1241  if(group2pdf_[j1][k] == j2) c_[j2](k) = self_weight;
1242  }
1243  }
1244  }
1245 }
std::vector< int32 > pdf2group_
Definition: am-sgmm2.h:409
std::vector< Vector< BaseFloat > > c_
c_{jm}, mixture weights. Dimension is [J2][#mix]
Definition: am-sgmm2.h:438
kaldi::int32 int32
int32 PhoneSpaceDim() const
Definition: am-sgmm2.h:361
std::vector< Matrix< BaseFloat > > v_
The parameters in a particular SGMM state.
Definition: am-sgmm2.h:436
int32 NumGroups() const
Definition: am-sgmm2.h:351
int32 NumPdfs() const
Various model dimensions.
Definition: am-sgmm2.h:350
std::vector< std::vector< int32 > > group2pdf_
Definition: am-sgmm2.h:410
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( AmSgmm2  )
private

maps from each pdf (index j2) to the corresponding group of pdfs (index j1) for SCTM.

◆ LogLikelihood()

BaseFloat LogLikelihood ( const Sgmm2PerFrameDerivedVars per_frame_vars,
int32  j2,
Sgmm2LikelihoodCache cache,
Sgmm2PerSpkDerivedVars spk_vars,
BaseFloat  log_prune = 0.0 
) const

This does a likelihood computation for a given state using the pre-selected Gaussian components (in per_frame_vars).

If the log_prune parameter is nonzero (e.g. 5.0), the LogSumExp() stage is pruned, which is a significant speedup... smaller values are faster. Note: you have to call cache->NextFrame() before calling this for a new frame of data.

Definition at line 517 of file am-sgmm2.cc.

References MatrixBase< Real >::Add(), MatrixBase< Real >::ApplyExp(), kaldi::ApproxEqual(), KALDI_ASSERT, Sgmm2LikelihoodCache::SubstateCacheElement::likes, kaldi::Log(), Sgmm2LikelihoodCache::PdfCacheElement::log_like, MatrixBase< Real >::Max(), MatrixBase< Real >::NumCols(), Sgmm2LikelihoodCache::pdf_cache, kaldi::Rand(), Sgmm2LikelihoodCache::SubstateCacheElement::remaining_log_like, Sgmm2LikelihoodCache::substate_cache, Sgmm2LikelihoodCache::SubstateCacheElement::t, Sgmm2LikelihoodCache::PdfCacheElement::t, Sgmm2LikelihoodCache::t, and kaldi::VecVec().

Referenced by DecodableAmSgmm2::LogLikelihoodForPdf(), TestSgmm2AccsIO(), TestSgmm2FmllrAccsIO(), TestSgmm2IncreaseDim(), TestSgmm2Init(), TestSgmm2IO(), and TestSgmm2Substates().

521  {
522  int32 t = cache->t; // not a real time; used to uniquely identify frames.
523  // Forgo asserts here, as this is frequently called.
524  // We'll probably get a segfault if an error is made.
525  Sgmm2LikelihoodCache::PdfCacheElement &pdf_cache =
526  cache->pdf_cache[j2];
527 #ifdef KALDI_PARANOID
528  bool random_test = (Rand() % 1000 == 1); // to check that the user is
529  // calling Next() on the cache, as they should.
530 #else
531  bool random_test = false; // compiler will ignore test branches.
532 #endif
533  if (pdf_cache.t == t) {
534  if (!random_test) return pdf_cache.log_like;
535  } else {
536  random_test = false;
537  }
538  // if random_test == true at this point, it was already cached, and we will
539  // verify that we return the same value as the cached one.
540  pdf_cache.t = t;
541 
542  int32 j1 = pdf2group_[j2];
543  Sgmm2LikelihoodCache::SubstateCacheElement &substate_cache =
544  cache->substate_cache[j1];
545  if (substate_cache.t != t) { // Need to compute sub-state likelihoods.
546  substate_cache.t = t;
547  Matrix<BaseFloat> loglikes; // indexed [gselect-index][substate-index]
548  ComponentLogLikes(per_frame_vars, j1, spk_vars, &loglikes);
549  BaseFloat max = loglikes.Max(); // use this to keep things in good numerical range.
550  loglikes.Add(-max);
551  loglikes.ApplyExp();
552  substate_cache.remaining_log_like = max;
553  int32 num_substates = loglikes.NumCols();
554  substate_cache.likes.Resize(num_substates); // zeroes it.
555  substate_cache.likes.AddRowSumMat(1.0, loglikes); // add likelihoods [not in log!] for
556  // each column [i.e. summing over the rows], so we get the sum for
557  // each substate index. You have to multiply by exp(remaining_log_like)
558  // to get a real likelihood.
559  }
560 
561  BaseFloat log_like = substate_cache.remaining_log_like
562  + Log(VecVec(substate_cache.likes, c_[j2]));
563 
564  if (random_test)
565  KALDI_ASSERT(ApproxEqual(pdf_cache.log_like, log_like));
566 
567  pdf_cache.log_like = log_like;
568  KALDI_ASSERT(log_like == log_like && log_like - log_like == 0); // check
569  // that it's not NaN or infinity.
570  return log_like;
571 }
std::vector< int32 > pdf2group_
Definition: am-sgmm2.h:409
std::vector< Vector< BaseFloat > > c_
c_{jm}, mixture weights. Dimension is [J2][#mix]
Definition: am-sgmm2.h:438
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
double Log(double x)
Definition: kaldi-math.h:100
void ComponentLogLikes(const Sgmm2PerFrameDerivedVars &per_frame_vars, int32 j1, Sgmm2PerSpkDerivedVars *spk_vars, Matrix< BaseFloat > *loglikes) const
The code below is called internally from LogLikelihood() and ComponentPosteriors().
Definition: am-sgmm2.cc:476
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).
Definition: kaldi-math.h:265

◆ NumGauss()

◆ NumGroups()

int32 NumGroups ( ) const
inline

Definition at line 351 of file am-sgmm2.h.

Referenced by MleAmSgmm2Accs::Check(), main(), MleAmSgmm2Accs::ResizeAccumulators(), TestSgmm2AccsIO(), TestSgmm2FmllrAccsIO(), TestSgmm2IncreaseDim(), TestSgmm2Init(), TestSgmm2IO(), and TestSgmm2Substates().

351 { return group2pdf_.size(); } // relates to SCTM. # pdf groups,
std::vector< std::vector< int32 > > group2pdf_
Definition: am-sgmm2.h:410

◆ NumPdfs()

int32 NumPdfs ( ) const
inline

◆ NumSubstatesForGroup()

◆ NumSubstatesForPdf()

int32 NumSubstatesForPdf ( int32  j2) const
inline

Definition at line 354 of file am-sgmm2.h.

References KALDI_ASSERT.

Referenced by MleSgmm2SpeakerAccs::AccumulateFromPosteriors(), MleAmSgmm2Accs::Check(), main(), MleAmSgmm2Accs::ResizeAccumulators(), EbwAmSgmm2Updater::UpdateSubstateWeights(), and MleAmSgmm2Updater::UpdateSubstateWeights().

354  {
355  KALDI_ASSERT(j2 < NumPdfs()); return c_[j2].Dim();
356  }
std::vector< Vector< BaseFloat > > c_
c_{jm}, mixture weights. Dimension is [J2][#mix]
Definition: am-sgmm2.h:438
int32 NumPdfs() const
Various model dimensions.
Definition: am-sgmm2.h:350
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ Pdf2Group()

int32 Pdf2Group ( int32  j2) const

Definition at line 196 of file am-sgmm2.cc.

References KALDI_ASSERT.

Referenced by FmllrSgmm2Accs::AccumulateFromPosteriors(), MleAmSgmm2Accs::AccumulateFromPosteriors(), MleSgmm2SpeakerAccs::AccumulateFromPosteriors(), and TestSgmm2Init().

196  {
197  KALDI_ASSERT(static_cast<size_t>(j2) < pdf2group_.size());
198  int32 j1 = pdf2group_[j2];
199  return j1;
200 }
std::vector< int32 > pdf2group_
Definition: am-sgmm2.h:409
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ PhoneSpaceDim()

int32 PhoneSpaceDim ( ) const
inline

Definition at line 361 of file am-sgmm2.h.

Referenced by MleAmSgmm2Accs::Check(), MleAmSgmm2Updater::ComputeMPrior(), main(), MleAmSgmm2Updater::MapUpdateM(), MleAmSgmm2Accs::ResizeAccumulators(), TestSgmm2AccsIO(), TestSgmm2FmllrAccsIO(), TestSgmm2FmllrSubspace(), TestSgmm2IncreaseDim(), TestSgmm2Init(), TestSgmm2IO(), and EbwAmSgmm2Updater::UpdateM().

361 { return w_.NumCols(); }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
Matrix< BaseFloat > w_
Phonetic-subspace weight projection vectors. Dimension is [I][S].
Definition: am-sgmm2.h:429

◆ Read()

void Read ( std::istream &  is,
bool  binary 
)

Definition at line 89 of file am-sgmm2.cc.

References kaldi::ExpectToken(), rnnlm::i, KALDI_ASSERT, KALDI_ERR, KALDI_WARN, kaldi::ReadBasicType(), kaldi::ReadIntegerVector(), and kaldi::ReadToken().

Referenced by main(), and TestSgmm2IO().

89  {
90  { // We want this to work even if the object was previously
91  // populated, so we clear the items that are more likely
92  // to cause problems.
93  pdf2group_.clear();
94  group2pdf_.clear();
95  u_.Resize(0,0);
96  w_jmi_.clear();
97  v_.clear();
98  }
99  // removing anything that was in the object before.
100  int32 num_pdfs = -1, feat_dim, num_gauss;
101  std::string token;
102 
103  ExpectToken(in_stream, binary, "<SGMM>");
104  ExpectToken(in_stream, binary, "<NUMSTATES>");
105  ReadBasicType(in_stream, binary, &num_pdfs);
106  ExpectToken(in_stream, binary, "<DIMENSION>");
107  ReadBasicType(in_stream, binary, &feat_dim);
108  ExpectToken(in_stream, binary, "<NUMGAUSS>");
109  ReadBasicType(in_stream, binary, &num_gauss);
110 
111  KALDI_ASSERT(num_pdfs > 0 && feat_dim > 0);
112 
113  ReadToken(in_stream, binary, &token);
114 
115  while (token != "</SGMM>") {
116  if (token == "<PDF2GROUP>") {
117  ReadIntegerVector(in_stream, binary, &pdf2group_);
119  } else if (token == "<WEIGHTIDX2GAUSS>") { // TEMP! Will remove.
120  std::vector<int32> garbage;
121  ReadIntegerVector(in_stream, binary, &garbage);
122  } else if (token == "<DIAG_UBM>") {
123  diag_ubm_.Read(in_stream, binary);
124  } else if (token == "<FULL_UBM>") {
125  full_ubm_.Read(in_stream, binary);
126  } else if (token == "<SigmaInv>") {
127  SigmaInv_.resize(num_gauss);
128  for (int32 i = 0; i < num_gauss; i++) {
129  SigmaInv_[i].Read(in_stream, binary);
130  }
131  } else if (token == "<M>") {
132  M_.resize(num_gauss);
133  for (int32 i = 0; i < num_gauss; i++) {
134  M_[i].Read(in_stream, binary);
135  }
136  } else if (token == "<N>") {
137  N_.resize(num_gauss);
138  for (int32 i = 0; i < num_gauss; i++) {
139  N_[i].Read(in_stream, binary);
140  }
141  } else if (token == "<w>") {
142  w_.Read(in_stream, binary);
143  } else if (token == "<u>") {
144  u_.Read(in_stream, binary);
145  } else if (token == "<v>") {
146  int32 num_groups = group2pdf_.size();
147  if (num_groups == 0) {
148  KALDI_WARN << "Reading old model with new code (should still work)";
149  num_groups = num_pdfs;
150  }
151  v_.resize(num_groups);
152  for (int32 j1 = 0; j1 < num_groups; j1++) {
153  v_[j1].Read(in_stream, binary);
154  }
155  } else if (token == "<c>") {
156  c_.resize(num_pdfs);
157  for (int32 j2 = 0; j2 < num_pdfs; j2++) {
158  c_[j2].Read(in_stream, binary);
159  }
160  } else if (token == "<n>") {
161  int32 num_groups = group2pdf_.size();
162  if (num_groups == 0) num_groups = num_pdfs;
163  n_.resize(num_groups);
164  for (int32 j1 = 0; j1 < num_groups; j1++) {
165  n_[j1].Read(in_stream, binary);
166  }
167  // The following are the Gaussian prior parameters for MAP adaptation of M
168  // They may be moved to somewhere else eventually.
169  } else if (token == "<M_Prior>") {
170  ExpectToken(in_stream, binary, "<NUMGaussians>");
171  ReadBasicType(in_stream, binary, &num_gauss);
172  M_prior_.resize(num_gauss);
173  for (int32 i = 0; i < num_gauss; i++) {
174  M_prior_[i].Read(in_stream, binary);
175  }
176  } else if (token == "<Row_Cov_Inv>") {
177  row_cov_inv_.Read(in_stream, binary);
178  } else if (token == "<Col_Cov_Inv>") {
179  col_cov_inv_.Read(in_stream, binary);
180  } else {
181  KALDI_ERR << "Unexpected token '" << token << "' in model file ";
182  }
183  ReadToken(in_stream, binary, &token);
184  }
185 
186  if (pdf2group_.empty())
187  ComputePdfMappings(); // sets up group2pdf_, and pdf2group_ if reading
188  // old model.
189 
190  if (n_.empty())
193  ComputeWeights();
194 }
void ComputeWeights()
Computes the weights w_jmi_, which is needed for likelihood evaluation with SSGMMs.
Definition: am-sgmm2.cc:796
Matrix< BaseFloat > u_
[SSGMM] Speaker-subspace weight projection vectors. Dimension is [I][T]
Definition: am-sgmm2.h:431
std::vector< int32 > pdf2group_
Definition: am-sgmm2.h:409
std::vector< Vector< BaseFloat > > c_
c_{jm}, mixture weights. Dimension is [J2][#mix]
Definition: am-sgmm2.h:438
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
Matrix< BaseFloat > w_
Phonetic-subspace weight projection vectors. Dimension is [I][S].
Definition: am-sgmm2.h:429
kaldi::int32 int32
DiagGmm diag_ubm_
These contain the "background" model associated with the subspace GMM.
Definition: am-sgmm2.h:413
std::vector< Matrix< BaseFloat > > n_
n_{jim}, per-Gaussian normalizer. Dimension is [J1][I][#mix]
Definition: am-sgmm2.h:440
std::vector< Matrix< BaseFloat > > N_
Speaker-subspace projections. Dimension is [I][D][T].
Definition: am-sgmm2.h:427
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
SpMatrix< BaseFloat > col_cov_inv_
Definition: am-sgmm2.h:451
std::vector< Matrix< BaseFloat > > v_
The parameters in a particular SGMM state.
Definition: am-sgmm2.h:436
std::vector< Matrix< BaseFloat > > M_
Phonetic-subspace projections. Dimension is [I][D][S].
Definition: am-sgmm2.h:425
void Read(std::istream &in, bool binary, bool add=false)
read from stream.
void ReadIntegerVector(std::istream &is, bool binary, std::vector< T > *v)
Function for reading STL vector of integer types.
Definition: io-funcs-inl.h:232
std::vector< SpMatrix< BaseFloat > > SigmaInv_
Globally shared parameters of the subspace GMM.
Definition: am-sgmm2.h:423
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
std::vector< Matrix< BaseFloat > > M_prior_
Definition: am-sgmm2.h:449
FullGmm full_ubm_
Definition: am-sgmm2.h:414
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
void ComputePdfMappings()
Definition: am-sgmm2.cc:72
void Read(std::istream &is, bool binary)
Definition: full-gmm.cc:813
SpMatrix< BaseFloat > row_cov_inv_
Definition: am-sgmm2.h:450
void Read(std::istream &in, bool binary)
Definition: diag-gmm.cc:728
std::vector< std::vector< int32 > > group2pdf_
Definition: am-sgmm2.h:410
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void ComputeNormalizers()
Computes the data-independent terms in the log-likelihood computation for each Gaussian component and...
Definition: am-sgmm2.cc:857
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).
bool HasSpeakerDependentWeights() const
True if doing SSGMM.
Definition: am-sgmm2.h:366
std::vector< Matrix< BaseFloat > > w_jmi_
[SSGMM] w_{jmi}, dimension is [J1][#mix][I]. Computed from w_ and v_.
Definition: am-sgmm2.h:442

◆ RemoveSpeakerSpace()

void RemoveSpeakerSpace ( )
inline

Definition at line 370 of file am-sgmm2.h.

Referenced by main().

370 { N_.clear(); u_.Resize(0, 0); w_jmi_.clear(); }
Matrix< BaseFloat > u_
[SSGMM] Speaker-subspace weight projection vectors. Dimension is [I][T]
Definition: am-sgmm2.h:431
std::vector< Matrix< BaseFloat > > N_
Speaker-subspace projections. Dimension is [I][D][T].
Definition: am-sgmm2.h:427
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).
std::vector< Matrix< BaseFloat > > w_jmi_
[SSGMM] w_{jmi}, dimension is [J1][#mix][I]. Computed from w_ and v_.
Definition: am-sgmm2.h:442

◆ SpkSpaceDim()

int32 SpkSpaceDim ( ) const
inline

Definition at line 362 of file am-sgmm2.h.

Referenced by MleSgmm2SpeakerAccs::AccumulateFromPosteriors(), MleAmSgmm2Accs::Check(), main(), MleSgmm2SpeakerAccs::MleSgmm2SpeakerAccs(), MleAmSgmm2Accs::ResizeAccumulators(), and TestSgmm2Init().

362 { return (N_.size() > 0) ? N_[0].NumCols() : 0; }
std::vector< Matrix< BaseFloat > > N_
Speaker-subspace projections. Dimension is [I][D][T].
Definition: am-sgmm2.h:427

◆ SplitSubstates()

void SplitSubstates ( const Vector< BaseFloat > &  state_occupancies,
const Sgmm2SplitSubstatesConfig config 
)

Increases the total number of substates based on the state occupancies.

Definition at line 657 of file am-sgmm2.cc.

References SpMatrix< Real >::ApplyPow(), VectorBase< Real >::Dim(), kaldi::GetSplitTargets(), KALDI_ASSERT, KALDI_LOG, Sgmm2SplitSubstatesConfig::max_cond, Sgmm2SplitSubstatesConfig::min_count, Sgmm2SplitSubstatesConfig::power, and Sgmm2SplitSubstatesConfig::split_substates.

Referenced by main(), and TestSgmm2Substates().

658  {
659  KALDI_ASSERT(pdf_occupancies.Dim() == NumPdfs());
660  int32 J1 = NumGroups(), J2 = NumPdfs();
661  Vector<BaseFloat> group_occupancies(J1);
662  for (int32 j2 = 0; j2 < J2; j2++)
663  group_occupancies(Pdf2Group(j2)) += pdf_occupancies(j2);
664 
665  vector<int32> tgt_num_substates;
666 
667  GetSplitTargets(group_occupancies, opts.split_substates,
668  opts.power, opts.min_count, &tgt_num_substates);
669 
670  int32 tot_num_substates_old = 0, tot_num_substates_new = 0;
671  vector< SpMatrix<BaseFloat> > H_i;
672  SpMatrix<BaseFloat> sqrt_H_sm;
673 
674  ComputeH(&H_i); // set up that array.
675  ComputeHsmFromModel(H_i, pdf_occupancies, &sqrt_H_sm, opts.max_cond);
676  H_i.clear();
677  sqrt_H_sm.ApplyPow(-0.5);
678 
679  for (int32 j1 = 0; j1 < J1; j1++) {
680  int32 cur_M = NumSubstatesForGroup(j1),
681  tgt_M = tgt_num_substates[j1];
682  tot_num_substates_old += cur_M;
683  tot_num_substates_new += std::max(cur_M, tgt_M);
684  if (cur_M < tgt_M)
685  SplitSubstatesInGroup(pdf_occupancies, opts, sqrt_H_sm, j1, tgt_M);
686  }
687  if (tot_num_substates_old == tot_num_substates_new) {
688  KALDI_LOG << "Not splitting substates; current #substates is "
689  << tot_num_substates_old << " and target is "
690  << opts.split_substates;
691  } else {
692  KALDI_LOG << "Getting rid of normalizers as they will no longer be valid";
693  n_.clear();
694  KALDI_LOG << "Split " << tot_num_substates_old << " substates to "
695  << tot_num_substates_new;
696  }
697 }
kaldi::int32 int32
std::vector< Matrix< BaseFloat > > n_
n_{jim}, per-Gaussian normalizer. Dimension is [J1][I][#mix]
Definition: am-sgmm2.h:440
void ComputeHsmFromModel(const std::vector< SpMatrix< BaseFloat > > &H, const Vector< BaseFloat > &state_occupancies, SpMatrix< BaseFloat > *H_sm, BaseFloat max_cond) const
Definition: am-sgmm2.cc:1260
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...
int32 NumGroups() const
Definition: am-sgmm2.h:351
int32 Pdf2Group(int32 j2) const
Definition: am-sgmm2.cc:196
void SplitSubstatesInGroup(const Vector< BaseFloat > &pdf_occupancies, const Sgmm2SplitSubstatesConfig &opts, const SpMatrix< BaseFloat > &sqrt_H_sm, int32 j1, int32 M)
Called inside SplitSubstates(); splits substates of one group.
Definition: am-sgmm2.cc:599
int32 NumPdfs() const
Various model dimensions.
Definition: am-sgmm2.h:350
void ComputeH(std::vector< SpMatrix< Real > > *H_i) const
Computes quantities H = M_i Sigma_i^{-1} M_i^T.
Definition: am-sgmm2.cc:1107
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define KALDI_LOG
Definition: kaldi-error.h:153
int32 NumSubstatesForGroup(int32 j1) const
Definition: am-sgmm2.h:357

◆ SplitSubstatesInGroup()

void SplitSubstatesInGroup ( const Vector< BaseFloat > &  pdf_occupancies,
const Sgmm2SplitSubstatesConfig opts,
const SpMatrix< BaseFloat > &  sqrt_H_sm,
int32  j1,
int32  M 
)
private

Called inside SplitSubstates(); splits substates of one group.

Definition at line 599 of file am-sgmm2.cc.

References kaldi::_RandGauss(), VectorBase< Real >::AddRowSumMat(), VectorBase< Real >::AddSpVec(), VectorBase< Real >::Data(), rnnlm::i, KALDI_ASSERT, Sgmm2SplitSubstatesConfig::perturb_factor, and MatrixBase< Real >::Row().

603  {
604  const std::vector<int32> &pdfs = group2pdf_[j1];
605  int32 phn_dim = PhoneSpaceDim(), cur_M = NumSubstatesForGroup(j1),
606  num_pdfs_for_group = pdfs.size();
607  Vector<BaseFloat> rand_vec(phn_dim), v_shift(phn_dim);
608 
609  KALDI_ASSERT(tgt_M >= cur_M);
610  if (cur_M == tgt_M) return;
611  // Resize v[j1] to fit new substates
612  {
613  Matrix<BaseFloat> tmp_v_j(v_[j1]);
614  v_[j1].Resize(tgt_M, phn_dim);
615  v_[j1].Range(0, cur_M, 0, phn_dim).CopyFromMat(tmp_v_j);
616  }
617 
618  // we'll use a temporary matrix for the c quantities.
619  Matrix<BaseFloat> c_j(num_pdfs_for_group, tgt_M);
620  for (int32 i = 0; i < num_pdfs_for_group; i++) {
621  int32 j2 = pdfs[i];
622  c_j.Row(i).Range(0, cur_M).CopyFromVec(c_[j2]);
623  }
624 
625  // Keep splitting substates until obtaining the desired number
626  for (; cur_M < tgt_M; cur_M++) {
627  int32 split_m; // substate to split.
628  {
629  Vector<BaseFloat> substate_count(tgt_M);
630  substate_count.AddRowSumMat(1.0, c_j);
631  BaseFloat *data = substate_count.Data();
632  split_m = std::max_element(data, data+cur_M) - data;
633  }
634  for (int32 i = 0; i < num_pdfs_for_group; i++) { // divide count of split
635  // substate. [extended for SCTM]
636  // c_{jkm} := c_{jmk}' := c_{jkm} / 2
637  c_j(i, split_m) = c_j(i, cur_M) = c_j(i, split_m) / 2;
638  }
639  // v_{jkm} := +/- split_perturb * H_k^{(sm)}^{-0.5} * rand_vec
640  std::generate(rand_vec.Data(), rand_vec.Data() + rand_vec.Dim(),
641  _RandGauss);
642  v_shift.AddSpVec(opts.perturb_factor, sqrt_H_sm, rand_vec, 0.0);
643  v_[j1].Row(cur_M).CopyFromVec(v_[j1].Row(split_m));
644  v_[j1].Row(cur_M).AddVec(1.0, v_shift);
645  v_[j1].Row(split_m).AddVec(-1.0, v_shift);
646  }
647  // copy the temporary matrix for the c_ (sub-state weight)
648  // quantities back to the place it belongs.
649  for (int32 i = 0; i < num_pdfs_for_group; i++) {
650  int32 j2 = pdfs[i];
651  c_[j2].Resize(tgt_M);
652  c_[j2].CopyFromVec(c_j.Row(i));
653  }
654 }
std::vector< Vector< BaseFloat > > c_
c_{jm}, mixture weights. Dimension is [J2][#mix]
Definition: am-sgmm2.h:438
kaldi::int32 int32
int32 PhoneSpaceDim() const
Definition: am-sgmm2.h:361
std::vector< Matrix< BaseFloat > > v_
The parameters in a particular SGMM state.
Definition: am-sgmm2.h:436
static float _RandGauss()
Definition: am-sgmm2.cc:34
float BaseFloat
Definition: kaldi-types.h:29
std::vector< std::vector< int32 > > group2pdf_
Definition: am-sgmm2.h:410
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
int32 NumSubstatesForGroup(int32 j1) const
Definition: am-sgmm2.h:357

◆ Write()

void Write ( std::ostream &  os,
bool  binary,
SgmmWriteFlagsType  write_params 
) const

Definition at line 203 of file am-sgmm2.cc.

References rnnlm::i, KALDI_WARN, kaldi::kSgmmBackgroundGmms, kaldi::kSgmmGlobalParams, kaldi::kSgmmNormalizers, kaldi::kSgmmStateParams, kaldi::WriteBasicType(), kaldi::WriteIntegerVector(), and kaldi::WriteToken().

Referenced by main(), TestSgmm2AccsIO(), and TestSgmm2IO().

205  {
206  int32 num_pdfs = NumPdfs(),
207  feat_dim = FeatureDim(),
208  num_gauss = NumGauss();
209 
210  WriteToken(out_stream, binary, "<SGMM>");
211  if (!binary) out_stream << "\n";
212  WriteToken(out_stream, binary, "<NUMSTATES>");
213  WriteBasicType(out_stream, binary, num_pdfs);
214  WriteToken(out_stream, binary, "<DIMENSION>");
215  WriteBasicType(out_stream, binary, feat_dim);
216  WriteToken(out_stream, binary, "<NUMGAUSS>");
217  WriteBasicType(out_stream, binary, num_gauss);
218  if (!binary) out_stream << "\n";
219 
220  if (write_params & kSgmmBackgroundGmms) {
221  WriteToken(out_stream, binary, "<DIAG_UBM>");
222  diag_ubm_.Write(out_stream, binary);
223  WriteToken(out_stream, binary, "<FULL_UBM>");
224  full_ubm_.Write(out_stream, binary);
225  }
226 
227  if (write_params & kSgmmGlobalParams) {
228  WriteToken(out_stream, binary, "<SigmaInv>");
229  if (!binary) out_stream << "\n";
230  for (int32 i = 0; i < num_gauss; i++) {
231  SigmaInv_[i].Write(out_stream, binary);
232  }
233  WriteToken(out_stream, binary, "<M>");
234  if (!binary) out_stream << "\n";
235  for (int32 i = 0; i < num_gauss; i++) {
236  M_[i].Write(out_stream, binary);
237  }
238  if (N_.size() != 0) {
239  WriteToken(out_stream, binary, "<N>");
240  if (!binary) out_stream << "\n";
241  for (int32 i = 0; i < num_gauss; i++) {
242  N_[i].Write(out_stream, binary);
243  }
244  }
245  WriteToken(out_stream, binary, "<w>");
246  w_.Write(out_stream, binary);
247  WriteToken(out_stream, binary, "<u>");
248  u_.Write(out_stream, binary);
249  }
250 
251  if (write_params & kSgmmStateParams) {
252  WriteToken(out_stream, binary, "<PDF2GROUP>");
253  WriteIntegerVector(out_stream, binary, pdf2group_);
254  WriteToken(out_stream, binary, "<v>");
255  for (int32 j1 = 0; j1 < NumGroups(); j1++) {
256  v_[j1].Write(out_stream, binary);
257  }
258  WriteToken(out_stream, binary, "<c>");
259  for (int32 j2 = 0; j2 < num_pdfs; j2++) {
260  c_[j2].Write(out_stream, binary);
261  }
262  }
263 
264  if (write_params & kSgmmNormalizers) {
265  WriteToken(out_stream, binary, "<n>");
266  if (n_.empty())
267  KALDI_WARN << "Not writing normalizers since they are not present.";
268  else
269  for (int32 j1 = 0; j1 < NumGroups(); j1++)
270  n_[j1].Write(out_stream, binary);
271  }
272  WriteToken(out_stream, binary, "</SGMM>");
273 }
void Write(std::ostream &os, bool binary, SgmmWriteFlagsType write_params) const
Definition: am-sgmm2.cc:203
Matrix< BaseFloat > u_
[SSGMM] Speaker-subspace weight projection vectors. Dimension is [I][T]
Definition: am-sgmm2.h:431
void Write(std::ostream &out, bool binary) const
write to stream.
std::vector< int32 > pdf2group_
Definition: am-sgmm2.h:409
void Write(std::ostream &os, bool binary) const
Definition: diag-gmm.cc:705
std::vector< Vector< BaseFloat > > c_
c_{jm}, mixture weights. Dimension is [J2][#mix]
Definition: am-sgmm2.h:438
Matrix< BaseFloat > w_
Phonetic-subspace weight projection vectors. Dimension is [I][S].
Definition: am-sgmm2.h:429
kaldi::int32 int32
DiagGmm diag_ubm_
These contain the "background" model associated with the subspace GMM.
Definition: am-sgmm2.h:413
std::vector< Matrix< BaseFloat > > n_
n_{jim}, per-Gaussian normalizer. Dimension is [J1][I][#mix]
Definition: am-sgmm2.h:440
void Write(std::ostream &os, bool binary) const
Definition: full-gmm.cc:758
std::vector< Matrix< BaseFloat > > N_
Speaker-subspace projections. Dimension is [I][D][T].
Definition: am-sgmm2.h:427
std::vector< Matrix< BaseFloat > > v_
The parameters in a particular SGMM state.
Definition: am-sgmm2.h:436
std::vector< Matrix< BaseFloat > > M_
Phonetic-subspace projections. Dimension is [I][D][S].
Definition: am-sgmm2.h:425
int32 FeatureDim() const
Definition: am-sgmm2.h:363
int32 NumGroups() const
Definition: am-sgmm2.h:351
std::vector< SpMatrix< BaseFloat > > SigmaInv_
Globally shared parameters of the subspace GMM.
Definition: am-sgmm2.h:423
FullGmm full_ubm_
Definition: am-sgmm2.h:414
int32 NumPdfs() const
Various model dimensions.
Definition: am-sgmm2.h:350
#define KALDI_WARN
Definition: kaldi-error.h:150
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
Definition: am-sgmm2.h:360
void WriteIntegerVector(std::ostream &os, bool binary, const std::vector< T > &v)
Function for writing STL vectors of integer types.
Definition: io-funcs-inl.h:198
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

Friends And Related Function Documentation

◆ AmSgmm2Functions

friend class AmSgmm2Functions
friend

Definition at line 506 of file am-sgmm2.h.

◆ ComputeNormalizersClass

friend class ComputeNormalizersClass
friend

Definition at line 500 of file am-sgmm2.h.

◆ EbwAmSgmm2Updater

friend class EbwAmSgmm2Updater
friend

Definition at line 502 of file am-sgmm2.h.

◆ MleAmSgmm2Accs

friend class MleAmSgmm2Accs
friend

Definition at line 503 of file am-sgmm2.h.

◆ MleAmSgmm2Updater

friend class MleAmSgmm2Updater
friend

Definition at line 504 of file am-sgmm2.h.

◆ MleSgmm2SpeakerAccs

friend class MleSgmm2SpeakerAccs
friend

Definition at line 505 of file am-sgmm2.h.

◆ Sgmm2Feature

friend class Sgmm2Feature
friend

Definition at line 507 of file am-sgmm2.h.

◆ Sgmm2Project

friend class Sgmm2Project
friend

Definition at line 501 of file am-sgmm2.h.

Member Data Documentation

◆ c_

std::vector< Vector<BaseFloat> > c_
protected

c_{jm}, mixture weights. Dimension is [J2][#mix]

Definition at line 438 of file am-sgmm2.h.

Referenced by AmSgmm2::CopyFromSgmm2(), EbwAmSgmm2Updater::UpdateSubstateWeights(), and MleAmSgmm2Updater::UpdateSubstateWeights().

◆ col_cov_inv_

SpMatrix<BaseFloat> col_cov_inv_
protected

Definition at line 451 of file am-sgmm2.h.

Referenced by MleAmSgmm2Updater::ComputeMPrior(), and MleAmSgmm2Updater::MapUpdateM().

◆ diag_ubm_

DiagGmm diag_ubm_
protected

These contain the "background" model associated with the subspace GMM.

Definition at line 413 of file am-sgmm2.h.

Referenced by Sgmm2Project::ApplyProjection(), AmSgmm2::CopyFromSgmm2(), and AmSgmm2::CopyGlobalsInitVecs().

◆ full_ubm_

FullGmm full_ubm_
protected

◆ group2pdf_

std::vector<std::vector<int32> > group2pdf_
protected

Definition at line 410 of file am-sgmm2.h.

Referenced by AmSgmm2::CopyFromSgmm2().

◆ M_

◆ M_prior_

std::vector< Matrix<BaseFloat> > M_prior_
protected

Definition at line 449 of file am-sgmm2.h.

Referenced by MleAmSgmm2Updater::ComputeMPrior(), and MleAmSgmm2Updater::MapUpdateM().

◆ N_

◆ n_

std::vector< Matrix<BaseFloat> > n_
protected

n_{jim}, per-Gaussian normalizer. Dimension is [J1][I][#mix]

Definition at line 440 of file am-sgmm2.h.

Referenced by Sgmm2Project::ApplyProjection(), AmSgmm2::CopyFromSgmm2(), and MleAmSgmm2Updater::Update().

◆ pdf2group_

std::vector<int32> pdf2group_
protected

Definition at line 409 of file am-sgmm2.h.

Referenced by AmSgmm2::CopyFromSgmm2().

◆ row_cov_inv_

SpMatrix<BaseFloat> row_cov_inv_
protected

Definition at line 450 of file am-sgmm2.h.

Referenced by MleAmSgmm2Updater::ComputeMPrior(), and MleAmSgmm2Updater::MapUpdateM().

◆ SigmaInv_

std::vector< SpMatrix<BaseFloat> > SigmaInv_
protected

Globally shared parameters of the subspace GMM.

The various quantities are: I = number of Gaussians, D = data dimension, S = phonetic subspace dimension, T = speaker subspace dimension, J2 = number of pdfs, J1 = number of groups of pdfs (for SCTM), #mix = number of substates [of state j2 or state-group j1, depending on context]. Inverse within-class (full) covariances; dim is [I][D][D].

Definition at line 423 of file am-sgmm2.h.

Referenced by Sgmm2Project::ApplyProjection(), AmSgmm2::CopyFromSgmm2(), AmSgmm2::CopyGlobalsInitVecs(), MleAmSgmm2Updater::MapUpdateM(), MleSgmm2SpeakerAccs::MleSgmm2SpeakerAccs(), EbwAmSgmm2Updater::UpdateM(), MleAmSgmm2Updater::UpdateM(), EbwAmSgmm2Updater::UpdateN(), MleAmSgmm2Updater::UpdateN(), EbwAmSgmm2Updater::UpdateVars(), and MleAmSgmm2Updater::UpdateVars().

◆ u_

Matrix<BaseFloat> u_
protected

[SSGMM] Speaker-subspace weight projection vectors. Dimension is [I][T]

Definition at line 431 of file am-sgmm2.h.

Referenced by AmSgmm2::CopyFromSgmm2(), AmSgmm2::CopyGlobalsInitVecs(), EbwAmSgmm2Updater::UpdateU(), MleAmSgmm2Updater::UpdateU(), and MleSgmm2SpeakerAccs::UpdateWithU().

◆ v_

◆ w_

◆ w_jmi_

std::vector< Matrix<BaseFloat> > w_jmi_
protected

[SSGMM] w_{jmi}, dimension is [J1][#mix][I]. Computed from w_ and v_.

Definition at line 442 of file am-sgmm2.h.

Referenced by MleAmSgmm2Accs::AccumulateFromPosteriors(), MleSgmm2SpeakerAccs::AccumulateFromPosteriors(), AmSgmm2::CopyFromSgmm2(), MleAmSgmm2Updater::Update(), and MleAmSgmm2Updater::UpdateW().


The documentation for this class was generated from the following files: