Skip to content

Commit

Permalink
[src] Simplification and efficiency improvement in ivector-plda-scori…
Browse files Browse the repository at this point in the history
…ng-dense (#2991)
  • Loading branch information
david-ryan-snyder authored and danpovey committed Jan 16, 2019
1 parent 9f981d0 commit ae573c9
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/ivectorbin/ivector-plda-scoring-dense.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@
namespace kaldi {

bool EstPca(const Matrix<BaseFloat> &ivector_mat, BaseFloat target_energy,
Matrix<BaseFloat> *mat) {
const std::string &reco, Matrix<BaseFloat> *mat) {

// If the target_energy is 1.0, it's equivalent to not applying the
// conversation-dependent PCA at all, so it's better to exit this
// function before doing any computation.
if (ApproxEqual(target_energy, 1.0, 0.001))
return false;

int32 num_rows = ivector_mat.NumRows(),
num_cols = ivector_mat.NumCols();
Vector<BaseFloat> sum;
Expand All @@ -50,6 +57,8 @@ bool EstPca(const Matrix<BaseFloat> &ivector_mat, BaseFloat target_energy,
else
Matrix<BaseFloat>(sumsq).Svd(&s, &P, NULL);
} catch (...) {
KALDI_WARN << "Unable to compute conversation dependent PCA for"
<< " recording " << reco << ".";
return false;
}

Expand Down Expand Up @@ -181,7 +190,7 @@ int main(int argc, char *argv[]) {
for (size_t i = 0; i < ivectors.size(); i++) {
ivector_mat.Row(i).CopyFromVec(ivectors[i]);
}
if (EstPca(ivector_mat, target_energy, &pca_transform)) {
if (EstPca(ivector_mat, target_energy, reco, &pca_transform)) {
// Apply the PCA transform to the raw i-vectors.
ApplyPca(ivector_mat, pca_transform, &ivector_mat_pca);

Expand All @@ -192,8 +201,7 @@ int main(int argc, char *argv[]) {
TransformIvectors(ivector_mat_pca, plda_config, this_plda,
&ivector_mat_plda);
} else {
KALDI_WARN << "Unable to compute conversation dependent PCA for"
<< " recording " << reco << ".";
// If EstPca returns false, we won't apply any PCA.
TransformIvectors(ivector_mat, plda_config, this_plda,
&ivector_mat_plda);
}
Expand Down

0 comments on commit ae573c9

Please sign in to comment.