Packed symetric matrix class. More...
#include <matrix-common.h>
Public Member Functions | |
SpMatrix () | |
SpMatrix (const CuSpMatrix< Real > &cu) | |
Copy constructor from CUDA version of SpMatrix This is defined in ../cudamatrix/cu-sp-matrix.h. More... | |
SpMatrix (MatrixIndexT r, MatrixResizeType resize_type=kSetZero) | |
SpMatrix (const SpMatrix< Real > &orig) | |
template<typename OtherReal > | |
SpMatrix (const SpMatrix< OtherReal > &orig) | |
SpMatrix (const MatrixBase< Real > &orig, SpCopyType copy_type=kTakeMean) | |
void | Swap (SpMatrix *other) |
Shallow swap. More... | |
void | Resize (MatrixIndexT nRows, MatrixResizeType resize_type=kSetZero) |
void | CopyFromSp (const SpMatrix< Real > &other) |
template<typename OtherReal > | |
void | CopyFromSp (const SpMatrix< OtherReal > &other) |
void | CopyFromMat (const MatrixBase< Real > &orig, SpCopyType copy_type=kTakeMean) |
Real | operator() (MatrixIndexT r, MatrixIndexT c) const |
Real & | operator() (MatrixIndexT r, MatrixIndexT c) |
SpMatrix< Real > & | operator= (const SpMatrix< Real > &other) |
void | Invert (Real *logdet=NULL, Real *det_sign=NULL, bool inverse_needed=true) |
matrix inverse. More... | |
void | InvertDouble (Real *logdet=NULL, Real *det_sign=NULL, bool inverse_needed=true) |
Real | Cond () const |
Returns maximum ratio of singular values. More... | |
void | ApplyPow (Real exponent) |
Takes matrix to a fraction power via Svd. More... | |
void | SymPosSemiDefEig (VectorBase< Real > *s, MatrixBase< Real > *P, Real tolerance=0.001) const |
This is the version of SVD that we implement for symmetric positive definite matrices. More... | |
void | Eig (VectorBase< Real > *s, MatrixBase< Real > *P=NULL) const |
Solves the symmetric eigenvalue problem: at end we should have (*this) = P * diag(s) * P^T. More... | |
void | TopEigs (VectorBase< Real > *s, MatrixBase< Real > *P, MatrixIndexT lanczos_dim=0) const |
This function gives you, approximately, the largest eigenvalues of the symmetric matrix and the corresponding eigenvectors. More... | |
Real | MaxAbsEig () const |
Returns the maximum of the absolute values of any of the eigenvalues. More... | |
void | PrintEigs (const char *name) |
bool | IsPosDef () const |
void | AddSp (const Real alpha, const SpMatrix< Real > &Ma) |
Real | LogPosDefDet () const |
Computes log determinant but only for +ve-def matrices (it uses Cholesky). More... | |
Real | LogDet (Real *det_sign=NULL) const |
template<typename OtherReal > | |
void | AddVec2 (const Real alpha, const VectorBase< OtherReal > &v) |
rank-one update, this <– this + alpha v v' More... | |
void | AddVecVec (const Real alpha, const VectorBase< Real > &v, const VectorBase< Real > &w) |
rank-two update, this <– this + alpha (v w' + w v'). More... | |
void | AddVec2Sp (const Real alpha, const VectorBase< Real > &v, const SpMatrix< Real > &S, const Real beta) |
Does *this = beta * *thi + alpha * diag(v) * S * diag(v) More... | |
template<typename OtherReal > | |
void | AddDiagVec (const Real alpha, const VectorBase< OtherReal > &v) |
diagonal update, this <– this + diag(v) More... | |
void | AddMat2 (const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transM, const Real beta) |
rank-N update: if (transM == kNoTrans) (*this) = beta*(*this) + alpha * M * M^T, or (if transM == kTrans) (*this) = beta*(*this) + alpha * M^T * M Note: beta used to default to 0.0. More... | |
void | AddMat2Sp (const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transM, const SpMatrix< Real > &A, const Real beta=0.0) |
Extension of rank-N update: this <– beta*this + alpha * M * A * M^T. More... | |
void | AddSmat2Sp (const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transM, const SpMatrix< Real > &A, const Real beta=0.0) |
This is a version of AddMat2Sp specialized for when M is fairly sparse. More... | |
void | AddTp2Sp (const Real alpha, const TpMatrix< Real > &T, MatrixTransposeType transM, const SpMatrix< Real > &A, const Real beta=0.0) |
The following function does: this <– beta*this + alpha * T * A * T^T. More... | |
void | AddTp2 (const Real alpha, const TpMatrix< Real > &T, MatrixTransposeType transM, const Real beta=0.0) |
The following function does: this <– beta*this + alpha * T * T^T. More... | |
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. More... | |
int | ApplyFloor (const SpMatrix< Real > &Floor, Real alpha=1.0, bool verbose=false) |
Floors this symmetric matrix to the matrix alpha * Floor, where the matrix Floor is positive definite. More... | |
int | ApplyFloor (Real floor) |
Floor: Given a positive semidefinite matrix, floors the eigenvalues to the specified quantity. More... | |
bool | IsDiagonal (Real cutoff=1.0e-05) const |
bool | IsUnit (Real cutoff=1.0e-05) const |
bool | IsZero (Real cutoff=1.0e-05) const |
bool | IsTridiagonal (Real cutoff=1.0e-05) const |
Real | FrobeniusNorm () const |
sqrt of sum of square elements. More... | |
bool | ApproxEqual (const SpMatrix< Real > &other, float tol=0.01) const |
Returns true if ((*this)-other).FrobeniusNorm() <= tol*(*this).FrobeniusNorma() More... | |
MatrixIndexT | LimitCond (Real maxCond=1.0e+5, bool invert=false) |
MatrixIndexT | LimitCondDouble (Real maxCond=1.0e+5, bool invert=false) |
Real | Trace () const |
void | Tridiagonalize (MatrixBase< Real > *Q) |
Tridiagonalize the matrix with an orthogonal transformation. More... | |
void | Qr (MatrixBase< Real > *Q) |
The symmetric QR algorithm. More... | |
template<> | |
void | AddVec2 (const double alpha, const VectorBase< double > &v) |
template<> | |
void | AddVec2 (const float alpha, const VectorBase< float > &v) |
template<> | |
void | AddVec2 (const double alpha, const VectorBase< double > &v) |
Public Member Functions inherited from PackedMatrix< Real > | |
PackedMatrix () | |
PackedMatrix (MatrixIndexT r, MatrixResizeType resize_type=kSetZero) | |
PackedMatrix (const PackedMatrix< Real > &orig) | |
template<typename OtherReal > | |
PackedMatrix (const PackedMatrix< OtherReal > &orig) | |
void | SetZero () |
void | SetUnit () |
< Set to zero More... | |
void | SetRandn () |
< Set to unit matrix. More... | |
Real | Trace () const |
< Set to random values of a normal distribution More... | |
PackedMatrix< Real > & | operator= (const PackedMatrix< Real > &other) |
~PackedMatrix () | |
void | Resize (MatrixIndexT nRows, MatrixResizeType resize_type=kSetZero) |
Set packed matrix to a specified size (can be zero). More... | |
void | AddToDiag (const Real r) |
void | ScaleDiag (const Real alpha) |
void | SetDiag (const Real alpha) |
template<typename OtherReal > | |
void | CopyFromPacked (const PackedMatrix< OtherReal > &orig) |
template<typename OtherReal > | |
void | CopyFromVec (const SubVector< OtherReal > &orig) |
CopyFromVec just interprets the vector as having the same layout as the packed matrix. More... | |
Real * | Data () |
const Real * | Data () const |
MatrixIndexT | NumRows () const |
MatrixIndexT | NumCols () const |
size_t | SizeInBytes () const |
Real | operator() (MatrixIndexT r, MatrixIndexT c) const |
Real & | operator() (MatrixIndexT r, MatrixIndexT c) |
Real | Max () const |
Real | Min () const |
void | Scale (Real c) |
void | Read (std::istream &in, bool binary, bool add=false) |
void | Write (std::ostream &out, bool binary) const |
void | Destroy () |
void | Swap (PackedMatrix< Real > *other) |
Swaps the contents of *this and *other. Shallow swap. More... | |
void | Swap (Matrix< Real > *other) |
Private Member Functions | |
void | EigInternal (VectorBase< Real > *s, MatrixBase< Real > *P, Real tolerance, int recurse) const |
Friends | |
class | CuSpMatrix< Real > |
class | std::vector< Matrix< Real > > |
Additional Inherited Members | |
Protected Member Functions inherited from PackedMatrix< Real > | |
void | AddPacked (const Real alpha, const PackedMatrix< Real > &M) |
Protected Attributes inherited from PackedMatrix< Real > | |
Real * | data_ |
MatrixIndexT | num_rows_ |
Packed symetric matrix class.
Definition at line 62 of file matrix-common.h.
|
inline |
Definition at line 47 of file sp-matrix.h.
Referenced by SpMatrix< float >::SpMatrix().
|
explicit |
Copy constructor from CUDA version of SpMatrix This is defined in ../cudamatrix/cu-sp-matrix.h.
Definition at line 154 of file cu-sp-matrix.h.
|
inlineexplicit |
Definition at line 54 of file sp-matrix.h.
Definition at line 57 of file sp-matrix.h.
Definition at line 61 of file sp-matrix.h.
|
inlineexplicit |
Definition at line 71 of file sp-matrix.h.
template void AddDiagVec | ( | const Real | alpha, |
const VectorBase< OtherReal > & | v | ||
) |
diagonal update, this <– this + diag(v)
Definition at line 183 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddDiagVec(), SpMatrix< float >::AddSp(), Fmpe::ComputeC(), main(), and kaldi::UnitTestSpAddDiagVec().
void AddMat2 | ( | const Real | alpha, |
const MatrixBase< Real > & | M, | ||
MatrixTransposeType | transM, | ||
const Real | beta | ||
) |
rank-N update: if (transM == kNoTrans) (*this) = beta*(*this) + alpha * M * M^T, or (if transM == kTrans) (*this) = beta*(*this) + alpha * M^T * M Note: beta used to default to 0.0.
Definition at line 1110 of file sp-matrix.cc.
Referenced by CovarianceStats::AccStats(), SpMatrix< float >::AddSp(), SpMatrix< float >::ApplyFloor(), kaldi::CholeskyUnitTestTr(), kaldi::ComputePca(), kaldi::EstPca(), main(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), rand_posdef_spmatrix(), kaldi::RandFullCova(), kaldi::unittest::RandPosdefSpMatrix(), RandPosdefSpMatrix(), kaldi::RandPosdefSpMatrix(), MatrixBase< float >::SymPosSemiDefEig(), kaldi::UnitTestAddMat2(), kaldi::UnitTestCuSpMatrixAddMat2(), kaldi::UnitTestCuSpMatrixInvert(), kaldi::UnitTestCuTpMatrixCholesky(), kaldi::UnitTestFloorChol(), kaldi::UnitTestFloorUnit(), kaldi::UnitTestLimitCondInvert(), kaldi::UnitTestMat2Vec(), kaldi::UnitTestPca(), kaldi::UnitTestPca2(), kaldi::UnitTestPldaEstimation(), kaldi::UnitTestRankNUpdate(), kaldi::UnitTestSolve(), kaldi::UnitTestTopEigs(), and kaldi::UnitTestTp2().
void AddMat2Sp | ( | const Real | alpha, |
const MatrixBase< Real > & | M, | ||
MatrixTransposeType | transM, | ||
const SpMatrix< Real > & | A, | ||
const Real | beta = 0.0 |
||
) |
Extension of rank-N update: this <– beta*this + alpha * M * A * M^T.
(*this) and A are allowed to be the same. If transM == kTrans, then we do it as M^T * A * M.
Definition at line 982 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), kaldi::ApplyFeatureTransformToStats(), SpMatrix< float >::ApplyFloor(), Plda::ApplyTransform(), IvectorExtractor::ComputeDerivedVars(), kaldi::ComputeFeatureNormalizingTransform(), AmSgmm2::ComputeFmllrPreXform(), AmSgmm2::ComputeH(), Sgmm2Project::ComputeLdaTransform(), kaldi::ComputeLdaTransform(), MleAmSgmm2Updater::ComputeMPrior(), Sgmm2Project::ComputeProjection(), LdaEstimate::Estimate(), BasisFmllrEstimate::EstimateFmllrBasis(), FeatureTransformEstimate::EstimateInternal(), FeatureTransformEstimateMulti::EstimateTransformPart(), PldaEstimator::GetOutput(), Sgmm2Project::ProjectVariance(), MleAmSgmm2Updater::RenormalizeV(), kaldi::SolveDoubleQuadraticMatrixProblem(), kaldi::SolveQuadraticMatrixProblem(), kaldi::UnitTestAddVec2Sp(), kaldi::UnitTestPca2(), kaldi::UnitTestTp2Sp(), kaldi::UnitTestTransposeScatter(), kaldi::UnitTestTridiagonalize(), kaldi::UnitTestTridiagonalizeAndQr(), PldaUnsupervisedAdaptor::UpdatePlda(), IvectorExtractorStats::UpdatePrior(), and IvectorExtractorStats::UpdateVariances().
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.
if transM == kTrans, then this <– beta*this + alpha * M^T * diag(v) * M.
Definition at line 1081 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), IvectorExtractor::GetAcousticAuxfWeight(), IvectorExtractor::GetIvectorDistWeight(), IvectorExtractor::InvertWithFlooring(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), kaldi::UnitTestEigSp(), and kaldi::UnitTestMat2Vec().
void AddSmat2Sp | ( | const Real | alpha, |
const MatrixBase< Real > & | M, | ||
MatrixTransposeType | transM, | ||
const SpMatrix< Real > & | A, | ||
const Real | beta = 0.0 |
||
) |
This is a version of AddMat2Sp specialized for when M is fairly sparse.
This was required for making the raw-fMLLR code efficient.
Definition at line 1026 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), FmllrRawAccs::ConvertToSimpleStats(), and kaldi::UnitTestAddMat2Sp().
|
inline |
Definition at line 211 of file sp-matrix.h.
Referenced by IvectorExtractorStats::Add(), CovarianceStats::AddStats(), SpMatrix< float >::ApproxEqual(), IvectorExtractorStats::CommitStatsForPrior(), kaldi::ComputeFeatureNormalizingTransform(), AmSgmm2::ComputeHsmFromModel(), Sgmm2Project::ComputeLdaStats(), kaldi::ComputeLdaTransform(), PldaEstimator::ComputeObjfPart2(), EbwAmSgmm2Updater::ComputePhoneVecStats(), LdaEstimate::Estimate(), FeatureTransformEstimate::EstimateInternal(), PldaEstimator::GetStatsFromClassMeans(), PldaEstimator::GetStatsFromIntraClass(), CovarianceStats::GetWithinCovar(), FullGmm::MergedComponentsLogdet(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), LdaEstimate::Read(), MleAmSgmm2Updater::RenormalizeN(), MleAmSgmm2Updater::RenormalizeV(), kaldi::SolveDoubleQuadraticMatrixProblem(), kaldi::UnitTestCuSpMatrixAddSp(), kaldi::UnitTestCuSpMatrixApproxEqual(), kaldi::UnitTestEigSp(), UnitTestEstimateLda(), EbwAmSgmm2Updater::UpdateM(), EbwAmSgmm2Updater::UpdateN(), MleSgmm2SpeakerAccs::UpdateNoU(), EbwAmSgmm2Updater::UpdatePhoneVectorsInternal(), MleAmSgmm2Updater::UpdatePhoneVectorsInternal(), EbwAmSgmm2Updater::UpdateU(), IvectorExtractorStats::UpdateVariances(), EbwAmSgmm2Updater::UpdateVars(), MleAmSgmm2Updater::UpdateVars(), MleSgmm2SpeakerAccs::UpdateWithU(), and FisherComputationClass::~FisherComputationClass().
void AddTp2 | ( | const Real | alpha, |
const TpMatrix< Real > & | T, | ||
MatrixTransposeType | transM, | ||
const Real | beta = 0.0 |
||
) |
The following function does: this <– beta*this + alpha * T * T^T.
(*this) and A are allowed to be the same. If transM == kTrans, then we do it as alpha * T^T * T Currently it just calls AddMat2, but if needed we can implement it more efficiently.
Definition at line 1156 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), CompressedAffineXformStats::ExtractOneG(), main(), and CuMatrixBase< float >::SymInvertPosDef().
void AddTp2Sp | ( | const Real | alpha, |
const TpMatrix< Real > & | T, | ||
MatrixTransposeType | transM, | ||
const SpMatrix< Real > & | A, | ||
const Real | beta = 0.0 |
||
) |
The following function does: this <– beta*this + alpha * T * A * T^T.
(*this) and A are allowed to be the same. If transM == kTrans, then we do it as alpha * T^T * A * T. Currently it just calls AddMat2Sp, but if needed we can implement it more efficiently.
Definition at line 1139 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), Sgmm2Project::ComputeLdaTransform(), kaldi::UnitTestPldaEstimation(), and PldaUnsupervisedAdaptor::UpdatePlda().
void AddVec2 | ( | const double | alpha, |
const VectorBase< double > & | v | ||
) |
void AddVec2 | ( | const Real | alpha, |
const VectorBase< OtherReal > & | v | ||
) |
rank-one update, this <– this + alpha v v'
Definition at line 946 of file sp-matrix.cc.
Referenced by CovarianceStats::AccStats(), IvectorExtractorUtteranceStats::AccStats(), LdaEstimate::Accumulate(), FmllrSgmm2Accs::AccumulateForFmllrSubspace(), RegtreeMllrDiagGmmAccs::AccumulateForGaussian(), RegtreeFmllrDiagGmmAccs::AccumulateForGaussian(), RegtreeMllrDiagGmmAccs::AccumulateForGmm(), RegtreeFmllrDiagGmmAccs::AccumulateForGmm(), AccumFullGmm::AccumulateFromPosteriors(), FmllrSgmm2Accs::AccumulateFromPosteriors(), SpMatrix< float >::AddDiagVec(), SpMatrix< float >::AddSp(), SpMatrix< float >::AddVec2(), FmllrRawAccs::CommitSingleFrameStats(), FmllrDiagGmmAccs::CommitSingleFrameStats(), IvectorExtractorStats::CommitStatsForM(), IvectorExtractorStats::CommitStatsForPrior(), IvectorExtractorStats::CommitStatsForWPoint(), Fmpe::ComputeC(), kaldi::ComputeFeatureNormalizingTransform(), AmSgmm2::ComputeFmllrPreXform(), Sgmm2Project::ComputeLdaStats(), EbwAmSgmm2Updater::ComputePhoneVecStats(), kaldi::EstPca(), IvectorExtractor::GetAcousticAuxfVariance(), LdaEstimate::GetStats(), PldaEstimator::GetStatsFromClassMeans(), FullGmm::LogLikelihoodsPreselect(), main(), FullGmm::MergedComponentsLogdet(), FisherComputationClass::operator()(), IvectorExtractorStats::PriorDiagnostics(), AccumFullGmm::Read(), LdaEstimate::Read(), MleAmSgmm2Updater::RenormalizeV(), kaldi::UnitTestCuSpMatrixAddVec2(), UnitTestEstimateLda(), kaldi::UnitTestSimpleForMat(), MleAmSgmm2Updater::UpdatePhoneVectorsInternal(), PldaUnsupervisedAdaptor::UpdatePlda(), IvectorExtractorStats::UpdatePrior(), MleAmSgmm2Updater::UpdateWGetStats(), MleSgmm2SpeakerAccs::UpdateWithU(), AccumFullGmm::Write(), and LdaEstimate::Write().
void AddVec2 | ( | const float | alpha, |
const VectorBase< float > & | v | ||
) |
Definition at line 915 of file sp-matrix.cc.
void AddVec2 | ( | const double | alpha, |
const VectorBase< double > & | v | ||
) |
Definition at line 938 of file sp-matrix.cc.
void AddVec2Sp | ( | const Real | alpha, |
const VectorBase< Real > & | v, | ||
const SpMatrix< Real > & | S, | ||
const Real | beta | ||
) |
Does *this = beta * *thi + alpha * diag(v) * S * diag(v)
Definition at line 922 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), kaldi::SolveQuadraticMatrixProblem(), kaldi::SolveQuadraticProblem(), and kaldi::UnitTestAddVec2Sp().
void AddVecVec | ( | const Real | alpha, |
const VectorBase< Real > & | v, | ||
const VectorBase< Real > & | w | ||
) |
rank-two update, this <– this + alpha (v w' + w v').
Definition at line 1147 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), and kaldi::UnitTestSpAddVecVec().
Floors this symmetric matrix to the matrix alpha * Floor, where the matrix Floor is positive 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 the number of elements that were floored.
Definition at line 536 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), main(), kaldi::UnitTestFloorChol(), kaldi::UnitTestFloorUnit(), IvectorExtractorStats::UpdateVariances(), and EbwAmSgmm2Updater::UpdateVars().
int ApplyFloor | ( | Real | floor | ) |
Floor: Given a positive semidefinite matrix, floors the eigenvalues to the specified quantity.
A previous version of this function had a tolerance which is now no longer needed since we have code to do the symmetric eigenvalue decomposition and no longer use the SVD code for that purose.
Definition at line 589 of file sp-matrix.cc.
void ApplyPow | ( | Real | exponent | ) |
Takes matrix to a fraction power via Svd.
Will throw exception if matrix is not positive semidefinite (to within a tolerance)
Definition at line 91 of file sp-matrix.cc.
Referenced by SpMatrix< float >::Cond(), AmSgmm2::SplitSubstates(), and kaldi::UnitTestPower().
Returns true if ((*this)-other).FrobeniusNorm() <= tol*(*this).FrobeniusNorma()
Definition at line 525 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), kaldi::AssertEqual(), kaldi::UnitTestEigSp(), and kaldi::UnitTestNorm().
|
inline |
Returns maximum ratio of singular values.
Definition at line 145 of file sp-matrix.h.
Referenced by IvectorExtractor::GetIvectorDistribution(), kaldi::InitRand(), and kaldi::InitRandNonsingular().
void CopyFromMat | ( | const MatrixBase< Real > & | orig, |
SpCopyType | copy_type = kTakeMean |
||
) |
Definition at line 112 of file sp-matrix.cc.
Referenced by BasisFmllrEstimate::ComputeAmDiagPrecond(), SpMatrix< float >::CopyFromSp(), SpMatrix< float >::SpMatrix(), kaldi::UnitTestCopySp(), kaldi::UnitTestDeterminant(), kaldi::UnitTestDeterminantSign(), and kaldi::UnitTestPower().
|
inline |
Definition at line 85 of file sp-matrix.h.
Referenced by SpMatrix< float >::AddMat2Sp(), PldaEstimator::ComputeObjfPart2(), DiagGmm::CopyFromFullGmm(), PldaEstimator::EstimateFromStats(), FullGmm::GetComponentMean(), AmSgmm2::GetInvCovars(), IvectorExtractor::GetIvectorDistribution(), FullGmm::GetMeans(), LdaEstimate::GetStats(), PldaEstimator::GetStatsFromClassMeans(), main(), FullGmm::MergedComponentsLogdet(), Sgmm2Project::ProjectVariance(), AffineXformStats::Read(), FullGmm::SetInvCovars(), kaldi::UnitTestIoCross(), kaldi::UnitTestMat2Vec(), kaldi::UnitTestSpInvert(), and MleAmSgmm2Updater::UpdateVars().
Definition at line 90 of file sp-matrix.h.
template void Eig | ( | VectorBase< Real > * | s, |
MatrixBase< Real > * | P = NULL |
||
) | const |
Solves the symmetric eigenvalue problem: at end we should have (*this) = P * diag(s) * P^T.
We solve the problem using the symmetric QR method. P may be NULL. Implemented in qr.cc. If you need the eigenvalues sorted, the function SortSvd declared in kaldi-matrix is suitable.
Definition at line 433 of file qr.cc.
Referenced by SpMatrix< float >::ApplyFloor(), Plda::ApplyTransform(), kaldi::ComputeFeatureNormalizingTransform(), AmSgmm2::ComputeFmllrPreXform(), kaldi::ComputeLdaTransform(), kaldi::ComputeNormalizingTransform(), kaldi::ComputePca(), SpMatrix< float >::Cond(), kaldi::EstimateSgmm2FmllrSubspace(), kaldi::EstPca(), kaldi::GetLogDetNoFailure(), PldaEstimator::GetOutput(), IvectorExtractor::InvertWithFlooring(), main(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditioner::PreconditionDirectionsInternal(), OnlineNaturalGradient::PreconditionDirectionsInternal(), SpMatrix< float >::TopEigs(), kaldi::UnitTestEigSp(), kaldi::UnitTestMaxAbsEig(), kaldi::UnitTestPca2(), kaldi::UnitTestPldaEstimation(), kaldi::UnitTestSvdSpeed(), kaldi::UnitTestTopEigs(), PldaUnsupervisedAdaptor::UpdatePlda(), and IvectorExtractorStats::UpdatePrior().
|
private |
Referenced by SpMatrix< float >::LimitCondDouble().
Real FrobeniusNorm | ( | ) | const |
sqrt of sum of square elements.
Definition at line 513 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), SpMatrix< float >::ApproxEqual(), kaldi::UnitTestCuSpMatrixApproxEqual(), kaldi::UnitTestCuSpMatrixSetUnit(), and kaldi::UnitTestNorm().
void Invert | ( | Real * | logdet = NULL , |
Real * | det_sign = NULL , |
||
bool | inverse_needed = true |
||
) |
matrix inverse.
if inverse_needed = false, will fill matrix with garbage. (only useful if logdet wanted).
Definition at line 219 of file sp-matrix.cc.
Referenced by Plda::ApplyTransform(), kaldi::ComputeMllrMatrix(), PldaEstimator::ComputeObjfPart1(), PldaEstimator::ComputeObjfPart2(), DiagGmm::CopyFromFullGmm(), IvectorExtractor::GetIvectorDistribution(), GetLogLikeTest(), PldaEstimator::GetStatsFromClassMeans(), SpMatrix< float >::Invert(), SpMatrix< float >::InvertDouble(), SpMatrix< float >::LogDet(), main(), SpMatrix< float >::operator=(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), Sgmm2Project::ProjectVariance(), kaldi::UnitTestCuMatrixSymInvertPosDef(), kaldi::UnitTestCuSpMatrixInvert(), kaldi::UnitTestLbfgs(), kaldi::UnitTestSolve(), kaldi::UnitTestSpInvert(), IvectorExtractorStats::UpdateVariances(), and EbwAmSgmm2Updater::UpdateVars().
void InvertDouble | ( | Real * | logdet = NULL , |
Real * | det_sign = NULL , |
||
bool | inverse_needed = true |
||
) |
Definition at line 312 of file sp-matrix.cc.
Referenced by AmSgmm2::ComputeFmllrPreXform(), FullGmm::ComputeGconsts(), FullGmm::GetComponentMean(), FullGmm::GetMeans(), main(), SpMatrix< float >::operator=(), FullGmm::SetInvCovars(), and kaldi::UnitTestSpInvert().
bool IsDiagonal | ( | Real | cutoff = 1.0e-05 | ) | const |
Definition at line 465 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), AmSgmm2::ComputeFmllrPreXform(), MleAmSgmm2Updater::RenormalizeV(), kaldi::SolveDoubleQuadraticMatrixProblem(), kaldi::UnitTestPca2(), and kaldi::UnitTestTridiagonalizeAndQr().
bool IsPosDef | ( | ) | const |
Definition at line 75 of file sp-matrix.cc.
Referenced by SpMatrix< float >::PrintEigs(), and MleAmSgmm2Updater::RenormalizeV().
bool IsTridiagonal | ( | Real | cutoff = 1.0e-05 | ) | const |
Definition at line 491 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), and kaldi::UnitTestTridiag().
bool IsUnit | ( | Real | cutoff = 1.0e-05 | ) | const |
Definition at line 480 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), AmSgmm2::ComputeFmllrPreXform(), Sgmm2Project::ComputeLdaTransform(), PldaEstimator::GetOutput(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), MleAmSgmm2Updater::RenormalizeV(), OnlineNaturalGradient::ReorthogonalizeRt1(), OnlinePreconditioner::ReorthogonalizeXt1(), OnlinePreconditioner::SelfTest(), OnlineNaturalGradient::SelfTest(), kaldi::SolveDoubleQuadraticMatrixProblem(), kaldi::UnitTestCuSpMatrixConstructor(), kaldi::UnitTestPca(), kaldi::UnitTestTopEigs(), and IvectorExtractorStats::UpdatePrior().
bool IsZero | ( | Real | cutoff = 1.0e-05 | ) | const |
Definition at line 507 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), kaldi::SolveQuadraticMatrixProblem(), kaldi::SolveQuadraticProblem(), and kaldi::UnitTestResize().
MatrixIndexT LimitCond | ( | Real | maxCond = 1.0e+5 , |
bool | invert = false |
||
) |
Definition at line 606 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), SpMatrix< float >::LimitCondDouble(), kaldi::UnitTestLimitCond(), and kaldi::UnitTestLimitCondInvert().
|
inline |
Definition at line 333 of file sp-matrix.h.
Referenced by AmSgmm2::ComputeHsmFromModel(), and MleAmSgmm2Updater::UpdateVars().
Real LogDet | ( | Real * | det_sign = NULL | ) | const |
Definition at line 579 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), kaldi::UnitTestDeterminant(), kaldi::UnitTestDeterminantSign(), kaldi::UnitTestTridiagonalize(), kaldi::UnitTestTridiagonalizeAndQr(), and EbwAmSgmm2Updater::UpdateVars().
Real LogPosDefDet | ( | ) | const |
Computes log determinant but only for +ve-def matrices (it uses Cholesky).
If matrix is not +ve-def, it will throw an exception was LogPDDeterminant()
Definition at line 36 of file sp-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), FullGmm::ComputeGconsts(), kaldi::GetLogDetNoFailure(), FullGmm::MergedComponentsLogdet(), IvectorExtractorStats::PriorDiagnostics(), rand_posdef_spmatrix(), kaldi::unittest::RandPosdefSpMatrix(), RandPosdefSpMatrix(), kaldi::UnitTestDeterminant(), kaldi::UnitTestDeterminantSign(), and IvectorExtractorStats::UpdateVariances().
Real MaxAbsEig | ( | ) | const |
Returns the maximum of the absolute values of any of the eigenvalues.
Definition at line 67 of file sp-matrix.cc.
Referenced by SpMatrix< float >::Cond(), main(), kaldi::UnitTestLinearCgd(), kaldi::UnitTestMaxAbsEig(), and IvectorExtractorStats::UpdateVariances().
|
inline |
Definition at line 102 of file sp-matrix.h.
|
inline |
Definition at line 115 of file sp-matrix.h.
Definition at line 126 of file sp-matrix.h.
|
inline |
Definition at line 203 of file sp-matrix.h.
Referenced by kaldi::nnet2::PreconditionDirections(), and MleAmSgmm2Updater::RenormalizeV().
template void Qr | ( | MatrixBase< Real > * | Q | ) |
The symmetric QR algorithm.
This is the symmetric QR algorithm, from Golub and Van Loan 3rd ed., Algorithm 8.3.3.
This will mostly be useful in internal code. Typically, you will call this after Tridiagonalize(), on the same object. When called, *this (call it A at this point) must be tridiagonal; at exit, *this will be a diagonal matrix D that is similar to A via orthogonal transformations. This algorithm right-multiplies Q by orthogonal transformations. It turns *this from a tridiagonal into a diagonal matrix while maintaining that (Q *this Q^T) has the same value at entry and exit. At entry Q should probably be either NULL or orthogonal, but we don't check this.
Q is transposed w.r.t. there, though.
Definition at line 409 of file qr.cc.
Referenced by SpMatrix< float >::Eig(), SpMatrix< float >::LimitCondDouble(), SpMatrix< float >::TopEigs(), and kaldi::UnitTestTridiagonalizeAndQr().
|
inline |
Definition at line 81 of file sp-matrix.h.
Referenced by SpMatrix< float >::AddMat2Sp(), BasisFmllrEstimate::ComputeAmDiagPrecond(), AmSgmm2::ComputeHsmFromModel(), Sgmm2Project::ComputeLdaStats(), FastNnetCombiner::ComputePreconditioner(), Sgmm2Project::ComputeProjection(), FmllrRawAccs::ConvertToSimpleStats(), kaldi::EstPca(), FisherComputationClass::FisherComputationClass(), FmllrRawAccs::FmllrRawAccs(), AmSgmm2::GetInvCovars(), LdaEstimate::GetStats(), LdaEstimate::Init(), PldaEstimator::InitParameters(), IvectorExtractorStats::IvectorExtractorStats(), main(), Sgmm2Project::ProjectVariance(), AffineXformStats::Read(), PldaEstimator::ResetPerIterStats(), kaldi::UnitTestIo(), kaldi::UnitTestResize(), and FisherComputationClass::~FisherComputationClass().
void Swap | ( | SpMatrix< Real > * | other | ) |
Shallow swap.
Definition at line 51 of file sp-matrix.cc.
Referenced by SpMatrix< float >::SpMatrix().
void SymPosSemiDefEig | ( | VectorBase< Real > * | s, |
MatrixBase< Real > * | P, | ||
Real | tolerance = 0.001 |
||
) | const |
This is the version of SVD that we implement for symmetric positive definite matrices.
This exists for historical reasons; right now its internal implementation is the same as Eig(). It computes the eigenvalue decomposition (*this) = P * diag(s) * P^T with P orthogonal. Will throw exception if input is not positive semidefinite to within a tolerance.
Definition at line 57 of file sp-matrix.cc.
Referenced by Sgmm2Project::ComputeLdaTransform(), SpMatrix< float >::Cond(), BasisFmllrEstimate::EstimateFmllrBasis(), GetLogLikeTest(), SpMatrix< float >::PrintEigs(), MleAmSgmm2Updater::RenormalizeN(), MleAmSgmm2Updater::RenormalizeV(), kaldi::SolveDoubleQuadraticMatrixProblem(), kaldi::SolveQuadraticMatrixProblem(), kaldi::SolveQuadraticProblem(), kaldi::UnitTestFloorUnit(), kaldi::UnitTestMat2Vec(), and kaldi::UnitTestSvdBad().
template void TopEigs | ( | VectorBase< Real > * | s, |
MatrixBase< Real > * | P, | ||
MatrixIndexT | lanczos_dim = 0 |
||
) | const |
This function gives you, approximately, the largest eigenvalues of the symmetric matrix and the corresponding eigenvectors.
(largest meaning, further from zero). It does this by doing a SVD within the Krylov subspace generated by this matrix and a random vector. This is a form of the Lanczos method with complete reorthogonalization, followed by SVD within a smaller dimension ("lanczos_dim").
If *this is m by m, s should be of dimension n and P should be of dimension m by n, with n <= m. The *columns* of P are the approximate eigenvectors; P * diag(s) * P^T would be a low-rank reconstruction of *this. The columns of P will be orthogonal, and the elements of s will be the eigenvalues of *this projected into that subspace, but beyond that there are no exact guarantees. (This is because the convergence of this method is statistical). Note: it only makes sense to use this method if you are in very high dimension and n is substantially smaller than m: for example, if you want the 100 top eigenvalues of a 10k by 10k matrix. This function calls Rand() to initialize the lanczos iterations and also for restarting. If lanczos_dim is zero, it will default to the greater of: s->Dim() + 50 or s->Dim() + s->Dim()/2, but not more than this->Dim(). If lanczos_dim == this->Dim(), you might as well just call the function Eig() since the result will be the same, and Eig() would be faster; the whole point of this function is to reduce the dimension of the SVD computation.
Definition at line 454 of file qr.cc.
Referenced by kaldi::ComputePca(), SpMatrix< float >::Cond(), SpMatrix< float >::TopEigs(), and kaldi::UnitTestTopEigs().
Real Trace | ( | ) | const |
Definition at line 171 of file sp-matrix.cc.
Referenced by FastNnetCombiner::ComputePreconditioner(), LdaEstimate::Estimate(), PldaEstimator::EstimateFromStats(), FeatureTransformEstimate::EstimateInternal(), IvectorExtractor::GetIvectorDistribution(), IvectorExtractor::GetPriorAuxf(), SpMatrix< float >::LimitCondDouble(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlinePreconditioner::PreconditionDirectionsInternal(), OnlineNaturalGradient::PreconditionDirectionsInternal(), CompressedAffineXformStats::PrepareOneG(), IvectorExtractorStats::PriorDiagnostics(), kaldi::UnitTestCuMatrixSymInvertPosDef(), kaldi::UnitTestCuSpMatrixCopyFromMat(), kaldi::UnitTestPca2(), kaldi::UnitTestPldaEstimation(), kaldi::UnitTestTrace(), kaldi::UnitTestTridiagonalize(), and kaldi::UnitTestTridiagonalizeAndQr().
template void Tridiagonalize | ( | MatrixBase< Real > * | Q | ) |
Tridiagonalize the matrix with an orthogonal transformation.
This routine tridiagonalizes *this.
If *this starts as S, produce T (and Q, if non-NULL) such that T = Q A Q^T, i.e. S = Q^T T Q. Caution: this is the other way round from most authors (it's more efficient in row-major indexing).
C.f. Golub and Van Loan 3rd ed., sec. 8.3.1 (p415). We reverse the order of the indices as it's more natural with packed lower-triangular matrices to do it this way. There's also a shift from one-based to zero-based indexing, so the index k is transformed k -> n - k, and a corresponding transpose...
Let the original *this be A. This algorithms replaces *this with a tridiagonal matrix T such that T = Q A Q^T for an orthogonal Q. Caution: Q is transposed vs. Golub and Van Loan. If Q != NULL it outputs Q.
Definition at line 165 of file qr.cc.
Referenced by SpMatrix< float >::Eig(), SpMatrix< float >::LimitCondDouble(), SpMatrix< float >::Tridiagonalize(), kaldi::UnitTestTridiagonalize(), and kaldi::UnitTestTridiagonalizeAndQr().
|
friend |
Definition at line 42 of file sp-matrix.h.
|
friend |
Definition at line 45 of file sp-matrix.h.