#include <plda.h>
Public Member Functions | |
Plda () | |
Plda (const Plda &other) | |
double | TransformIvector (const PldaConfig &config, const VectorBase< double > &ivector, int32 num_enroll_examples, VectorBase< double > *transformed_ivector) const |
Transforms an iVector into a space where the within-class variance is unit and between-class variance is diagonalized. More... | |
float | TransformIvector (const PldaConfig &config, const VectorBase< float > &ivector, int32 num_enroll_examples, VectorBase< float > *transformed_ivector) const |
float version of the above (not BaseFloat because we'd be implementing it twice for the same type if BaseFloat == double). More... | |
double | LogLikelihoodRatio (const VectorBase< double > &transformed_enroll_ivector, int32 num_enroll_utts, const VectorBase< double > &transformed_test_ivector) const |
Returns the log-likelihood ratio log (p(test_ivector | same) / p(test_ivector | different)). More... | |
void | SmoothWithinClassCovariance (double smoothing_factor) |
This function smooths the within-class covariance by adding to it, smoothing_factor (e.g. More... | |
void | ApplyTransform (const Matrix< double > &in_transform) |
Apply a transform to the PLDA model. More... | |
int32 | Dim () const |
void | Write (std::ostream &os, bool binary) const |
void | Read (std::istream &is, bool binary) |
Protected Member Functions | |
void | ComputeDerivedVars () |
Protected Attributes | |
Vector< double > | mean_ |
Matrix< double > | transform_ |
Vector< double > | psi_ |
Vector< double > | offset_ |
Private Member Functions | |
Plda & | operator= (const Plda &other) |
double | GetNormalizationFactor (const VectorBase< double > &transformed_ivector, int32 num_examples) const |
This returns a normalization factor, which is a quantity we must multiply "transformed_ivector" by so that it has the length that it "should" have. More... | |
Friends | |
class | PldaEstimator |
class | PldaUnsupervisedAdaptor |
void ApplyTransform | ( | const Matrix< double > & | in_transform | ) |
Apply a transform to the PLDA model.
This is mostly used for projecting the parameters of the model into a lower dimensional space, i.e. in_transform.NumRows() <= in_transform.NumCols(), typically for speaker diarization with a PCA transform.
Definition at line 220 of file plda.cc.
References SpMatrix< Real >::AddMat2Sp(), MatrixBase< Real >::AddMatMat(), VectorBase< Real >::AddMatVec(), VectorBase< Real >::ApplyFloor(), Plda::ComputeDerivedVars(), kaldi::ComputeNormalizingTransform(), VectorBase< Real >::CopyFromVec(), Plda::Dim(), SpMatrix< Real >::Eig(), SpMatrix< Real >::Invert(), KALDI_ASSERT, KALDI_WARN, kaldi::kNoTrans, kaldi::kTrans, Plda::mean_, VectorBase< Real >::Min(), rnnlm::n, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), Plda::psi_, Vector< Real >::Resize(), Matrix< Real >::Resize(), kaldi::SortSvd(), and Plda::transform_.
Referenced by main().
|
protected |
Definition at line 57 of file plda.cc.
References VectorBase< Real >::AddMatVec(), Plda::Dim(), KALDI_ASSERT, kaldi::kNoTrans, Plda::mean_, Plda::offset_, Vector< Real >::Resize(), and Plda::transform_.
Referenced by Plda::ApplyTransform(), PldaEstimator::GetOutput(), Plda::Read(), and Plda::SmoothWithinClassCovariance().
|
inline |
Definition at line 140 of file plda.h.
Referenced by Plda::ApplyTransform(), Plda::ComputeDerivedVars(), Plda::GetNormalizationFactor(), Plda::LogLikelihoodRatio(), main(), Plda::SmoothWithinClassCovariance(), Plda::TransformIvector(), kaldi::TransformIvectors(), and PldaUnsupervisedAdaptor::UpdatePlda().
|
private |
This returns a normalization factor, which is a quantity we must multiply "transformed_ivector" by so that it has the length that it "should" have.
This comment explains the thinking behind the function LogLikelihoodRatio.
We assume "transformed_ivector" is an iVector in the transformed space (i.e., mean-subtracted, and multiplied by transform_). The covariance it "should" have in this space is + I/num_examples.
The reference is "Probabilistic Linear Discriminant Analysis" by Sergey Ioffe, ECCV 2006.
I'm looking at the un-numbered equation between eqs. (4) and (5), that says P(u^p | u^g_{1...n}) = N (u^p | {n }{n + I} {u}^g, I + {}{n + I})
Here, the superscript ^p refers to the "probe" example (e.g. the example to be classified), and u^g_1 is the first "gallery" example, i.e. the first training example of that class. is the between-class covariance matrix, assumed to be diagonalized, and I can be interpreted as the within-class covariance matrix which we have made unit.
We want the likelihood ratio P(u^p | u^g_{1..n}) / P(u^p), where the numerator is the probability of u^p given that it's in that class, and the denominator is the probability of u^p with no class assumption at all (e.g. in its own class).
The expression above even works for n = 0 (e.g. the denominator of the likelihood ratio), where it gives us P(u^p) = N(u^p | 0, I + ) i.e. it's distributed with zero mean and covarance (within + between). The likelihood ratio we want is: N(u^p | {n }{n + I} {u}^g, I + {}{n + I}) / N(u^p | 0, I + ) where {u}^g is the mean of the "gallery examples"; and we can expand the log likelihood ratio as
Definition at line 99 of file plda.cc.
References VectorBase< Real >::Add(), VectorBase< Real >::ApplyPow(), Plda::Dim(), VectorBase< Real >::InvertElements(), KALDI_ASSERT, Plda::psi_, and kaldi::VecVec().
Referenced by Plda::TransformIvector().
double LogLikelihoodRatio | ( | const VectorBase< double > & | transformed_enroll_ivector, |
int32 | num_enroll_utts, | ||
const VectorBase< double > & | transformed_test_ivector | ||
) | const |
Returns the log-likelihood ratio log (p(test_ivector | same) / p(test_ivector | different)).
transformed_enroll_ivector is an average over utterances for that speaker. Both transformed_enroll_vector and transformed_test_ivector are assumed to have been transformed by the function TransformIvector(). Note: any length normalization will have been done while computing the transformed iVectors.
Definition at line 153 of file plda.cc.
References VectorBase< Real >::Add(), VectorBase< Real >::AddVec(), VectorBase< Real >::ApplyPow(), Plda::Dim(), rnnlm::i, VectorBase< Real >::InvertElements(), kaldi::kUndefined, M_LOG_2PI, Plda::psi_, VectorBase< Real >::SumLog(), and kaldi::VecVec().
Referenced by main().
void Read | ( | std::istream & | is, |
bool | binary | ||
) |
Definition at line 34 of file plda.cc.
References Plda::ComputeDerivedVars(), kaldi::ExpectToken(), Plda::mean_, Plda::psi_, Vector< Real >::Read(), Matrix< Real >::Read(), and Plda::transform_.
void SmoothWithinClassCovariance | ( | double | smoothing_factor | ) |
This function smooths the within-class covariance by adding to it, smoothing_factor (e.g.
0.1) times the between-class covariance (it's implemented by modifying transform_). This is to compensate for situations where there were too few utterances per speaker get a good estimate of the within-class covariance, and where the leading elements of psi_ were as a result very large.
We now revise our estimate of the within-class covariance to this larger value. This means that the transform has to change to as to make this new, larger covariance unit. And our between-class covariance in this space is now less.
Definition at line 195 of file plda.cc.
References VectorBase< Real >::AddVec(), VectorBase< Real >::ApplyPow(), Plda::ComputeDerivedVars(), Plda::Dim(), KALDI_ASSERT, KALDI_LOG, MatrixBase< Real >::MulRowsVec(), Plda::psi_, VectorBase< Real >::Set(), and Plda::transform_.
Referenced by main().
double TransformIvector | ( | const PldaConfig & | config, |
const VectorBase< double > & | ivector, | ||
int32 | num_enroll_examples, | ||
VectorBase< double > * | transformed_ivector | ||
) | const |
Transforms an iVector into a space where the within-class variance is unit and between-class variance is diagonalized.
The only anticipated use of this function is to pre-transform iVectors before giving them to the function LogLikelihoodRatio (it's done this way for efficiency because a given iVector may be used multiple times in LogLikelihoodRatio and we don't want to repeat the matrix multiplication
If config.normalize_length == true, it will also normalize the iVector's length by multiplying by a scalar that ensures that ivector^T inv_var ivector = dim. In this case, "num_enroll_examples" comes into play because it affects the expected covariance matrix of the iVector. The normalization factor is returned, even if config.normalize_length == false, in which case the normalization factor is computed but not applied. If config.simple_length_normalization == true, then an alternative normalization factor is computed that causes the iVector length to be equal to the square root of the iVector dimension.
Definition at line 120 of file plda.cc.
References VectorBase< Real >::AddMatVec(), VectorBase< Real >::CopyFromVec(), VectorBase< Real >::Dim(), Plda::Dim(), Plda::GetNormalizationFactor(), KALDI_ASSERT, kaldi::kNoTrans, VectorBase< Real >::Norm(), PldaConfig::normalize_length, Plda::offset_, VectorBase< Real >::Scale(), PldaConfig::simple_length_norm, and Plda::transform_.
Referenced by main(), Plda::TransformIvector(), and kaldi::TransformIvectors().
float TransformIvector | ( | const PldaConfig & | config, |
const VectorBase< float > & | ivector, | ||
int32 | num_enroll_examples, | ||
VectorBase< float > * | transformed_ivector | ||
) | const |
float version of the above (not BaseFloat because we'd be implementing it twice for the same type if BaseFloat == double).
Definition at line 140 of file plda.cc.
References VectorBase< Real >::CopyFromVec(), VectorBase< Real >::Dim(), and Plda::TransformIvector().
void Write | ( | std::ostream & | os, |
bool | binary | ||
) | const |
Definition at line 26 of file plda.cc.
References Plda::mean_, Plda::psi_, Plda::transform_, VectorBase< Real >::Write(), MatrixBase< Real >::Write(), and kaldi::WriteToken().
|
friend |
|
friend |
|
protected |
Definition at line 148 of file plda.h.
Referenced by Plda::ApplyTransform(), Plda::ComputeDerivedVars(), PldaEstimator::GetOutput(), Plda::Read(), PldaUnsupervisedAdaptor::UpdatePlda(), and Plda::Write().
|
protected |
Definition at line 155 of file plda.h.
Referenced by Plda::ComputeDerivedVars(), and Plda::TransformIvector().
|
protected |
Definition at line 152 of file plda.h.
Referenced by Plda::ApplyTransform(), Plda::GetNormalizationFactor(), PldaEstimator::GetOutput(), Plda::LogLikelihoodRatio(), Plda::Read(), Plda::SmoothWithinClassCovariance(), PldaUnsupervisedAdaptor::UpdatePlda(), and Plda::Write().
|
protected |
Definition at line 149 of file plda.h.
Referenced by Plda::ApplyTransform(), Plda::ComputeDerivedVars(), PldaEstimator::GetOutput(), Plda::Read(), Plda::SmoothWithinClassCovariance(), Plda::TransformIvector(), PldaUnsupervisedAdaptor::UpdatePlda(), and Plda::Write().