IvectorExtractor Class Reference

#include <ivector-extractor.h>

Collaboration diagram for IvectorExtractor:

Public Member Functions

 IvectorExtractor ()
 
 IvectorExtractor (const IvectorExtractorOptions &opts, const FullGmm &fgmm)
 
void GetIvectorDistribution (const IvectorExtractorUtteranceStats &utt_stats, VectorBase< double > *mean, SpMatrix< double > *var) const
 Gets the distribution over ivectors (or at least, a Gaussian approximation to it). More...
 
double PriorOffset () const
 The distribution over iVectors, in our formulation, is not centered at zero; its first dimension has a nonzero offset. More...
 
double GetAuxf (const IvectorExtractorUtteranceStats &utt_stats, const VectorBase< double > &mean, const SpMatrix< double > *var=NULL) const
 Returns the log-likelihood objective function, summed over frames, for this distribution of iVectors (a point distribution, if var == NULL). More...
 
double GetAcousticAuxf (const IvectorExtractorUtteranceStats &utt_stats, const VectorBase< double > &mean, const SpMatrix< double > *var=NULL) const
 Returns the data-dependent part of the log-likelihood objective function, summed over frames. More...
 
double GetPriorAuxf (const VectorBase< double > &mean, const SpMatrix< double > *var=NULL) const
 Returns the prior-related part of the log-likelihood objective function. More...
 
double GetAcousticAuxfVariance (const IvectorExtractorUtteranceStats &utt_stats) const
 This returns just the part of the acoustic auxf that relates to the variance of the utt_stats (i.e. More...
 
double GetAcousticAuxfMean (const IvectorExtractorUtteranceStats &utt_stats, const VectorBase< double > &mean, const SpMatrix< double > *var=NULL) const
 This returns just the part of the acoustic auxf that relates to the speaker-dependent means (and how they differ from the data means). More...
 
double GetAcousticAuxfGconst (const IvectorExtractorUtteranceStats &utt_stats) const
 This returns the part of the acoustic auxf that relates to the gconsts of the Gaussians. More...
 
double GetAcousticAuxfWeight (const IvectorExtractorUtteranceStats &utt_stats, const VectorBase< double > &mean, const SpMatrix< double > *var=NULL) const
 This returns the part of the acoustic auxf that relates to the Gaussian-specific weights. More...
 
void GetIvectorDistMean (const IvectorExtractorUtteranceStats &utt_stats, VectorBase< double > *linear, SpMatrix< double > *quadratic) const
 Gets the linear and quadratic terms in the distribution over iVectors, but only the terms arising from the Gaussian means (i.e. More...
 
void GetIvectorDistPrior (const IvectorExtractorUtteranceStats &utt_stats, VectorBase< double > *linear, SpMatrix< double > *quadratic) const
 Gets the linear and quadratic terms in the distribution over iVectors, that arise from the prior. More...
 
void GetIvectorDistWeight (const IvectorExtractorUtteranceStats &utt_stats, const VectorBase< double > &mean, VectorBase< double > *linear, SpMatrix< double > *quadratic) const
 Gets the linear and quadratic terms in the distribution over iVectors, that arise from the weights (if applicable). More...
 
int32 FeatDim () const
 
int32 IvectorDim () const
 
int32 NumGauss () const
 
bool IvectorDependentWeights () const
 
void Write (std::ostream &os, bool binary) const
 
void Read (std::istream &is, bool binary)
 

Protected Member Functions

void ComputeDerivedVars ()
 
void ComputeDerivedVars (int32 i)
 
void TransformIvectors (const MatrixBase< double > &T, double new_prior_offset)
 

Protected Attributes

Matrix< double > w_
 Weight projection vectors, if used. Dimension is [I][S]. More...
 
Vector< double > w_vec_
 If we are not using weight-projection vectors, stores the Gaussian mixture weights from the UBM. More...
 
std::vector< Matrix< double > > M_
 Ivector-subspace projection matrices, dimension is [I][D][S]. More...
 
std::vector< SpMatrix< double > > Sigma_inv_
 Inverse variances of speaker-adapted model, dimension [I][D][D]. More...
 
double prior_offset_
 1st dim of the prior over the ivector has an offset, so it is not zero. More...
 
Vector< double > gconsts_
 The constant term in the log-likelihood of each Gaussian (not counting any weight). More...
 
Matrix< double > U_
 U_i = M_i^T ^{-1} M_i is a quantity that comes up in ivector estimation. More...
 
std::vector< Matrix< double > > Sigma_inv_M_
 The product of Sigma_inv_[i] with M_[i]. More...
 

Static Private Member Functions

static void InvertWithFlooring (const SpMatrix< double > &quadratic_term, SpMatrix< double > *var)
 

Friends

class IvectorExtractorStats
 
class OnlineIvectorEstimationStats
 
class IvectorExtractorComputeDerivedVarsClass
 

Detailed Description

Definition at line 136 of file ivector-extractor.h.

Constructor & Destructor Documentation

◆ IvectorExtractor() [1/2]

IvectorExtractor ( )
inline

Definition at line 141 of file ivector-extractor.h.

141 : prior_offset_(0.0) { }
double prior_offset_
1st dim of the prior over the ivector has an offset, so it is not zero.

◆ IvectorExtractor() [2/2]

IvectorExtractor ( const IvectorExtractorOptions opts,
const FullGmm fgmm 
)

Definition at line 137 of file ivector-extractor.cc.

References IvectorExtractor::ComputeDerivedVars(), VectorBase< Real >::CopyFromVec(), FullGmm::GetMeans(), rnnlm::i, FullGmm::inv_covars(), IvectorExtractorOptions::ivector_dim, KALDI_ASSERT, IvectorExtractor::M_, FullGmm::NumGauss(), PackedMatrix< Real >::NumRows(), IvectorExtractor::prior_offset_, Vector< Real >::Resize(), Matrix< Real >::Resize(), MatrixBase< Real >::Row(), MatrixBase< Real >::Scale(), IvectorExtractor::Sigma_inv_, IvectorExtractorOptions::use_weights, IvectorExtractor::w_, IvectorExtractor::w_vec_, and FullGmm::weights().

139  {
140  KALDI_ASSERT(opts.ivector_dim > 0);
141  Sigma_inv_.resize(fgmm.NumGauss());
142  for (int32 i = 0; i < fgmm.NumGauss(); i++) {
143  const SpMatrix<BaseFloat> &inv_var = fgmm.inv_covars()[i];
144  Sigma_inv_[i].Resize(inv_var.NumRows());
145  Sigma_inv_[i].CopyFromSp(inv_var);
146  }
147  Matrix<double> gmm_means;
148  fgmm.GetMeans(&gmm_means);
149  KALDI_ASSERT(!Sigma_inv_.empty());
150  int32 feature_dim = Sigma_inv_[0].NumRows(),
151  num_gauss = Sigma_inv_.size();
152 
153  prior_offset_ = 100.0; // hardwired for now. Must be nonzero.
154  gmm_means.Scale(1.0 / prior_offset_);
155 
156  M_.resize(num_gauss);
157  for (int32 i = 0; i < num_gauss; i++) {
158  M_[i].Resize(feature_dim, opts.ivector_dim);
159  M_[i].SetRandn();
160  M_[i].CopyColFromVec(gmm_means.Row(i), 0);
161  }
162  if (opts.use_weights) { // will regress the log-weights on the iVector.
163  w_.Resize(num_gauss, opts.ivector_dim);
164  } else {
165  w_vec_.Resize(fgmm.NumGauss());
166  w_vec_.CopyFromVec(fgmm.weights());
167  }
169 }
Vector< double > w_vec_
If we are not using weight-projection vectors, stores the Gaussian mixture weights from the UBM...
kaldi::int32 int32
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
std::vector< SpMatrix< double > > Sigma_inv_
Inverse variances of speaker-adapted model, dimension [I][D][D].
std::vector< Matrix< double > > M_
Ivector-subspace projection matrices, dimension is [I][D][S].
#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).
double prior_offset_
1st dim of the prior over the ivector has an offset, so it is not zero.
Matrix< double > w_
Weight projection vectors, if used. Dimension is [I][S].

Member Function Documentation

◆ ComputeDerivedVars() [1/2]

void ComputeDerivedVars ( )
protected

Definition at line 182 of file ivector-extractor.cc.

References IvectorExtractor::FeatDim(), kaldi::g_num_threads, IvectorExtractor::gconsts_, rnnlm::i, IvectorExtractor::IvectorDim(), KALDI_LOG, M_LOG_2PI, TaskSequencerConfig::num_threads, IvectorExtractor::NumGauss(), Vector< Real >::Resize(), Matrix< Real >::Resize(), TaskSequencer< C >::Run(), IvectorExtractor::Sigma_inv_, IvectorExtractor::Sigma_inv_M_, and IvectorExtractor::U_.

Referenced by IvectorExtractorStats::GetOrthogonalIvectorTransform(), IvectorExtractor::IvectorExtractor(), and IvectorExtractorStats::Update().

182  {
183  KALDI_LOG << "Computing derived variables for iVector extractor";
185  for (int32 i = 0; i < NumGauss(); i++) {
186  double var_logdet = -Sigma_inv_[i].LogPosDefDet();
187  gconsts_(i) = -0.5 * (var_logdet + FeatDim() * M_LOG_2PI);
188  // the gconsts don't contain any weight-related terms.
189  }
190  U_.Resize(NumGauss(), IvectorDim() * (IvectorDim() + 1) / 2);
191  Sigma_inv_M_.resize(NumGauss());
192 
193  // Note, we could have used RunMultiThreaded for this and similar tasks we
194  // have here, but we found that we don't get as complete CPU utilization as we
195  // could because some tasks finish before others.
196  {
197  TaskSequencerConfig sequencer_opts;
198  sequencer_opts.num_threads = g_num_threads;
199  TaskSequencer<IvectorExtractorComputeDerivedVarsClass> sequencer(
200  sequencer_opts);
201  for (int32 i = 0; i < NumGauss(); i++)
202  sequencer.Run(new IvectorExtractorComputeDerivedVarsClass(this, i));
203  }
204  KALDI_LOG << "Done.";
205 }
#define M_LOG_2PI
Definition: kaldi-math.h:60
Matrix< double > U_
U_i = M_i^T ^{-1} M_i is a quantity that comes up in ivector estimation.
int32 g_num_threads
Definition: kaldi-thread.cc:25
kaldi::int32 int32
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
std::vector< Matrix< double > > Sigma_inv_M_
The product of Sigma_inv_[i] with M_[i].
friend class IvectorExtractorComputeDerivedVarsClass
std::vector< SpMatrix< double > > Sigma_inv_
Inverse variances of speaker-adapted model, dimension [I][D][D].
Vector< double > gconsts_
The constant term in the log-likelihood of each Gaussian (not counting any weight).
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

◆ ComputeDerivedVars() [2/2]

void ComputeDerivedVars ( int32  i)
protected

Definition at line 208 of file ivector-extractor.cc.

References SpMatrix< Real >::AddMat2Sp(), PackedMatrix< Real >::Data(), IvectorExtractor::FeatDim(), rnnlm::i, IvectorExtractor::IvectorDim(), kaldi::kNoTrans, kaldi::kTrans, IvectorExtractor::M_, MatrixBase< Real >::Row(), IvectorExtractor::Sigma_inv_, IvectorExtractor::Sigma_inv_M_, and IvectorExtractor::U_.

208  {
209  SpMatrix<double> temp_U(IvectorDim());
210  // temp_U = M_i^T Sigma_i^{-1} M_i
211  temp_U.AddMat2Sp(1.0, M_[i], kTrans, Sigma_inv_[i], 0.0);
212  SubVector<double> temp_U_vec(temp_U.Data(),
213  IvectorDim() * (IvectorDim() + 1) / 2);
214  U_.Row(i).CopyFromVec(temp_U_vec);
215 
216  Sigma_inv_M_[i].Resize(FeatDim(), IvectorDim());
217  Sigma_inv_M_[i].AddSpMat(1.0, Sigma_inv_[i], M_[i], kNoTrans, 0.0);
218 }
Matrix< double > U_
U_i = M_i^T ^{-1} M_i is a quantity that comes up in ivector estimation.
std::vector< Matrix< double > > Sigma_inv_M_
The product of Sigma_inv_[i] with M_[i].
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
std::vector< SpMatrix< double > > Sigma_inv_
Inverse variances of speaker-adapted model, dimension [I][D][D].
std::vector< Matrix< double > > M_
Ivector-subspace projection matrices, dimension is [I][D][S].

◆ FeatDim()

◆ GetAcousticAuxf()

double GetAcousticAuxf ( const IvectorExtractorUtteranceStats utt_stats,
const VectorBase< double > &  mean,
const SpMatrix< double > *  var = NULL 
) const

Returns the data-dependent part of the log-likelihood objective function, summed over frames.

If variance pointer is NULL, uses point value.

Definition at line 419 of file ivector-extractor.cc.

References IvectorExtractorUtteranceStats::gamma_, IvectorExtractor::GetAcousticAuxfGconst(), IvectorExtractor::GetAcousticAuxfMean(), IvectorExtractor::GetAcousticAuxfVariance(), IvectorExtractor::GetAcousticAuxfWeight(), KALDI_VLOG, and VectorBase< Real >::Sum().

Referenced by IvectorExtractor::GetAuxf().

422  {
423  double weight_auxf = GetAcousticAuxfWeight(utt_stats, mean, var),
424  gconst_auxf = GetAcousticAuxfGconst(utt_stats),
425  mean_auxf = GetAcousticAuxfMean(utt_stats, mean, var),
426  var_auxf = GetAcousticAuxfVariance(utt_stats),
427  T = utt_stats.gamma_.Sum();
428  KALDI_VLOG(3) << "Per frame, auxf is: weight " << (weight_auxf/T) << ", gconst "
429  << (gconst_auxf/T) << ", mean " << (mean_auxf/T) << ", var "
430  << (var_auxf/T) << ", over " << T << " frames.";
431  return weight_auxf + gconst_auxf + mean_auxf + var_auxf;
432 }
double GetAcousticAuxfWeight(const IvectorExtractorUtteranceStats &utt_stats, const VectorBase< double > &mean, const SpMatrix< double > *var=NULL) const
This returns the part of the acoustic auxf that relates to the Gaussian-specific weights.
double GetAcousticAuxfMean(const IvectorExtractorUtteranceStats &utt_stats, const VectorBase< double > &mean, const SpMatrix< double > *var=NULL) const
This returns just the part of the acoustic auxf that relates to the speaker-dependent means (and how ...
double GetAcousticAuxfVariance(const IvectorExtractorUtteranceStats &utt_stats) const
This returns just the part of the acoustic auxf that relates to the variance of the utt_stats (i...
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
double GetAcousticAuxfGconst(const IvectorExtractorUtteranceStats &utt_stats) const
This returns the part of the acoustic auxf that relates to the gconsts of the Gaussians.

◆ GetAcousticAuxfGconst()

double GetAcousticAuxfGconst ( const IvectorExtractorUtteranceStats utt_stats) const

This returns the part of the acoustic auxf that relates to the gconsts of the Gaussians.

Definition at line 490 of file ivector-extractor.cc.

References IvectorExtractorUtteranceStats::gamma_, IvectorExtractor::gconsts_, and kaldi::VecVec().

Referenced by IvectorExtractor::GetAcousticAuxf().

491  {
492  return VecVec(Vector<double>(utt_stats.gamma_),
493  gconsts_);
494 }
Vector< double > gconsts_
The constant term in the log-likelihood of each Gaussian (not counting any weight).
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37

◆ GetAcousticAuxfMean()

double GetAcousticAuxfMean ( const IvectorExtractorUtteranceStats utt_stats,
const VectorBase< double > &  mean,
const SpMatrix< double > *  var = NULL 
) const

This returns just the part of the acoustic auxf that relates to the speaker-dependent means (and how they differ from the data means).

Definition at line 460 of file ivector-extractor.cc.

References VectorBase< Real >::AddMatVec(), VectorBase< Real >::AddSpVec(), PackedMatrix< Real >::Data(), IvectorExtractor::FeatDim(), IvectorExtractorUtteranceStats::gamma_, rnnlm::i, IvectorExtractor::IvectorDim(), kaldi::kTrans, IvectorExtractor::M_, IvectorExtractor::NumGauss(), MatrixBase< Real >::Row(), IvectorExtractor::Sigma_inv_, kaldi::TraceSpSp(), IvectorExtractor::U_, kaldi::VecSpVec(), kaldi::VecVec(), and IvectorExtractorUtteranceStats::X_.

Referenced by IvectorExtractor::GetAcousticAuxf().

463  {
464  double K = 0.0;
465  Vector<double> a(IvectorDim()), temp(FeatDim());
466 
467  int32 I = NumGauss();
468  for (int32 i = 0; i < I; i++) {
469  double gamma = utt_stats.gamma_(i);
470  if (gamma != 0.0) {
471  Vector<double> x(utt_stats.X_.Row(i)); // == \gamma(i) \m_i
472  temp.AddSpVec(1.0 / gamma, Sigma_inv_[i], x, 0.0);
473  // now temp = Sigma_i^{-1} \m_i.
474  // next line: K += -0.5 \gamma_i \m_i^T \Sigma_i^{-1} \m_i
475  K += -0.5 * VecVec(x, temp);
476  // next line: a += \gamma_i \M_i^T \Sigma_i^{-1} \m_i
477  a.AddMatVec(gamma, M_[i], kTrans, temp, 1.0);
478  }
479  }
480  SpMatrix<double> B(IvectorDim());
481  SubVector<double> B_vec(B.Data(), IvectorDim()*(IvectorDim()+1)/2);
482  B_vec.AddMatVec(1.0, U_, kTrans, Vector<double>(utt_stats.gamma_), 0.0);
483 
484  double ans = K + VecVec(mean, a) - 0.5 * VecSpVec(mean, B, mean);
485  if (var != NULL)
486  ans -= 0.5 * TraceSpSp(*var, B);
487  return ans;
488 }
Matrix< double > U_
U_i = M_i^T ^{-1} M_i is a quantity that comes up in ivector estimation.
kaldi::int32 int32
std::vector< SpMatrix< double > > Sigma_inv_
Inverse variances of speaker-adapted model, dimension [I][D][D].
double TraceSpSp(const SpMatrix< double > &A, const SpMatrix< double > &B)
Definition: sp-matrix.cc:326
Real VecSpVec(const VectorBase< Real > &v1, const SpMatrix< Real > &M, const VectorBase< Real > &v2)
Computes v1^T * M * v2.
Definition: sp-matrix.cc:964
std::vector< Matrix< double > > M_
Ivector-subspace projection matrices, dimension is [I][D][S].
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37

◆ GetAcousticAuxfVariance()

double GetAcousticAuxfVariance ( const IvectorExtractorUtteranceStats utt_stats) const

This returns just the part of the acoustic auxf that relates to the variance of the utt_stats (i.e.

which would be zero if the utt_stats had zero variance. This does not depend on the iVector, it's included as an aid to debugging. We can only get this if we stored the S statistics. If not we assume the variance is generated from the model.

Definition at line 497 of file ivector-extractor.cc.

References SpMatrix< Real >::AddVec2(), IvectorExtractor::FeatDim(), IvectorExtractorUtteranceStats::gamma_, rnnlm::i, IvectorExtractor::NumGauss(), MatrixBase< Real >::Row(), IvectorExtractorUtteranceStats::S_, PackedMatrix< Real >::Scale(), VectorBase< Real >::Scale(), IvectorExtractor::Sigma_inv_, VectorBase< Real >::Sum(), kaldi::TraceSpSp(), and IvectorExtractorUtteranceStats::X_.

Referenced by IvectorExtractor::GetAcousticAuxf().

498  {
499  if (utt_stats.S_.empty()) {
500  // we did not store the variance, so assume it's as predicted
501  // by the model itself.
502  // for each Gaussian i, we have a term -0.5 * gamma(i) * trace(Sigma[i] * Sigma[i]^{-1})
503  // = -0.5 * gamma(i) * FeatDim().
504  return -0.5 * utt_stats.gamma_.Sum() * FeatDim();
505  } else {
506  int32 I = NumGauss();
507  double ans = 0.0;
508  for (int32 i = 0; i < I; i++) {
509  double gamma = utt_stats.gamma_(i);
510  if (gamma != 0.0) {
511  SpMatrix<double> var(utt_stats.S_[i]);
512  var.Scale(1.0 / gamma);
513  Vector<double> mean(utt_stats.X_.Row(i));
514  mean.Scale(1.0 / gamma);
515  var.AddVec2(-1.0, mean); // get centered covariance..
516  ans += -0.5 * gamma * TraceSpSp(var, Sigma_inv_[i]);
517  }
518  }
519  return ans;
520  }
521 }
kaldi::int32 int32
std::vector< SpMatrix< double > > Sigma_inv_
Inverse variances of speaker-adapted model, dimension [I][D][D].
double TraceSpSp(const SpMatrix< double > &A, const SpMatrix< double > &B)
Definition: sp-matrix.cc:326

◆ GetAcousticAuxfWeight()

double GetAcousticAuxfWeight ( const IvectorExtractorUtteranceStats utt_stats,
const VectorBase< double > &  mean,
const SpMatrix< double > *  var = NULL 
) const

This returns the part of the acoustic auxf that relates to the Gaussian-specific weights.

(impacted by the iVector only if we are using w_).

Definition at line 285 of file ivector-extractor.cc.

References VectorBase< Real >::Add(), SpMatrix< Real >::AddMat2Vec(), VectorBase< Real >::AddMatVec(), MatrixBase< Real >::AddVecVec(), VectorBase< Real >::ApplyExp(), VectorBase< Real >::ApplyLog(), IvectorExtractorUtteranceStats::gamma_, IvectorExtractor::IvectorDependentWeights(), IvectorExtractor::IvectorDim(), kaldi::kNoTrans, kaldi::kTrans, VectorBase< Real >::LogSumExp(), IvectorExtractor::NumGauss(), kaldi::TraceSpSp(), kaldi::VecVec(), IvectorExtractor::w_, and IvectorExtractor::w_vec_.

Referenced by IvectorExtractor::GetAcousticAuxf().

288  {
289  if (!IvectorDependentWeights()) { // Not using the weight-projection matrices.
290  Vector<double> log_w_vec(w_vec_);
291  log_w_vec.ApplyLog();
292  return VecVec(log_w_vec, utt_stats.gamma_);
293  } else {
294  Vector<double> w(NumGauss());
295  w.AddMatVec(1.0, w_, kNoTrans, mean, 0.0); // now w is unnormalized
296  // log-weights.
297 
298  double lse = w.LogSumExp();
299  w.Add(-lse); // Normalize so log-weights sum to one.
300 
301  // "ans" below is the point-value of the weight auxf, without
302  // considering the variance. At the moment, "w" contains
303  // the normalized log weights.
304  double ans = VecVec(w, utt_stats.gamma_);
305 
306  w.ApplyExp(); // now w is the weights.
307 
308  if (var == NULL) {
309  return ans;
310  } else {
311  // Below, "Jacobian" will be the derivative d(log_w) / d(ivector)
312  // = (I - w w^T) W, where W (w_ in the code) is the projection matrix
313  // from iVector space to unnormalized log-weights, and w is the normalized
314  // weight values at the current point.
315  Matrix<double> Jacobian(w_);
316  Vector<double> WTw(IvectorDim()); // W^T w
317  WTw.AddMatVec(1.0, w_, kTrans, w, 0.0);
318  Jacobian.AddVecVec(1.0, w, WTw); // Jacobian += (w (W^T w)^T = w^T w W)
319 
320  // the matrix S is the negated 2nd derivative of the objf w.r.t. the iVector \x.
321  SpMatrix<double> S(IvectorDim());
322  S.AddMat2Vec(1.0, Jacobian, kTrans, Vector<double>(utt_stats.gamma_), 0.0);
323  ans += -0.5 * TraceSpSp(S, *var);
324  return ans;
325  }
326  }
327 }
Vector< double > w_vec_
If we are not using weight-projection vectors, stores the Gaussian mixture weights from the UBM...
bool IvectorDependentWeights() const
double TraceSpSp(const SpMatrix< double > &A, const SpMatrix< double > &B)
Definition: sp-matrix.cc:326
Matrix< double > w_
Weight projection vectors, if used. Dimension is [I][S].
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37

◆ GetAuxf()

double GetAuxf ( const IvectorExtractorUtteranceStats utt_stats,
const VectorBase< double > &  mean,
const SpMatrix< double > *  var = NULL 
) const

Returns the log-likelihood objective function, summed over frames, for this distribution of iVectors (a point distribution, if var == NULL).

Definition at line 331 of file ivector-extractor.cc.

References IvectorExtractorUtteranceStats::gamma_, IvectorExtractor::GetAcousticAuxf(), IvectorExtractor::GetPriorAuxf(), KALDI_VLOG, and VectorBase< Real >::Sum().

Referenced by IvectorExtractorStats::CommitStatsForUtterance(), IvectorExtractor::GetIvectorDistribution(), IvectorExtractTask::operator()(), kaldi::RunPerSpeaker(), and kaldi::TestIvectorExtraction().

333  {
334 
335  double acoustic_auxf = GetAcousticAuxf(utt_stats, mean, var),
336  prior_auxf = GetPriorAuxf(mean, var), num_frames = utt_stats.gamma_.Sum();
337  KALDI_VLOG(3) << "Acoustic auxf is " << (acoustic_auxf/num_frames) << "/frame over "
338  << num_frames << " frames, prior auxf is " << prior_auxf
339  << " = " << (prior_auxf/num_frames) << " per frame.";
340  return acoustic_auxf + prior_auxf;
341 }
double GetPriorAuxf(const VectorBase< double > &mean, const SpMatrix< double > *var=NULL) const
Returns the prior-related part of the log-likelihood objective function.
double GetAcousticAuxf(const IvectorExtractorUtteranceStats &utt_stats, const VectorBase< double > &mean, const SpMatrix< double > *var=NULL) const
Returns the data-dependent part of the log-likelihood objective function, summed over frames...
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156

◆ GetIvectorDistMean()

void GetIvectorDistMean ( const IvectorExtractorUtteranceStats utt_stats,
VectorBase< double > *  linear,
SpMatrix< double > *  quadratic 
) const

Gets the linear and quadratic terms in the distribution over iVectors, but only the terms arising from the Gaussian means (i.e.

not the weights or the priors). Setup is log p(x) x^T linear -0.5 x^T quadratic x. This function *adds to* the output rather than setting it.

Definition at line 257 of file ivector-extractor.cc.

References VectorBase< Real >::AddMatVec(), PackedMatrix< Real >::Data(), IvectorExtractorUtteranceStats::gamma_, rnnlm::i, IvectorExtractor::IvectorDim(), kaldi::kTrans, IvectorExtractor::NumGauss(), IvectorExtractor::Sigma_inv_M_, IvectorExtractor::U_, and IvectorExtractorUtteranceStats::X_.

Referenced by IvectorExtractor::GetIvectorDistribution().

260  {
261  int32 I = NumGauss();
262  for (int32 i = 0; i < I; i++) {
263  double gamma = utt_stats.gamma_(i);
264  if (gamma != 0.0) {
265  SubVector<double> x(utt_stats.X_, i); // == \gamma(i) \m_i
266  // next line: a += \gamma_i \M_i^T \Sigma_i^{-1} \m_i
267  linear->AddMatVec(1.0, Sigma_inv_M_[i], kTrans, x, 1.0);
268  }
269  }
270  SubVector<double> q_vec(quadratic->Data(), IvectorDim()*(IvectorDim()+1)/2);
271  q_vec.AddMatVec(1.0, U_, kTrans, utt_stats.gamma_, 1.0);
272 }
Matrix< double > U_
U_i = M_i^T ^{-1} M_i is a quantity that comes up in ivector estimation.
kaldi::int32 int32
std::vector< Matrix< double > > Sigma_inv_M_
The product of Sigma_inv_[i] with M_[i].

◆ GetIvectorDistPrior()

void GetIvectorDistPrior ( const IvectorExtractorUtteranceStats utt_stats,
VectorBase< double > *  linear,
SpMatrix< double > *  quadratic 
) const

Gets the linear and quadratic terms in the distribution over iVectors, that arise from the prior.

Adds to the outputs, rather than setting them.

The inverse-variance for the prior is the unit matrix.

Definition at line 274 of file ivector-extractor.cc.

References PackedMatrix< Real >::AddToDiag(), and IvectorExtractor::prior_offset_.

Referenced by IvectorExtractor::GetIvectorDistribution().

277  {
278 
279  (*linear)(0) += prior_offset_; // the zero'th dimension has an offset mean.
281  quadratic->AddToDiag(1.0);
282 }
void AddToDiag(const Real r)
double prior_offset_
1st dim of the prior over the ivector has an offset, so it is not zero.

◆ GetIvectorDistribution()

void GetIvectorDistribution ( const IvectorExtractorUtteranceStats utt_stats,
VectorBase< double > *  mean,
SpMatrix< double > *  var 
) const

Gets the distribution over ivectors (or at least, a Gaussian approximation to it).

The output "var" may be NULL if you don't need it. "mean", and "var", if present, must be the correct dimension (this->IvectorDim()). If you only need a point estimate of the iVector, get the mean only.

Definition at line 63 of file ivector-extractor.cc.

References VectorBase< Real >::AddSpVec(), VectorBase< Real >::AddVec(), SpMatrix< Real >::Cond(), SpMatrix< Real >::CopyFromSp(), VectorBase< Real >::CopyFromVec(), VectorBase< Real >::Dim(), IvectorExtractor::GetAuxf(), IvectorExtractor::GetIvectorDistMean(), IvectorExtractor::GetIvectorDistPrior(), IvectorExtractor::GetIvectorDistWeight(), kaldi::GetVerboseLevel(), SpMatrix< Real >::Invert(), IvectorExtractor::InvertWithFlooring(), IvectorExtractor::IvectorDependentWeights(), IvectorExtractor::IvectorDim(), KALDI_VLOG, VectorBase< Real >::Norm(), VectorBase< Real >::Range(), and SpMatrix< Real >::Trace().

Referenced by IvectorExtractorStats::CommitStatsForUtterance(), IvectorExtractTask::operator()(), kaldi::RunPerSpeaker(), and kaldi::TestIvectorExtraction().

66  {
67  if (!IvectorDependentWeights()) {
68  Vector<double> linear(IvectorDim());
69  SpMatrix<double> quadratic(IvectorDim());
70  GetIvectorDistMean(utt_stats, &linear, &quadratic);
71  GetIvectorDistPrior(utt_stats, &linear, &quadratic);
72  if (var != NULL) {
73  var->CopyFromSp(quadratic);
74  var->Invert(); // now it's a variance.
75 
76  // mean of distribution = quadratic^{-1} * linear...
77  mean->AddSpVec(1.0, *var, linear, 0.0);
78  } else {
79  quadratic.Invert();
80  mean->AddSpVec(1.0, quadratic, linear, 0.0);
81  }
82  } else {
83  Vector<double> linear(IvectorDim());
84  SpMatrix<double> quadratic(IvectorDim());
85  GetIvectorDistMean(utt_stats, &linear, &quadratic);
86  GetIvectorDistPrior(utt_stats, &linear, &quadratic);
87  // At this point, "linear" and "quadratic" contain
88  // the mean and prior-related terms, and we avoid
89  // recomputing those.
90 
91  Vector<double> cur_mean(IvectorDim());
92 
93  SpMatrix<double> quadratic_inv(IvectorDim());
94  InvertWithFlooring(quadratic, &quadratic_inv);
95  cur_mean.AddSpVec(1.0, quadratic_inv, linear, 0.0);
96 
97  KALDI_VLOG(3) << "Trace of quadratic is " << quadratic.Trace()
98  << ", condition is " << quadratic.Cond();
99  KALDI_VLOG(3) << "Trace of quadratic_inv is " << quadratic_inv.Trace()
100  << ", condition is " << quadratic_inv.Cond();
101 
102  // The loop is finding successively better approximation points
103  // for the quadratic expansion of the weights.
104  int32 num_iters = 4;
105  double change_threshold = 0.1; // If the iVector changes by less than
106  // this (in 2-norm), we abort early.
107  for (int32 iter = 0; iter < num_iters; iter++) {
108  if (GetVerboseLevel() >= 3) {
109  KALDI_VLOG(3) << "Auxf on iter " << iter << " is "
110  << GetAuxf(utt_stats, cur_mean, &quadratic_inv);
111  int32 show_dim = 5;
112  if (show_dim > cur_mean.Dim()) show_dim = cur_mean.Dim();
113  KALDI_VLOG(3) << "Current distribution mean is "
114  << cur_mean.Range(0, show_dim) << "... "
115  << ", var trace is " << quadratic_inv.Trace();
116  }
117  Vector<double> this_linear(linear);
118  SpMatrix<double> this_quadratic(quadratic);
119  GetIvectorDistWeight(utt_stats, cur_mean,
120  &this_linear, &this_quadratic);
121  InvertWithFlooring(this_quadratic, &quadratic_inv);
122  Vector<double> mean_diff(cur_mean);
123  cur_mean.AddSpVec(1.0, quadratic_inv, this_linear, 0.0);
124  mean_diff.AddVec(-1.0, cur_mean);
125  double change = mean_diff.Norm(2.0);
126  KALDI_VLOG(2) << "On iter " << iter << ", iVector changed by " << change;
127  if (change < change_threshold)
128  break;
129  }
130  mean->CopyFromVec(cur_mean);
131  if (var != NULL)
132  var->CopyFromSp(quadratic_inv);
133  }
134 }
static void InvertWithFlooring(const SpMatrix< double > &quadratic_term, SpMatrix< double > *var)
bool IvectorDependentWeights() const
int32 GetVerboseLevel()
Get verbosity level, usually set via command line &#39;–verbose=&#39; switch.
Definition: kaldi-error.h:60
double GetAuxf(const IvectorExtractorUtteranceStats &utt_stats, const VectorBase< double > &mean, const SpMatrix< double > *var=NULL) const
Returns the log-likelihood objective function, summed over frames, for this distribution of iVectors ...
kaldi::int32 int32
void CopyFromSp(const SpMatrix< Real > &other)
Definition: sp-matrix.h:85
void GetIvectorDistPrior(const IvectorExtractorUtteranceStats &utt_stats, VectorBase< double > *linear, SpMatrix< double > *quadratic) const
Gets the linear and quadratic terms in the distribution over iVectors, that arise from the prior...
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
void GetIvectorDistWeight(const IvectorExtractorUtteranceStats &utt_stats, const VectorBase< double > &mean, VectorBase< double > *linear, SpMatrix< double > *quadratic) const
Gets the linear and quadratic terms in the distribution over iVectors, that arise from the weights (i...
void GetIvectorDistMean(const IvectorExtractorUtteranceStats &utt_stats, VectorBase< double > *linear, SpMatrix< double > *quadratic) const
Gets the linear and quadratic terms in the distribution over iVectors, but only the terms arising fro...
void Invert(Real *logdet=NULL, Real *det_sign=NULL, bool inverse_needed=true)
matrix inverse.
Definition: sp-matrix.cc:219

◆ GetIvectorDistWeight()

void GetIvectorDistWeight ( const IvectorExtractorUtteranceStats utt_stats,
const VectorBase< double > &  mean,
VectorBase< double > *  linear,
SpMatrix< double > *  quadratic 
) const

Gets the linear and quadratic terms in the distribution over iVectors, that arise from the weights (if applicable).

The "mean" parameter is the iVector point that we compute the expansion around (it's a quadratic approximation of a nonlinear function, but with a "safety factor" (the "max" stuff). Adds to the outputs, rather than setting them.

Definition at line 221 of file ivector-extractor.cc.

References SpMatrix< Real >::AddMat2Vec(), VectorBase< Real >::AddMatVec(), VectorBase< Real >::ApplySoftMax(), IvectorExtractorUtteranceStats::gamma_, rnnlm::i, IvectorExtractor::IvectorDependentWeights(), kaldi::kNoTrans, kaldi::kTrans, IvectorExtractor::NumGauss(), VectorBase< Real >::Sum(), and IvectorExtractor::w_.

Referenced by IvectorExtractor::GetIvectorDistribution().

225  {
226  // If there is no w_, then weights do not depend on the iVector
227  // and the weights contribute nothing to the distribution.
229  return;
230 
231  Vector<double> logw_unnorm(NumGauss());
232  logw_unnorm.AddMatVec(1.0, w_, kNoTrans, mean, 0.0);
233 
234  Vector<double> w(logw_unnorm);
235  w.ApplySoftMax(); // now w is the weights.
236 
237  // See eq.58 in SGMM paper
238  // http://www.sciencedirect.com/science/article/pii/S088523081000063X
239  // linear_coeff(i) = \gamma_{jmi} - \gamma_{jm} \hat{w}_{jmi} + \max(\gamma_{jmi}, \gamma_{jm} \hat{w}_{jmi} \hat{\w}_i \v_{jm}
240  // here \v_{jm} corresponds to the iVector. Ignore the j,m indices.
241  Vector<double> linear_coeff(NumGauss());
242  Vector<double> quadratic_coeff(NumGauss());
243  double gamma = utt_stats.gamma_.Sum();
244  for (int32 i = 0; i < NumGauss(); i++) {
245  double gamma_i = utt_stats.gamma_(i);
246  double max_term = std::max(gamma_i, gamma * w(i));
247  linear_coeff(i) = gamma_i - gamma * w(i) + max_term * logw_unnorm(i);
248  quadratic_coeff(i) = max_term;
249  }
250  linear->AddMatVec(1.0, w_, kTrans, linear_coeff, 1.0);
251 
252  // *quadratic += \sum_i quadratic_coeff(i) w_i w_i^T, where w_i is
253  // i'th row of w_.
254  quadratic->AddMat2Vec(1.0, w_, kTrans, quadratic_coeff, 1.0);
255 }
void AddMat2Vec(const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transM, const VectorBase< Real > &v, const Real beta=0.0)
Extension of rank-N update: this <– beta*this + alpha * M * diag(v) * M^T.
Definition: sp-matrix.cc:1081
bool IvectorDependentWeights() const
kaldi::int32 int32
Matrix< double > w_
Weight projection vectors, if used. Dimension is [I][S].

◆ GetPriorAuxf()

double GetPriorAuxf ( const VectorBase< double > &  mean,
const SpMatrix< double > *  var = NULL 
) const

Returns the prior-related part of the log-likelihood objective function.

Note: if var != NULL, this quantity is a *probability*, otherwise it is a likelihood (and the corresponding probability is zero).

Definition at line 381 of file ivector-extractor.cc.

References VectorBase< Real >::Dim(), kaldi::GetLogDetNoFailure(), IvectorExtractor::IvectorDim(), KALDI_ASSERT, M_LOG_2PI, PackedMatrix< Real >::NumRows(), IvectorExtractor::prior_offset_, SpMatrix< Real >::Trace(), and kaldi::VecVec().

Referenced by IvectorExtractor::GetAuxf().

383  {
384  KALDI_ASSERT(mean.Dim() == IvectorDim());
385 
386  Vector<double> offset(mean);
387  offset(0) -= prior_offset_; // The mean of the prior distribution
388  // may only be nonzero in the first dimension. Now, "offset" is the
389  // offset of ivector from the prior's mean.
390 
391 
392  if (var == NULL) {
393  // The log-determinant of the variance of the prior distribution is one,
394  // since it's the unit matrix.
395  return -0.5 * (VecVec(offset, offset) + IvectorDim()*M_LOG_2PI);
396  } else {
397  // The mean-related part of the answer will be
398  // -0.5 * (VecVec(offset, offset), just like above.
399  // The variance-related part will be
400  // \int p(x) . -0.5 (x^T I x - x^T var^{-1} x + logdet(I) - logdet(var)) dx
401  // and using the fact that x is distributed with variance "var", this is:
402  //= \int p(x) . -0.5 (x^T I x - x^T var^{-1} x + logdet(I) - logdet(var)) dx
403  // = -0.5 ( trace(var I) - trace(var^{-1} var) + 0.0 - logdet(var))
404  // = -0.5 ( trace(var) - dim(var) - logdet(var))
405 
406  KALDI_ASSERT(var->NumRows() == IvectorDim());
407  return -0.5 * (VecVec(offset, offset) + var->Trace() -
408  IvectorDim() - GetLogDetNoFailure(*var));
409  }
410 }
static double GetLogDetNoFailure(const SpMatrix< double > &var)
#define M_LOG_2PI
Definition: kaldi-math.h:60
Real Trace() const
Definition: sp-matrix.cc:171
MatrixIndexT NumRows() const
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
double prior_offset_
1st dim of the prior over the ivector has an offset, so it is not zero.
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37

◆ InvertWithFlooring()

void InvertWithFlooring ( const SpMatrix< double > &  quadratic_term,
SpMatrix< double > *  var 
)
staticprivate

Definition at line 49 of file ivector-extractor.cc.

References SpMatrix< Real >::AddMat2Vec(), VectorBase< Real >::ApplyFloor(), SpMatrix< Real >::Eig(), VectorBase< Real >::InvertElements(), kaldi::kNoTrans, and PackedMatrix< Real >::NumRows().

Referenced by IvectorExtractor::GetIvectorDistribution(), and IvectorExtractorStats::IvectorVarianceDiagnostic().

50  {
51  SpMatrix<double> dbl_var(inverse_var);
52  int32 dim = inverse_var.NumRows();
53  Vector<double> s(dim);
54  Matrix<double> P(dim, dim);
55  // Solve the symmetric eigenvalue problem, inverse_var = P diag(s) P^T.
56  inverse_var.Eig(&s, &P);
57  s.ApplyFloor(1.0);
58  s.InvertElements();
59  var->AddMat2Vec(1.0, P, kNoTrans, s, 0.0);
60 }
void AddMat2Vec(const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transM, const VectorBase< Real > &v, const Real beta=0.0)
Extension of rank-N update: this <– beta*this + alpha * M * diag(v) * M^T.
Definition: sp-matrix.cc:1081
kaldi::int32 int32

◆ IvectorDependentWeights()

◆ IvectorDim()

◆ NumGauss()

◆ PriorOffset()

double PriorOffset ( ) const
inline

The distribution over iVectors, in our formulation, is not centered at zero; its first dimension has a nonzero offset.

This function returns that offset.

Definition at line 159 of file ivector-extractor.h.

Referenced by kaldi::EstimateIvectorsOnline(), main(), OnlineIvectorFeature::OnlineIvectorFeature(), IvectorExtractTask::operator()(), kaldi::RunPerSpeaker(), kaldi::TestIvectorExtraction(), and IvectorExtractTask::~IvectorExtractTask().

159 { return prior_offset_; }
double prior_offset_
1st dim of the prior over the ivector has an offset, so it is not zero.

◆ Read()

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

Definition at line 828 of file ivector-extractor.cc.

References kaldi::ExpectToken(), rnnlm::i, KALDI_ASSERT, OnlineIvectorEstimationStats::prior_offset_, OnlineIvectorEstimationStats::Read(), and kaldi::ReadBasicType().

Referenced by kaldi::TestIvectorExtractorIO().

828  {
829  ExpectToken(is, binary, "<IvectorExtractor>");
830  ExpectToken(is, binary, "<w>");
831  w_.Read(is, binary);
832  ExpectToken(is, binary, "<w_vec>");
833  w_vec_.Read(is, binary);
834  ExpectToken(is, binary, "<M>");
835  int32 size;
836  ReadBasicType(is, binary, &size);
837  KALDI_ASSERT(size > 0);
838  M_.resize(size);
839  for (int32 i = 0; i < size; i++)
840  M_[i].Read(is, binary);
841  ExpectToken(is, binary, "<SigmaInv>");
842  Sigma_inv_.resize(size);
843  for (int32 i = 0; i < size; i++)
844  Sigma_inv_[i].Read(is, binary);
845  ExpectToken(is, binary, "<IvectorOffset>");
846  ReadBasicType(is, binary, &prior_offset_);
847  ExpectToken(is, binary, "</IvectorExtractor>");
849 }
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
Vector< double > w_vec_
If we are not using weight-projection vectors, stores the Gaussian mixture weights from the UBM...
kaldi::int32 int32
void Read(std::istream &in, bool binary, bool add=false)
read from stream.
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< SpMatrix< double > > Sigma_inv_
Inverse variances of speaker-adapted model, dimension [I][D][D].
std::vector< Matrix< double > > M_
Ivector-subspace projection matrices, dimension is [I][D][S].
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void Read(std::istream &is, bool binary)
double prior_offset_
1st dim of the prior over the ivector has an offset, so it is not zero.
Matrix< double > w_
Weight projection vectors, if used. Dimension is [I][S].
void Read(std::istream &in, bool binary, bool add=false)
Read function using C++ streams.

◆ TransformIvectors()

void TransformIvectors ( const MatrixBase< double > &  T,
double  new_prior_offset 
)
protected

Definition at line 523 of file ivector-extractor.cc.

References MatrixBase< Real >::AddMatMat(), rnnlm::i, MatrixBase< Real >::Invert(), IvectorExtractor::IvectorDependentWeights(), KALDI_LOG, kaldi::kNoTrans, IvectorExtractor::M_, IvectorExtractor::NumGauss(), IvectorExtractor::prior_offset_, and IvectorExtractor::w_.

Referenced by IvectorExtractorStats::UpdatePrior().

524  {
525  Matrix<double> Tinv(T);
526  Tinv.Invert();
527  // w <-- w Tinv. (construct temporary copy with Matrix<double>(w))
529  w_.AddMatMat(1.0, Matrix<double>(w_), kNoTrans, Tinv, kNoTrans, 0.0);
530  // next: M_i <-- M_i Tinv. (construct temporary copy with Matrix<double>(M_[i]))
531  for (int32 i = 0; i < NumGauss(); i++)
532  M_[i].AddMatMat(1.0, Matrix<double>(M_[i]), kNoTrans, Tinv, kNoTrans, 0.0);
533  KALDI_LOG << "Setting iVector prior offset to " << new_prior_offset;
534  prior_offset_ = new_prior_offset;
535 }
bool IvectorDependentWeights() const
kaldi::int32 int32
void AddMatMat(const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta)
std::vector< Matrix< double > > M_
Ivector-subspace projection matrices, dimension is [I][D][S].
double prior_offset_
1st dim of the prior over the ivector has an offset, so it is not zero.
Matrix< double > w_
Weight projection vectors, if used. Dimension is [I][S].
#define KALDI_LOG
Definition: kaldi-error.h:153

◆ Write()

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

Definition at line 807 of file ivector-extractor.cc.

References rnnlm::i, KALDI_ASSERT, OnlineIvectorEstimationStats::prior_offset_, OnlineIvectorEstimationStats::Write(), kaldi::WriteBasicType(), and kaldi::WriteToken().

Referenced by kaldi::TestIvectorExtractorIO().

807  {
808  WriteToken(os, binary, "<IvectorExtractor>");
809  WriteToken(os, binary, "<w>");
810  w_.Write(os, binary);
811  WriteToken(os, binary, "<w_vec>");
812  w_vec_.Write(os, binary);
813  WriteToken(os, binary, "<M>");
814  int32 size = M_.size();
815  WriteBasicType(os, binary, size);
816  for (int32 i = 0; i < size; i++)
817  M_[i].Write(os, binary);
818  WriteToken(os, binary, "<SigmaInv>");
819  KALDI_ASSERT(size == static_cast<int32>(Sigma_inv_.size()));
820  for (int32 i = 0; i < size; i++)
821  Sigma_inv_[i].Write(os, binary);
822  WriteToken(os, binary, "<IvectorOffset>");
823  WriteBasicType(os, binary, prior_offset_);
824  WriteToken(os, binary, "</IvectorExtractor>");
825 }
void Write(std::ostream &out, bool binary) const
write to stream.
Vector< double > w_vec_
If we are not using weight-projection vectors, stores the Gaussian mixture weights from the UBM...
void Write(std::ostream &Out, bool binary) const
Writes to C++ stream (option to write in binary).
kaldi::int32 int32
void Write(std::ostream &os, bool binary) const
std::vector< SpMatrix< double > > Sigma_inv_
Inverse variances of speaker-adapted model, dimension [I][D][D].
std::vector< Matrix< double > > M_
Ivector-subspace projection matrices, dimension is [I][D][S].
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
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
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
double prior_offset_
1st dim of the prior over the ivector has an offset, so it is not zero.
Matrix< double > w_
Weight projection vectors, if used. Dimension is [I][S].

Friends And Related Function Documentation

◆ IvectorExtractorComputeDerivedVarsClass

Definition at line 254 of file ivector-extractor.h.

◆ IvectorExtractorStats

friend class IvectorExtractorStats
friend

Definition at line 138 of file ivector-extractor.h.

◆ OnlineIvectorEstimationStats

friend class OnlineIvectorEstimationStats
friend

Definition at line 139 of file ivector-extractor.h.

Member Data Documentation

◆ gconsts_

Vector<double> gconsts_
protected

The constant term in the log-likelihood of each Gaussian (not counting any weight).

Definition at line 291 of file ivector-extractor.h.

Referenced by IvectorExtractor::ComputeDerivedVars(), and IvectorExtractor::GetAcousticAuxfGconst().

◆ M_

std::vector<Matrix<double> > M_
protected

Ivector-subspace projection matrices, dimension is [I][D][S].

The I'th matrix projects from ivector-space to Gaussian mean. There is no mean offset to add– we deal with it by having a prior with a nonzero mean.

Definition at line 276 of file ivector-extractor.h.

Referenced by IvectorExtractor::ComputeDerivedVars(), IvectorExtractor::FeatDim(), IvectorExtractor::GetAcousticAuxfMean(), IvectorExtractor::IvectorDim(), IvectorExtractor::IvectorExtractor(), IvectorExtractorStats::IvectorVarianceDiagnostic(), IvectorExtractor::NumGauss(), IvectorExtractor::TransformIvectors(), IvectorExtractorStats::UpdateProjection(), and IvectorExtractorStats::UpdateVariances().

◆ prior_offset_

◆ Sigma_inv_

◆ Sigma_inv_M_

std::vector<Matrix<double> > Sigma_inv_M_
protected

The product of Sigma_inv_[i] with M_[i].

Definition at line 301 of file ivector-extractor.h.

Referenced by OnlineIvectorEstimationStats::AccStats(), IvectorExtractor::ComputeDerivedVars(), and IvectorExtractor::GetIvectorDistMean().

◆ U_

Matrix<double> U_
protected

U_i = M_i^T ^{-1} M_i is a quantity that comes up in ivector estimation.

This is conceptually a std::vector<SpMatrix<double> >, but we store the packed-data in the rows of a matrix, which gives us an efficiency improvement (we can use matrix-multiplies).

Definition at line 298 of file ivector-extractor.h.

Referenced by OnlineIvectorEstimationStats::AccStats(), IvectorExtractor::ComputeDerivedVars(), IvectorExtractor::GetAcousticAuxfMean(), IvectorExtractor::GetIvectorDistMean(), and IvectorExtractorStats::GetOrthogonalIvectorTransform().

◆ w_

◆ w_vec_

Vector<double> w_vec_
protected

If we are not using weight-projection vectors, stores the Gaussian mixture weights from the UBM.

This does not affect the iVector; it is only useful as a way of making sure the log-probs are comparable between systems with and without weight projection matrices.

Definition at line 270 of file ivector-extractor.h.

Referenced by IvectorExtractor::GetAcousticAuxfWeight(), IvectorExtractorStats::GetOrthogonalIvectorTransform(), and IvectorExtractor::IvectorExtractor().


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