#include <mle-diag-gmm.h>
Public Member Functions | |
AccumDiagGmm () | |
AccumDiagGmm (const DiagGmm &gmm, GmmFlagsType flags) | |
AccumDiagGmm (const AccumDiagGmm &other) | |
void | Read (std::istream &in_stream, bool binary, bool add) |
void | Write (std::ostream &out_stream, bool binary) const |
void | Resize (int32 num_gauss, int32 dim, GmmFlagsType flags) |
Allocates memory for accumulators. More... | |
void | Resize (const DiagGmm &gmm, GmmFlagsType flags) |
Calls ResizeAccumulators with arguments based on gmm. More... | |
int32 | NumGauss () const |
Returns the number of mixture components. More... | |
int32 | Dim () const |
Returns the dimensionality of the feature vectors. More... | |
void | SetZero (GmmFlagsType flags) |
void | Scale (BaseFloat f, GmmFlagsType flags) |
void | AccumulateForComponent (const VectorBase< BaseFloat > &data, int32 comp_index, BaseFloat weight) |
Accumulate for a single component, given the posterior. More... | |
void | AccumulateFromPosteriors (const VectorBase< BaseFloat > &data, const VectorBase< BaseFloat > &gauss_posteriors) |
Accumulate for all components, given the posteriors. More... | |
BaseFloat | AccumulateFromDiag (const DiagGmm &gmm, const VectorBase< BaseFloat > &data, BaseFloat frame_posterior) |
Accumulate for all components given a diagonal-covariance GMM. More... | |
BaseFloat | AccumulateFromDiagMultiThreaded (const DiagGmm &gmm, const MatrixBase< BaseFloat > &data, const VectorBase< BaseFloat > &frame_weights, int32 num_threads) |
This does the same job as AccumulateFromDiag, but using multiple threads. More... | |
void | AddStatsForComponent (int32 comp_id, double occ, const VectorBase< double > &x_stats, const VectorBase< double > &x2_stats) |
Increment the stats for this component by the specified amount (not all parts may be taken, depending on flags). More... | |
void | Add (double scale, const AccumDiagGmm &acc) |
Increment with stats from this other accumulator (times scale) More... | |
void | SmoothStats (BaseFloat tau) |
Smooths the accumulated counts by adding 'tau' extra frames. More... | |
void | SmoothWithAccum (BaseFloat tau, const AccumDiagGmm &src_acc) |
Smooths the accumulated counts using some other accumulator. More... | |
void | SmoothWithModel (BaseFloat tau, const DiagGmm &src_gmm) |
Smooths the accumulated counts using the parameters of a given model. More... | |
GmmFlagsType | Flags () const |
const VectorBase< double > & | occupancy () const |
const MatrixBase< double > & | mean_accumulator () const |
const MatrixBase< double > & | variance_accumulator () const |
void | AssertEqual (const AccumDiagGmm &other) |
Private Attributes | |
int32 | dim_ |
int32 | num_comp_ |
GmmFlagsType | flags_ |
Flags corresponding to the accumulators that are stored. More... | |
Vector< double > | occupancy_ |
Matrix< double > | mean_accumulator_ |
Matrix< double > | variance_accumulator_ |
Definition at line 106 of file mle-diag-gmm.h.
|
inline |
Definition at line 108 of file mle-diag-gmm.h.
|
inlineexplicit |
Definition at line 109 of file mle-diag-gmm.h.
|
explicit |
Definition at line 255 of file mle-diag-gmm.cc.
void AccumulateForComponent | ( | const VectorBase< BaseFloat > & | data, |
int32 | comp_index, | ||
BaseFloat | weight | ||
) |
Accumulate for a single component, given the posterior.
Definition at line 140 of file mle-diag-gmm.cc.
References VectorBase< Real >::ApplyPow(), VectorBase< Real >::Dim(), AccumDiagGmm::Dim(), AccumDiagGmm::flags_, KALDI_ASSERT, kaldi::kGmmMeans, kaldi::kGmmVariances, AccumDiagGmm::mean_accumulator_, AccumDiagGmm::NumGauss(), AccumDiagGmm::occupancy_, MatrixBase< Real >::Row(), and AccumDiagGmm::variance_accumulator_.
Referenced by main(), and TestComponentAcc().
BaseFloat AccumulateFromDiag | ( | const DiagGmm & | gmm, |
const VectorBase< BaseFloat > & | data, | ||
BaseFloat | frame_posterior | ||
) |
Accumulate for all components given a diagonal-covariance GMM.
Computes posteriors and returns log-likelihood
Definition at line 191 of file mle-diag-gmm.cc.
References AccumDiagGmm::AccumulateFromPosteriors(), DiagGmm::ComponentPosteriors(), VectorBase< Real >::Dim(), DiagGmm::Dim(), AccumDiagGmm::Dim(), KALDI_ASSERT, DiagGmm::NumGauss(), and AccumDiagGmm::NumGauss().
Referenced by main(), test_flags_driven_update(), TestComponentAcc(), kaldi::UnitTestDiagGmmGenerate(), UnitTestEstimateDiagGmm(), and kaldi::UnitTestEstimateMmieDiagGmm().
BaseFloat AccumulateFromDiagMultiThreaded | ( | const DiagGmm & | gmm, |
const MatrixBase< BaseFloat > & | data, | ||
const VectorBase< BaseFloat > & | frame_weights, | ||
int32 | num_threads | ||
) |
This does the same job as AccumulateFromDiag, but using multiple threads.
Returns sum of (log-likelihood times frame weight) over all frames.
Definition at line 538 of file mle-diag-gmm.cc.
Referenced by kaldi::TrainOneIter(), and UnitTestEstimateDiagGmm().
void AccumulateFromPosteriors | ( | const VectorBase< BaseFloat > & | data, |
const VectorBase< BaseFloat > & | gauss_posteriors | ||
) |
Accumulate for all components, given the posteriors.
Definition at line 171 of file mle-diag-gmm.cc.
References VectorBase< Real >::AddVec(), MatrixBase< Real >::AddVecVec(), VectorBase< Real >::ApplyPow(), VectorBase< Real >::Dim(), AccumDiagGmm::Dim(), AccumDiagGmm::flags_, KALDI_ASSERT, kaldi::kGmmMeans, kaldi::kGmmVariances, AccumDiagGmm::mean_accumulator_, AccumDiagGmm::NumGauss(), AccumDiagGmm::occupancy_, and AccumDiagGmm::variance_accumulator_.
Referenced by AccumAmDiagGmm::AccumulateForGmmTwofeats(), AccumDiagGmm::AccumulateFromDiag(), and main().
void Add | ( | double | scale, |
const AccumDiagGmm & | acc | ||
) |
Increment with stats from this other accumulator (times scale)
Definition at line 399 of file mle-diag-gmm.cc.
References MatrixBase< Real >::AddMat(), VectorBase< Real >::AddVec(), AccumDiagGmm::flags_, kaldi::kGmmMeans, kaldi::kGmmVariances, AccumDiagGmm::mean_accumulator_, AccumDiagGmm::occupancy_, and AccumDiagGmm::variance_accumulator_.
void AddStatsForComponent | ( | int32 | comp_id, |
double | occ, | ||
const VectorBase< double > & | x_stats, | ||
const VectorBase< double > & | x2_stats | ||
) |
Increment the stats for this component by the specified amount (not all parts may be taken, depending on flags).
Note: x_stats and x2_stats are assumed to already be multiplied by "occ"
Definition at line 158 of file mle-diag-gmm.cc.
References AccumDiagGmm::flags_, KALDI_ASSERT, kaldi::kGmmMeans, kaldi::kGmmVariances, AccumDiagGmm::mean_accumulator_, AccumDiagGmm::NumGauss(), AccumDiagGmm::occupancy_, MatrixBase< Real >::Row(), and AccumDiagGmm::variance_accumulator_.
Referenced by kaldi::DiagGmmToStats(), kaldi::GetStatsDerivative(), and kaldi::IsmoothStatsDiagGmm().
void AssertEqual | ( | const AccumDiagGmm & | other | ) |
Definition at line 558 of file mle-diag-gmm.cc.
References VectorBase< Real >::ApproxEqual(), MatrixBase< Real >::ApproxEqual(), AccumDiagGmm::dim_, AccumDiagGmm::flags_, KALDI_ASSERT, AccumDiagGmm::mean_accumulator_, AccumDiagGmm::num_comp_, AccumDiagGmm::occupancy_, and AccumDiagGmm::variance_accumulator_.
Referenced by UnitTestEstimateDiagGmm().
|
inline |
Returns the dimensionality of the feature vectors.
Definition at line 126 of file mle-diag-gmm.h.
Referenced by AccumDiagGmm::AccumulateForComponent(), AccumDiagGmm::AccumulateFromDiag(), AccumDiagGmm::AccumulateFromPosteriors(), kaldi::DoRescalingUpdate(), kaldi::GetStatsDerivative(), kaldi::IsmoothStatsDiagGmm(), kaldi::MapDiagGmmUpdate(), kaldi::MleDiagGmmUpdate(), AccumDiagGmm::Read(), AccumDiagGmm::SmoothWithAccum(), test_io(), and kaldi::UpdateEbwDiagGmm().
|
inline |
Definition at line 182 of file mle-diag-gmm.h.
Referenced by kaldi::DoRescalingUpdate(), kaldi::GetStatsDerivative(), kaldi::IsmoothStatsDiagGmm(), kaldi::MapDiagGmmUpdate(), kaldi::MleDiagGmmUpdate(), kaldi::MlObjective(), AccumDiagGmm::Read(), AccumAmDiagGmm::Scale(), test_io(), and kaldi::UpdateEbwDiagGmm().
|
inline |
Definition at line 184 of file mle-diag-gmm.h.
Referenced by kaldi::ComputeAmGmmFeatureDeriv(), kaldi::DoRescalingUpdate(), kaldi::GetStatsDerivative(), kaldi::IsmoothStatsDiagGmm(), kaldi::MapDiagGmmUpdate(), kaldi::MleDiagGmmUpdate(), kaldi::MlObjective(), and kaldi::UpdateEbwDiagGmm().
|
inline |
Returns the number of mixture components.
Definition at line 124 of file mle-diag-gmm.h.
Referenced by AccumDiagGmm::AccumulateForComponent(), AccumDiagGmm::AccumulateFromDiag(), AccumDiagGmm::AccumulateFromPosteriors(), AccumDiagGmm::AddStatsForComponent(), kaldi::DoRescalingUpdate(), kaldi::GetStatsDerivative(), kaldi::IsmoothStatsDiagGmm(), kaldi::MapDiagGmmUpdate(), kaldi::MleDiagGmmUpdate(), AccumDiagGmm::Read(), AccumDiagGmm::SmoothWithAccum(), test_flags_driven_update(), test_io(), TestComponentAcc(), and kaldi::UpdateEbwDiagGmm().
|
inline |
Definition at line 183 of file mle-diag-gmm.h.
Referenced by kaldi::DoRescalingUpdate(), kaldi::GetStatsDerivative(), kaldi::IsmoothStatsDiagGmm(), main(), kaldi::MapDiagGmmUpdate(), kaldi::MleDiagGmmUpdate(), kaldi::MlObjective(), AccumAmDiagGmm::TotStatsCount(), kaldi::UpdateEbwDiagGmm(), and kaldi::UpdateEbwWeightsDiagGmm().
Definition at line 33 of file mle-diag-gmm.cc.
References AccumDiagGmm::Dim(), kaldi::ExpectToken(), AccumDiagGmm::Flags(), kaldi::GmmFlagsToString(), KALDI_ERR, AccumDiagGmm::mean_accumulator_, AccumDiagGmm::NumGauss(), AccumDiagGmm::occupancy_, Vector< Real >::Read(), Matrix< Real >::Read(), kaldi::ReadBasicType(), kaldi::ReadToken(), AccumDiagGmm::Resize(), and AccumDiagGmm::variance_accumulator_.
Referenced by main(), test_io(), and UnitTestEstimateDiagGmm().
void Resize | ( | int32 | num_gauss, |
int32 | dim, | ||
GmmFlagsType | flags | ||
) |
Allocates memory for accumulators.
Definition at line 106 of file mle-diag-gmm.cc.
References kaldi::AugmentGmmFlags(), AccumDiagGmm::dim_, AccumDiagGmm::flags_, KALDI_ASSERT, kaldi::kGmmMeans, kaldi::kGmmVariances, AccumDiagGmm::mean_accumulator_, AccumDiagGmm::num_comp_, AccumDiagGmm::occupancy_, Vector< Real >::Resize(), Matrix< Real >::Resize(), and AccumDiagGmm::variance_accumulator_.
Referenced by kaldi::DiagGmmToStats(), kaldi::GetStatsDerivative(), main(), AccumDiagGmm::Read(), test_flags_driven_update(), test_io(), TestComponentAcc(), UnitTestEstimateDiagGmm(), and kaldi::UnitTestEstimateMmieDiagGmm().
|
inline |
Calls ResizeAccumulators with arguments based on gmm.
Definition at line 206 of file mle-diag-gmm.h.
References DiagGmm::Dim(), kaldi::MapDiagGmmUpdate(), kaldi::MleDiagGmmUpdate(), kaldi::MlObjective(), and DiagGmm::NumGauss().
void Scale | ( | BaseFloat | f, |
GmmFlagsType | flags | ||
) |
Definition at line 131 of file mle-diag-gmm.cc.
References rnnlm::d, AccumDiagGmm::flags_, KALDI_ERR, kaldi::kGmmMeans, kaldi::kGmmVariances, kaldi::kGmmWeights, AccumDiagGmm::mean_accumulator_, AccumDiagGmm::occupancy_, MatrixBase< Real >::Scale(), VectorBase< Real >::Scale(), and AccumDiagGmm::variance_accumulator_.
Referenced by AccumAmDiagGmm::Scale(), and test_io().
void SetZero | ( | GmmFlagsType | flags | ) |
Definition at line 122 of file mle-diag-gmm.cc.
References AccumDiagGmm::flags_, KALDI_ERR, kaldi::kGmmMeans, kaldi::kGmmVariances, kaldi::kGmmWeights, AccumDiagGmm::mean_accumulator_, AccumDiagGmm::occupancy_, VectorBase< Real >::SetZero(), MatrixBase< Real >::SetZero(), and AccumDiagGmm::variance_accumulator_.
Referenced by test_flags_driven_update(), TestComponentAcc(), UnitTestEstimateDiagGmm(), and kaldi::UnitTestEstimateMmieDiagGmm().
void SmoothStats | ( | BaseFloat | tau | ) |
Smooths the accumulated counts by adding 'tau' extra frames.
An example use for this is I-smoothing for MMIE. Calls SmoothWithAccum.
Definition at line 208 of file mle-diag-gmm.cc.
References VectorBase< Real >::Add(), VectorBase< Real >::InvertElements(), AccumDiagGmm::mean_accumulator_, MatrixBase< Real >::MulRowsVec(), AccumDiagGmm::occupancy_, VectorBase< Real >::Scale(), and AccumDiagGmm::variance_accumulator_.
void SmoothWithAccum | ( | BaseFloat | tau, |
const AccumDiagGmm & | src_acc | ||
) |
Smooths the accumulated counts using some other accumulator.
Performs a weighted sum of the current accumulator with the given one. An example use for this is I-smoothing for MMI and MPE. Both accumulators must have the same dimension and number of components.
Definition at line 225 of file mle-diag-gmm.cc.
References AccumDiagGmm::Dim(), AccumDiagGmm::dim_, rnnlm::i, KALDI_ASSERT, KALDI_WARN, AccumDiagGmm::mean_accumulator_, AccumDiagGmm::num_comp_, AccumDiagGmm::NumGauss(), AccumDiagGmm::occupancy_, MatrixBase< Real >::Row(), and AccumDiagGmm::variance_accumulator_.
Smooths the accumulated counts using the parameters of a given model.
An example use of this is MAP-adaptation. The model must have the same dimension and number of components as the current accumulator.
Definition at line 240 of file mle-diag-gmm.cc.
References VectorBase< Real >::Add(), MatrixBase< Real >::AddMat(), DiagGmm::Dim(), AccumDiagGmm::dim_, DiagGmm::GetMeans(), DiagGmm::GetVars(), KALDI_ASSERT, kaldi::kNoTrans, AccumDiagGmm::mean_accumulator_, AccumDiagGmm::num_comp_, DiagGmm::NumGauss(), AccumDiagGmm::occupancy_, and AccumDiagGmm::variance_accumulator_.
|
inline |
Definition at line 185 of file mle-diag-gmm.h.
References kaldi::AssertEqual().
Referenced by kaldi::ComputeAmGmmFeatureDeriv(), kaldi::DoRescalingUpdate(), kaldi::GetStatsDerivative(), kaldi::IsmoothStatsDiagGmm(), kaldi::MapDiagGmmUpdate(), kaldi::MleDiagGmmUpdate(), kaldi::MlObjective(), and kaldi::UpdateEbwDiagGmm().
void Write | ( | std::ostream & | out_stream, |
bool | binary | ||
) | const |
Definition at line 77 of file mle-diag-gmm.cc.
References MatrixBase< Real >::CopyFromMat(), VectorBase< Real >::Dim(), AccumDiagGmm::dim_, AccumDiagGmm::flags_, AccumDiagGmm::mean_accumulator_, AccumDiagGmm::num_comp_, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), AccumDiagGmm::occupancy_, AccumDiagGmm::variance_accumulator_, kaldi::WriteBasicType(), and kaldi::WriteToken().
Referenced by main(), test_io(), and UnitTestEstimateDiagGmm().
|
private |
Definition at line 190 of file mle-diag-gmm.h.
Referenced by AccumDiagGmm::AssertEqual(), AccumDiagGmm::Resize(), AccumDiagGmm::SmoothWithAccum(), AccumDiagGmm::SmoothWithModel(), and AccumDiagGmm::Write().
|
private |
Flags corresponding to the accumulators that are stored.
Definition at line 193 of file mle-diag-gmm.h.
Referenced by AccumDiagGmm::AccumulateForComponent(), AccumDiagGmm::AccumulateFromPosteriors(), AccumDiagGmm::Add(), AccumDiagGmm::AddStatsForComponent(), AccumDiagGmm::AssertEqual(), AccumDiagGmm::Resize(), AccumDiagGmm::Scale(), AccumDiagGmm::SetZero(), and AccumDiagGmm::Write().
|
private |
Definition at line 196 of file mle-diag-gmm.h.
Referenced by AccumDiagGmm::AccumulateForComponent(), AccumDiagGmm::AccumulateFromPosteriors(), AccumDiagGmm::Add(), AccumDiagGmm::AddStatsForComponent(), AccumDiagGmm::AssertEqual(), AccumDiagGmm::Read(), AccumDiagGmm::Resize(), AccumDiagGmm::Scale(), AccumDiagGmm::SetZero(), AccumDiagGmm::SmoothStats(), AccumDiagGmm::SmoothWithAccum(), AccumDiagGmm::SmoothWithModel(), and AccumDiagGmm::Write().
|
private |
Definition at line 191 of file mle-diag-gmm.h.
Referenced by AccumDiagGmm::AssertEqual(), AccumDiagGmm::Resize(), AccumDiagGmm::SmoothWithAccum(), AccumDiagGmm::SmoothWithModel(), and AccumDiagGmm::Write().
|
private |
Definition at line 195 of file mle-diag-gmm.h.
Referenced by AccumDiagGmm::AccumulateForComponent(), AccumDiagGmm::AccumulateFromPosteriors(), AccumDiagGmm::Add(), AccumDiagGmm::AddStatsForComponent(), AccumDiagGmm::AssertEqual(), AccumDiagGmm::Read(), AccumDiagGmm::Resize(), AccumDiagGmm::Scale(), AccumDiagGmm::SetZero(), AccumDiagGmm::SmoothStats(), AccumDiagGmm::SmoothWithAccum(), AccumDiagGmm::SmoothWithModel(), and AccumDiagGmm::Write().
|
private |
Definition at line 197 of file mle-diag-gmm.h.
Referenced by AccumDiagGmm::AccumulateForComponent(), AccumDiagGmm::AccumulateFromPosteriors(), AccumDiagGmm::Add(), AccumDiagGmm::AddStatsForComponent(), AccumDiagGmm::AssertEqual(), AccumDiagGmm::Read(), AccumDiagGmm::Resize(), AccumDiagGmm::Scale(), AccumDiagGmm::SetZero(), AccumDiagGmm::SmoothStats(), AccumDiagGmm::SmoothWithAccum(), AccumDiagGmm::SmoothWithModel(), and AccumDiagGmm::Write().