Classes | |
struct | SolverOptions |
This class describes the options for maximizing various quadratic objective functions. More... | |
class | SplitRadixComplexFft< Real > |
class | SplitRadixRealFft< Real > |
Functions | |
template<typename Real > | |
void | SortSvd (VectorBase< Real > *s, MatrixBase< Real > *U, MatrixBase< Real > *Vt=NULL, bool sort_on_absolute_value=true) |
Function to ensure that SVD is sorted. More... | |
template<typename Real > | |
void | CreateEigenvalueMatrix (const VectorBase< Real > &real, const VectorBase< Real > &imag, MatrixBase< Real > *D) |
Creates the eigenvalue matrix D that is part of the decomposition used Matrix::Eig. More... | |
template<typename Real > | |
bool | AttemptComplexPower (Real *x_re, Real *x_im, Real power) |
The following function is used in Matrix::Power, and separately tested, so we declare it here mainly for the testing code to see. More... | |
template<typename Real > | |
void | ComplexFft (VectorBase< Real > *v, bool forward, Vector< Real > *tmp_work=NULL) |
The function ComplexFft does an Fft on the vector argument v. More... | |
template<typename Real > | |
void | ComplexFt (const VectorBase< Real > &in, VectorBase< Real > *out, bool forward) |
ComplexFt is the same as ComplexFft but it implements the Fourier transform in an inefficient way. More... | |
template<typename Real > | |
void | RealFft (VectorBase< Real > *v, bool forward) |
RealFft is a fourier transform of real inputs. More... | |
template<typename Real > | |
void | RealFftInefficient (VectorBase< Real > *v, bool forward) |
Inefficient version of Fourier transform, for testing purposes. More... | |
template<typename Real > | |
void | ComputeDctMatrix (Matrix< Real > *M) |
ComputeDctMatrix computes a matrix corresponding to the DCT, such that M * v equals the DCT of vector v. More... | |
template<typename Real > | |
void | ComplexMul (const Real &a_re, const Real &a_im, Real *b_re, Real *b_im) |
ComplexMul implements, inline, the complex multiplication b *= a. More... | |
template<typename Real > | |
void | ComplexAddProduct (const Real &a_re, const Real &a_im, const Real &b_re, const Real &b_im, Real *c_re, Real *c_im) |
ComplexMul implements, inline, the complex operation c += (a * b). More... | |
template<typename Real > | |
void | ComplexImExp (Real x, Real *a_re, Real *a_im) |
ComplexImExp implements a <– exp(i x), inline. More... | |
template<typename Real > | |
void | ComputePca (const MatrixBase< Real > &X, MatrixBase< Real > *U, MatrixBase< Real > *A, bool print_eigs=false, bool exact=true) |
ComputePCA does a PCA computation, using either outer products or inner products, whichever is more efficient. More... | |
template<typename Real > | |
void | AddOuterProductPlusMinus (Real alpha, const VectorBase< Real > &a, const VectorBase< Real > &b, MatrixBase< Real > *plus, MatrixBase< Real > *minus) |
template<typename Real1 , typename Real2 > | |
void | AssertSameDim (const MatrixBase< Real1 > &mat1, const MatrixBase< Real2 > &mat2) |
template<typename Real > | |
Real | SolveQuadraticProblem (const SpMatrix< Real > &H, const VectorBase< Real > &g, const SolverOptions &opts, VectorBase< Real > *x) |
Maximizes the auxiliary function
using a numerically stable method. More... | |
template<typename Real > | |
Real | SolveQuadraticMatrixProblem (const SpMatrix< Real > &Q, const MatrixBase< Real > &Y, const SpMatrix< Real > &P, const SolverOptions &opts, MatrixBase< Real > *M) |
Maximizes the auxiliary function :
Like a numerically stable version of . More... | |
template<typename Real > | |
Real | SolveDoubleQuadraticMatrixProblem (const MatrixBase< Real > &G, const SpMatrix< Real > &P1, const SpMatrix< Real > &P2, const SpMatrix< Real > &Q1, const SpMatrix< Real > &Q2, const SolverOptions &opts, MatrixBase< Real > *M) |
Maximizes the auxiliary function :
Encountered in matrix update with a prior. More... | |
void AddOuterProductPlusMinus | ( | Real | alpha, |
const VectorBase< Real > & | a, | ||
const VectorBase< Real > & | b, | ||
MatrixBase< Real > * | plus, | ||
MatrixBase< Real > * | minus | ||
) |
Definition at line 726 of file matrix-functions.cc.
References kaldi::AddOuterProductPlusMinus< double >(), kaldi::AddOuterProductPlusMinus< float >(), VectorBase< Real >::Data(), MatrixBase< Real >::Data(), VectorBase< Real >::Dim(), rnnlm::i, rnnlm::j, KALDI_ASSERT, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and MatrixBase< Real >::Stride().
Referenced by Fmpe::ApplyProjectionReverse(), and kaldi::UnitTestAddOuterProductPlusMinus().
|
inline |
Definition at line 161 of file matrix-functions.h.
References KALDI_ASSERT, MatrixBase< Real >::NumCols(), and MatrixBase< Real >::NumRows().
bool AttemptComplexPower | ( | Real * | x_re, |
Real * | x_im, | ||
Real | power | ||
) |
The following function is used in Matrix::Power, and separately tested, so we declare it here mainly for the testing code to see.
It takes a complex value to a power using a method that will work for noninteger powers (but will fail if the complex value is real and negative).
Definition at line 2659 of file kaldi-matrix.cc.
References kaldi::AttemptComplexPower().
Referenced by kaldi::TraceMat(), and kaldi::UnitTestComplexPower().
|
inline |
ComplexMul implements, inline, the complex operation c += (a * b).
Definition at line 38 of file matrix-functions-inl.h.
Referenced by kaldi::ComplexFftRecursive(), kaldi::ComplexFt(), SplitRadixRealFft< float >::Compute(), and kaldi::RealFft().
void ComplexFft | ( | VectorBase< Real > * | v, |
bool | forward, | ||
Vector< Real > * | tmp_work = NULL |
||
) |
The function ComplexFft does an Fft on the vector argument v.
v is a vector of even dimension, interpreted for both input and output as a vector of complex numbers i.e.
If "forward == true" this routine does the Discrete Fourier Transform (DFT), i.e.:
If "backward" it does the Inverse Discrete Fourier Transform (IDFT) WITHOUT THE FACTOR 1/N*, i.e.:
[note the sign difference on the 2 pi for the backward one.]
Note that this is the definition of the FT given in most texts, but it differs from the Numerical Recipes version in which the forward and backward algorithms are flipped.
Note that you would have to multiply by 1/N after the IDFT to get back to where you started from. We don't do this because in some contexts, the transform is made symmetric by multiplying by sqrt(N) in both passes. The user can do this by themselves.
See also SplitRadixComplexFft, declared in srfft.h, which is more efficient but only works if the length of the input is a power of 2.
Definition at line 334 of file matrix-functions.cc.
References kaldi::ComplexFftRecursive(), VectorBase< Real >::Data(), VectorBase< Real >::Dim(), kaldi::Factorize(), and KALDI_ASSERT.
Referenced by kaldi::RealFft(), kaldi::RealFftInefficient(), kaldi::UnitTestComplexFft(), and kaldi::UnitTestComplexFft2().
void ComplexFt | ( | const VectorBase< Real > & | in, |
VectorBase< Real > * | out, | ||
bool | forward | ||
) |
ComplexFt is the same as ComplexFft but it implements the Fourier transform in an inefficient way.
It is mainly included for testing purposes. See comment for ComplexFft to describe the input and outputs and what it does.
Definition at line 29 of file matrix-functions.cc.
References kaldi::ComplexAddProduct(), kaldi::ComplexImExp(), kaldi::ComplexMul(), VectorBase< Real >::Data(), VectorBase< Real >::Dim(), KALDI_ASSERT, and M_2PI.
Referenced by kaldi::UnitTestComplexFft(), kaldi::UnitTestComplexFft2(), kaldi::UnitTestComplexFt(), and kaldi::UnitTestSplitRadixComplexFft().
|
inline |
ComplexImExp implements a <– exp(i x), inline.
Definition at line 46 of file matrix-functions-inl.h.
Referenced by kaldi::ComplexFftRecursive(), kaldi::ComplexFt(), SplitRadixRealFft< float >::Compute(), and kaldi::RealFft().
|
inline |
ComplexMul implements, inline, the complex multiplication b *= a.
Definition at line 31 of file matrix-functions-inl.h.
Referenced by kaldi::ComplexFftRecursive(), kaldi::ComplexFt(), SplitRadixRealFft< float >::Compute(), kaldi::ElementwiseProductOfFft(), and kaldi::RealFft().
void ComputeDctMatrix | ( | Matrix< Real > * | M | ) |
ComputeDctMatrix computes a matrix corresponding to the DCT, such that M * v equals the DCT of vector v.
M must be square at input. This is the type = III DCT with normalization, corresponding to the following equations, where x is the signal and X is the DCT: X_0 = 1/sqrt(2*N) {n = 0}^{N-1} x_n X_k = 1/sqrt(N) {n = 0}^{N-1} x_n cos( /N (n + 1/2) k ) This matrix's transpose is its own inverse, so transposing this matrix will give the inverse DCT. Caution: the type III DCT is generally known as the "inverse DCT" (with the type II being the actual DCT), so this function is somewhatd mis-named. It was probably done this way for HTK compatibility. We don't change it because it was this way from the start and changing it would affect the feature generation.
Definition at line 592 of file matrix-functions.cc.
References rnnlm::j, KALDI_ASSERT, M_PI, rnnlm::n, MatrixBase< Real >::NumCols(), and MatrixBase< Real >::NumRows().
Referenced by DctComponent::Init(), MfccComputer::MfccComputer(), and kaldi::UnitTestDct().
void ComputePca | ( | const MatrixBase< Real > & | X, |
MatrixBase< Real > * | U, | ||
MatrixBase< Real > * | A, | ||
bool | print_eigs = false , |
||
bool | exact = true |
||
) |
ComputePCA does a PCA computation, using either outer products or inner products, whichever is more efficient.
Let D be the dimension of the data points, N be the number of data points, and G be the PCA dimension we want to retain. We assume G <= N and G <= D.
X | [in] An N x D matrix. Each row of X is a point x_i. |
U | [out] A G x D matrix. Each row of U is a basis element u_i. |
A | [out] An N x D matrix, or NULL. Each row of A is a set of coefficients in the basis for a point x_i, so A(i, g) is the coefficient of u_i in x_i. |
print_eigs | [in] If true, prints out diagnostic information about the eigenvalues. |
exact | [in] If true, does the exact computation; if false, does a much faster (but almost exact) computation based on the Lanczos method. |
Definition at line 616 of file matrix-functions.cc.
References SpMatrix< Real >::AddMat2(), MatrixBase< Real >::AddMatMat(), MatrixBase< Real >::DestructiveSvd(), SpMatrix< Real >::Eig(), KALDI_ASSERT, KALDI_LOG, KALDI_WARN, kaldi::kNoTrans, kaldi::kTrans, rnnlm::n, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), MatrixBase< Real >::OrthogonalizeRows(), Vector< Real >::Resize(), Matrix< Real >::Resize(), MatrixBase< Real >::Row(), kaldi::SortSvd(), SpMatrix< Real >::TopEigs(), and Matrix< Real >::Transpose().
Referenced by kaldi::UnitTestPca(), and kaldi::UnitTestPca2().
void CreateEigenvalueMatrix | ( | const VectorBase< Real > & | real, |
const VectorBase< Real > & | imag, | ||
MatrixBase< Real > * | D | ||
) |
Creates the eigenvalue matrix D that is part of the decomposition used Matrix::Eig.
D will be block-diagonal with blocks of size 1 (for real eigenvalues) or 2x2 for complex pairs. If a complex pair is lambda +- i*mu, D will have a corresponding 2x2 block [lambda, mu; -mu, lambda]. This function will throw if any complex eigenvalues are not in complex conjugate pairs (or the members of such pairs are not consecutively numbered).
if (im(j) < 0.0) KALDI_WARN << "Negative first im part of pair"; // TEMP
Definition at line 2623 of file kaldi-matrix.cc.
References kaldi::ApproxEqual(), kaldi::CreateEigenvalueMatrix(), VectorBase< Real >::Dim(), rnnlm::j, KALDI_ASSERT, rnnlm::n, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and MatrixBase< Real >::SetZero().
Referenced by kaldi::TraceMat(), and kaldi::UnitTestEig().
void RealFft | ( | VectorBase< Real > * | v, |
bool | forward | ||
) |
RealFft is a fourier transform of real inputs.
Internally it uses ComplexFft. The input dimension N must be even. If forward == true, it transforms from a sequence of N real points to its complex fourier transform; otherwise it goes in the reverse direction. If you call it in the forward and then reverse direction and multiply by 1.0/N, you will get back the original data. The interpretation of the complex-FFT data is as follows: the array is a sequence of complex numbers C_n of length N/2 with (real, im) format, i.e. [real0, real_{N/2}, real1, im1, real2, im2, real3, im3, ...]. See also SplitRadixRealFft, declared in srfft.h, which is more efficient but only works if the length of the input is a power of 2.
Definition at line 391 of file matrix-functions.cc.
References kaldi::ComplexAddProduct(), kaldi::ComplexFft(), kaldi::ComplexImExp(), kaldi::ComplexMul(), VectorBase< Real >::Data(), VectorBase< Real >::Dim(), KALDI_ASSERT, M_2PI, and VectorBase< Real >::Scale().
Referenced by SpectrogramComputer::Compute(), MfccComputer::Compute(), FbankComputer::Compute(), PlpComputer::Compute(), kaldi::UnitTestRealFft(), and kaldi::UnitTestRealFftSpeed().
void RealFftInefficient | ( | VectorBase< Real > * | v, |
bool | forward | ||
) |
Inefficient version of Fourier transform, for testing purposes.
RealFt has the same input and output format as RealFft above, but it is an inefficient implementation included for testing purposes.
Definition at line 350 of file matrix-functions.cc.
References kaldi::ComplexFft(), VectorBase< Real >::CopyFromVec(), VectorBase< Real >::Dim(), rnnlm::i, KALDI_ASSERT, and VectorBase< Real >::Range().
Referenced by kaldi::UnitTestRealFft(), and kaldi::UnitTestSplitRadixRealFft().
Real SolveDoubleQuadraticMatrixProblem | ( | const MatrixBase< Real > & | G, |
const SpMatrix< Real > & | P1, | ||
const SpMatrix< Real > & | P2, | ||
const SpMatrix< Real > & | Q1, | ||
const SpMatrix< Real > & | Q2, | ||
const SolverOptions & | opts, | ||
MatrixBase< Real > * | M | ||
) |
Maximizes the auxiliary function :
Encountered in matrix update with a prior.
We also apply a limit on the condition but it should be less frequently necessary, and can be set larger.
Definition at line 827 of file sp-matrix.cc.
References SpMatrix< Real >::AddMat2Sp(), MatrixBase< Real >::AddMatMat(), VectorBase< Real >::AddMatVec(), SpMatrix< Real >::AddSp(), TpMatrix< Real >::Cholesky(), rnnlm::d, TpMatrix< Real >::Invert(), MatrixBase< Real >::Invert(), SpMatrix< Real >::IsDiagonal(), SpMatrix< Real >::IsUnit(), KALDI_ASSERT, KALDI_ERR, KALDI_WARN, kaldi::kNoTrans, kaldi::kTrans, rnnlm::n, SolverOptions::name, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), PackedMatrix< Real >::NumRows(), MatrixBase< Real >::Row(), kaldi::SolveQuadraticProblem(), SpMatrix< Real >::SymPosSemiDefEig(), kaldi::VecSpVec(), and kaldi::VecVec().
Referenced by MleAmSgmm2Updater::MapUpdateM(), SolverOptions::SolverOptions(), kaldi::TraceSpSpLower(), and kaldi::UnitTestSolve().
Real SolveQuadraticMatrixProblem | ( | const SpMatrix< Real > & | Q, |
const MatrixBase< Real > & | Y, | ||
const SpMatrix< Real > & | P, | ||
const SolverOptions & | opts, | ||
MatrixBase< Real > * | M | ||
) |
Maximizes the auxiliary function :
Like a numerically stable version of .
Assumes Q and P positive semidefinite, and matrix dimensions match enough to make expressions meaningful. This is mostly as described in the SGMM paper "the subspace Gaussian mixture model – a structured model for speech recognition", but the diagonal_precondition option is newly added, to handle problems where different dimensions have very different scaling (we recommend to use the option but it's set false for back compatibility).
Definition at line 729 of file sp-matrix.cc.
References MatrixBase< Real >::AddMat(), SpMatrix< Real >::AddMat2Sp(), MatrixBase< Real >::AddMatMat(), SpMatrix< Real >::AddVec2Sp(), VectorBase< Real >::ApplyFloor(), VectorBase< Real >::ApplyPow(), SolverOptions::Check(), VectorBase< Real >::CopyDiagFromSp(), MatrixBase< Real >::CopyFromMat(), SolverOptions::diagonal_precondition, SolverOptions::eps, rnnlm::i, VectorBase< Real >::InvertElements(), SpMatrix< Real >::IsZero(), SolverOptions::K, KALDI_ASSERT, KALDI_LOG, KALDI_WARN, kaldi::kNoTrans, kaldi::kTrans, VectorBase< Real >::Max(), MatrixBase< Real >::MulColsVec(), SolverOptions::name, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), PackedMatrix< Real >::NumRows(), SolverOptions::optimize_delta, SolverOptions::print_debug_output, SpMatrix< Real >::SymPosSemiDefEig(), kaldi::TraceMatMat(), and kaldi::TraceSpSp().
Referenced by SolverOptions::SolverOptions(), kaldi::TraceSpSpLower(), kaldi::UnitTestSolve(), EbwAmSgmm2Updater::UpdateM(), MleAmSgmm2Updater::UpdateM(), EbwAmSgmm2Updater::UpdateN(), MleAmSgmm2Updater::UpdateN(), and IvectorExtractorStats::UpdateProjection().
Real kaldi::SolveQuadraticProblem | ( | const SpMatrix< Real > & | H, |
const VectorBase< Real > & | g, | ||
const SolverOptions & | opts, | ||
VectorBase< Real > * | x | ||
) |
Maximizes the auxiliary function
using a numerically stable method.
Like a numerically stable version of Assumes H positive semidefinite. Returns the objective-function change.
void SortSvd | ( | VectorBase< Real > * | s, |
MatrixBase< Real > * | U, | ||
MatrixBase< Real > * | Vt = NULL , |
||
bool | sort_on_absolute_value = true |
||
) |
Function to ensure that SVD is sorted.
This function is made as generic as possible, to be applicable to other types of problems. s->Dim() should be the same as U->NumCols(), and we sort s from greatest to least absolute value (if sort_on_absolute_value == true) or greatest to least value otherwise, moving the columns of U, if it exists, and the rows of Vt, if it exists, around in the same way. Note: the "absolute value" part won't matter if this is an actual SVD, since singular values are non-negative.
Makes sure the Svd is sorted (from greatest to least absolute value).
Definition at line 2580 of file kaldi-matrix.cc.
References rnnlm::d, VectorBase< Real >::Dim(), KALDI_ASSERT, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), MatrixBase< Real >::Row(), and kaldi::SortSvd().
Referenced by Plda::ApplyTransform(), kaldi::ComputeFeatureNormalizingTransform(), kaldi::ComputeLdaTransform(), kaldi::ComputeNormalizingTransform(), kaldi::ComputePca(), SvdApplier::DecomposeComponent(), LdaEstimate::Estimate(), BasisFmllrEstimate::EstimateFmllrBasis(), FeatureTransformEstimate::EstimateInternal(), kaldi::EstimateSgmm2FmllrSubspace(), kaldi::EstPca(), IvectorExtractorStats::GetOrthogonalIvectorTransform(), PldaEstimator::GetOutput(), AffineComponent::LimitRank(), main(), LimitRankClass::operator()(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlinePreconditioner::PreconditionDirectionsInternal(), OnlineNaturalGradient::PreconditionDirectionsInternal(), kaldi::nnet3::ReduceRankOfComponents(), SpMatrix< float >::TopEigs(), kaldi::TraceMat(), kaldi::UnitTestPca2(), kaldi::UnitTestSvdNodestroy(), and PldaUnsupervisedAdaptor::UpdatePlda().