Commit addf2be6 authored by Dan Povey's avatar Dan Povey
Browse files

trunk: modification to how ApplyFloor works to avoid failure in SymPosDefEig...

trunk: modification to how ApplyFloor works to avoid failure in SymPosDefEig (it's no longer necessary as Eig is now sufficiently stable).

git-svn-id: https://svn.code.sf.net/p/kaldi/code/trunk@4566 5e6a8d80-dfce-4ca6-a32a-6e07a63d50c8
parent d5ab6a10
......@@ -558,7 +558,7 @@ bool SpMatrix<Real>::ApproxEqual(const SpMatrix<Real> &other, float tol) const {
// function Floor: A = Floor(B, alpha * C) ... see tutorial document.
template<typename Real>
int SpMatrix<Real>::ApplyFloor(const SpMatrix<Real> &C, Real alpha,
bool verbose, bool is_psd) {
bool verbose) {
MatrixIndexT dim = this->NumRows();
int nfloored = 0;
KALDI_ASSERT(C.NumRows() == dim);
......@@ -577,14 +577,9 @@ int SpMatrix<Real>::ApplyFloor(const SpMatrix<Real> &C, Real alpha,
Vector<Real> l(dim);
Matrix<Real> U(dim, dim);
if (is_psd)
D.SymPosSemiDefEig(&l, &U);
else
D.Eig(&l, &U);
// We added the "Eig" function more recently. It's not as accurate as in the
// symmetric positive semidefinite case, so we only use it if the user says
// the calling matrix is not positive semidefinite.
// [Note: we since changed it to be more accurate.]
D.Eig(&l, &U);
if (verbose) {
KALDI_LOG << "ApplyFloor: flooring following diagonal to 1: " << l;
}
......
......@@ -295,14 +295,14 @@ class SpMatrix : public PackedMatrix<Real> {
/// Floors this symmetric matrix to the matrix
/// alpha * Floor, where the matrix Floor is positive
/// definite. If is_psd = true, then the
/// matrix (*this) must be positive semidefinite.
/// definite.
/// It is floored in the sense that after flooring,
/// x^T (*this) x >= x^T (alpha*Floor) x.
/// This is accomplished using an Svd. It will crash
/// if Floor is not positive definite. returns #floored
/// if Floor is not positive definite. Returns the number of
/// elements that were floored.
int ApplyFloor(const SpMatrix<Real> &Floor, Real alpha = 1.0,
bool verbose = false, bool is_psd = true);
bool verbose = false);
/// Floor: Given a positive semidefinite matrix, floors the eigenvalues
/// to the specified quantity. A previous version of this function had
......
......@@ -555,10 +555,9 @@ double EbwAmSgmmUpdater::UpdateVars(const MleAmSgmmAccs &num_accs,
SpMatrix<double> SigmaInv(SigmaStats); // before floor and ceiling. Currently sigma,
// not its inverse.
bool verbose = false;
bool is_psd = false; // we cannot guarantee that Sigma Inv is positive semidefinite.
int n_floor = SigmaInv.ApplyFloor(SigmaOld, options_.cov_min_value, verbose, is_psd);
int n_floor = SigmaInv.ApplyFloor(SigmaOld, options_.cov_min_value, verbose);
SigmaInv.Invert(); // make it inverse variance.
int n_ceiling = SigmaInv.ApplyFloor(SigmaInvOld, options_.cov_min_value, verbose, is_psd);
int n_ceiling = SigmaInv.ApplyFloor(SigmaInvOld, options_.cov_min_value, verbose);
// this auxf_change.
double auxf_change = -0.5 * count *(TraceSpSp(SigmaInv, SigmaStats)
......
......@@ -631,10 +631,9 @@ double EbwAmSgmm2Updater::UpdateVars(const MleAmSgmm2Accs &num_accs,
SpMatrix<double> SigmaInv(SigmaStats); // before floor and ceiling. Currently sigma,
// not its inverse.
bool verbose = false;
bool is_psd = false; // we cannot guarantee that Sigma Inv is positive semidefinite.
int n_floor = SigmaInv.ApplyFloor(SigmaOld, options_.cov_min_value, verbose, is_psd);
int n_floor = SigmaInv.ApplyFloor(SigmaOld, options_.cov_min_value, verbose);
SigmaInv.Invert(); // make it inverse variance.
int n_ceiling = SigmaInv.ApplyFloor(SigmaInvOld, options_.cov_min_value, verbose, is_psd);
int n_ceiling = SigmaInv.ApplyFloor(SigmaInvOld, options_.cov_min_value, verbose);
// this auxf_change.
double auxf_change = -0.5 * count *(TraceSpSp(SigmaInv, SigmaStats)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment