Class for computing linear discriminant analysis (LDA) transform. More...
#include <lda-estimate.h>
Public Member Functions | |
LdaEstimate () | |
void | Init (int32 num_classes, int32 dimension) |
Allocates memory for accumulators. More... | |
int32 | NumClasses () const |
Returns the number of classes. More... | |
int32 | Dim () const |
Returns the dimensionality of the feature vectors. More... | |
void | ZeroAccumulators () |
Sets all accumulators to zero. More... | |
void | Scale (BaseFloat f) |
Scales all accumulators. More... | |
double | TotCount () |
Return total count of the data. More... | |
void | Accumulate (const VectorBase< BaseFloat > &data, int32 class_id, BaseFloat weight=1.0) |
Accumulates data. More... | |
void | Estimate (const LdaEstimateOptions &opts, Matrix< BaseFloat > *M, Matrix< BaseFloat > *Mfull=NULL) const |
Estimates the LDA transform matrix m. More... | |
void | Read (std::istream &in_stream, bool binary, bool add) |
void | Write (std::ostream &out_stream, bool binary) const |
Protected Member Functions | |
void | GetStats (SpMatrix< double > *total_covar, SpMatrix< double > *between_covar, Vector< double > *total_mean, double *sum) const |
Extract a more processed form of the stats. More... | |
LdaEstimate & | operator= (const LdaEstimate &other) |
Static Protected Member Functions | |
static void | AddMeanOffset (const VectorBase< double > &total_mean, Matrix< BaseFloat > *projection) |
This function modifies the LDA matrix so that it also subtracts the mean feature value. More... | |
Protected Attributes | |
Vector< double > | zero_acc_ |
Matrix< double > | first_acc_ |
SpMatrix< double > | total_second_acc_ |
Class for computing linear discriminant analysis (LDA) transform.
C.f. Linear Discriminant Analysis (LDA) transforms.
Definition at line 57 of file lda-estimate.h.
|
inline |
Definition at line 59 of file lda-estimate.h.
void Accumulate | ( | const VectorBase< BaseFloat > & | data, |
int32 | class_id, | ||
BaseFloat | weight = 1.0 |
||
) |
Accumulates data.
Definition at line 45 of file lda-estimate.cc.
References SpMatrix< Real >::AddVec2(), VectorBase< Real >::Dim(), LdaEstimate::Dim(), LdaEstimate::first_acc_, KALDI_ASSERT, LdaEstimate::NumClasses(), MatrixBase< Real >::Row(), LdaEstimate::total_second_acc_, and LdaEstimate::zero_acc_.
Referenced by NnetLdaStatsAccumulator::AccStatsFromOutput(), main(), and UnitTestEstimateLda().
|
staticprotected |
This function modifies the LDA matrix so that it also subtracts the mean feature value.
Definition at line 166 of file lda-estimate.cc.
References VectorBase< Real >::AddMatVec(), MatrixBase< Real >::CopyColFromVec(), kaldi::kCopyData, kaldi::kNoTrans, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and Matrix< Real >::Resize().
Referenced by LdaEstimate::Estimate(), and FeatureTransformEstimate::EstimateInternal().
|
inline |
Returns the dimensionality of the feature vectors.
Definition at line 66 of file lda-estimate.h.
Referenced by NnetLdaStatsAccumulator::AccStatsFromOutput(), LdaEstimate::Accumulate(), LdaEstimate::Estimate(), FeatureTransformEstimateMulti::Estimate(), FeatureTransformEstimateMulti::EstimateTransformPart(), LdaEstimate::GetStats(), main(), LdaEstimate::Read(), test_io(), and LdaEstimate::Write().
void Estimate | ( | const LdaEstimateOptions & | opts, |
Matrix< BaseFloat > * | M, | ||
Matrix< BaseFloat > * | Mfull = NULL |
||
) | const |
Estimates the LDA transform matrix m.
If Mfull != NULL, it also outputs the full matrix (without dimensionality reduction), which is useful for some purposes. If opts.remove_offset == true, it will output both matrices with an extra column which corresponds to mean-offset removal (the matrix should be multiplied by the feature with a 1 appended to give the correct result, as with other Kaldi transforms.) The "remove_offset" argument is new and should be set to false for back compatibility.
Definition at line 85 of file lda-estimate.cc.
References SpMatrix< Real >::AddMat2Sp(), MatrixBase< Real >::AddMatMat(), LdaEstimate::AddMeanOffset(), SpMatrix< Real >::AddSp(), LdaEstimateOptions::allow_large_dim, TpMatrix< Real >::Cholesky(), MatrixBase< Real >::CopyFromMat(), count, LdaEstimateOptions::dim, LdaEstimate::Dim(), LdaEstimate::GetStats(), rnnlm::i, MatrixBase< Real >::Invert(), KALDI_ASSERT, KALDI_LOG, kaldi::kNoTrans, kaldi::kTrans, LdaEstimate::NumClasses(), PackedMatrix< Real >::NumRows(), MatrixBase< Real >::Range(), LdaEstimateOptions::remove_offset, Matrix< Real >::Resize(), MatrixBase< Real >::Row(), kaldi::SortSvd(), MatrixBase< Real >::Svd(), SpMatrix< Real >::Trace(), and LdaEstimateOptions::within_class_factor.
Referenced by main(), test_io(), and UnitTestEstimateLda().
|
protected |
Extract a more processed form of the stats.
Definition at line 57 of file lda-estimate.cc.
References VectorBase< Real >::AddRowSumMat(), SpMatrix< Real >::AddVec2(), SpMatrix< Real >::CopyFromSp(), VectorBase< Real >::CopyRowFromMat(), LdaEstimate::Dim(), LdaEstimate::first_acc_, LdaEstimate::NumClasses(), SpMatrix< Real >::Resize(), Vector< Real >::Resize(), PackedMatrix< Real >::Scale(), VectorBase< Real >::Scale(), VectorBase< Real >::Sum(), LdaEstimate::total_second_acc_, and LdaEstimate::zero_acc_.
Referenced by LdaEstimate::Estimate(), FeatureTransformEstimate::Estimate(), and FeatureTransformEstimateMulti::Estimate().
Allocates memory for accumulators.
Definition at line 26 of file lda-estimate.cc.
References LdaEstimate::first_acc_, SpMatrix< Real >::Resize(), Vector< Real >::Resize(), Matrix< Real >::Resize(), LdaEstimate::total_second_acc_, and LdaEstimate::zero_acc_.
Referenced by NnetLdaStatsAccumulator::AccStatsFromOutput(), main(), LdaEstimate::Read(), test_io(), and UnitTestEstimateLda().
|
inline |
Returns the number of classes.
Definition at line 64 of file lda-estimate.h.
Referenced by LdaEstimate::Accumulate(), LdaEstimate::Estimate(), LdaEstimate::GetStats(), LdaEstimate::Read(), test_io(), and LdaEstimate::Write().
|
protected |
Definition at line 180 of file lda-estimate.cc.
References MatrixBase< Real >::AddMat(), SpMatrix< Real >::AddSp(), VectorBase< Real >::AddVec(), SpMatrix< Real >::AddVec2(), LdaEstimate::Dim(), kaldi::ExpectToken(), LdaEstimate::first_acc_, LdaEstimate::Init(), KALDI_ERR, LdaEstimate::NumClasses(), PackedMatrix< Real >::Read(), Vector< Real >::Read(), Matrix< Real >::Read(), kaldi::ReadBasicType(), kaldi::ReadToken(), MatrixBase< Real >::Row(), VectorBase< Real >::SetZero(), PackedMatrix< Real >::SetZero(), MatrixBase< Real >::SetZero(), LdaEstimate::total_second_acc_, and LdaEstimate::zero_acc_.
Referenced by main(), and test_io().
void Scale | ( | BaseFloat | f | ) |
Scales all accumulators.
Definition at line 38 of file lda-estimate.cc.
References rnnlm::d, LdaEstimate::first_acc_, PackedMatrix< Real >::Scale(), MatrixBase< Real >::Scale(), VectorBase< Real >::Scale(), LdaEstimate::total_second_acc_, and LdaEstimate::zero_acc_.
Referenced by test_io().
|
inline |
Return total count of the data.
Definition at line 72 of file lda-estimate.h.
Referenced by NnetLdaStatsAccumulator::WriteStats().
void Write | ( | std::ostream & | out_stream, |
bool | binary | ||
) | const |
Definition at line 237 of file lda-estimate.cc.
References SpMatrix< Real >::AddVec2(), LdaEstimate::Dim(), LdaEstimate::first_acc_, LdaEstimate::NumClasses(), MatrixBase< Real >::Row(), LdaEstimate::total_second_acc_, PackedMatrix< Real >::Write(), VectorBase< Real >::Write(), MatrixBase< Real >::Write(), kaldi::WriteBasicType(), kaldi::WriteToken(), and LdaEstimate::zero_acc_.
Referenced by main(), and test_io().
void ZeroAccumulators | ( | ) |
Sets all accumulators to zero.
Definition at line 32 of file lda-estimate.cc.
References LdaEstimate::first_acc_, VectorBase< Real >::SetZero(), PackedMatrix< Real >::SetZero(), MatrixBase< Real >::SetZero(), LdaEstimate::total_second_acc_, and LdaEstimate::zero_acc_.
Referenced by UnitTestEstimateLda().
|
protected |
Definition at line 94 of file lda-estimate.h.
Referenced by LdaEstimate::Accumulate(), LdaEstimate::GetStats(), LdaEstimate::Init(), LdaEstimate::Read(), LdaEstimate::Scale(), LdaEstimate::Write(), and LdaEstimate::ZeroAccumulators().
|
protected |
Definition at line 95 of file lda-estimate.h.
Referenced by LdaEstimate::Accumulate(), LdaEstimate::GetStats(), LdaEstimate::Init(), LdaEstimate::Read(), LdaEstimate::Scale(), LdaEstimate::Write(), and LdaEstimate::ZeroAccumulators().
|
protected |
Definition at line 93 of file lda-estimate.h.
Referenced by LdaEstimate::Accumulate(), LdaEstimate::GetStats(), LdaEstimate::Init(), LdaEstimate::Read(), LdaEstimate::Scale(), LdaEstimate::Write(), and LdaEstimate::ZeroAccumulators().