DecodableAmDiagGmmRegtreeFmllr Class Reference

#include <decodable-am-diag-gmm-regtree.h>

Inheritance diagram for DecodableAmDiagGmmRegtreeFmllr:
Collaboration diagram for DecodableAmDiagGmmRegtreeFmllr:

Public Member Functions

 DecodableAmDiagGmmRegtreeFmllr (const AmDiagGmm &am, const TransitionModel &tm, const Matrix< BaseFloat > &feats, const RegtreeFmllrDiagGmm &fmllr_xform, const RegressionTree &regtree, BaseFloat scale, BaseFloat log_sum_exp_prune=-1.0)
 
virtual BaseFloat LogLikelihood (int32 frame, int32 tid)
 Returns the log likelihood, which will be negated in the decoder. More...
 
virtual int32 NumFramesReady () const
 The call NumFramesReady() will return the number of frames currently available for this decodable object. More...
 
virtual int32 NumIndices () const
 Returns the number of states in the acoustic model (they will be indexed one-based, i.e. More...
 
- Public Member Functions inherited from DecodableAmDiagGmmUnmapped
 DecodableAmDiagGmmUnmapped (const AmDiagGmm &am, const Matrix< BaseFloat > &feats, BaseFloat log_sum_exp_prune=-1.0)
 If you set log_sum_exp_prune to a value greater than 0 it will prune in the LogSumExp operation (larger = more exact); I suggest 5. More...
 
virtual bool IsLastFrame (int32 frame) const
 Returns true if this is the last frame. More...
 
- Public Member Functions inherited from DecodableInterface
virtual ~DecodableInterface ()
 

Protected Member Functions

virtual BaseFloat LogLikelihoodZeroBased (int32 frame, int32 state_index)
 
const TransitionModelTransModel ()
 
- Protected Member Functions inherited from DecodableAmDiagGmmUnmapped
void ResetLogLikeCache ()
 

Private Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (DecodableAmDiagGmmRegtreeFmllr)
 

Private Attributes

const TransitionModeltrans_model_
 
BaseFloat scale_
 
const RegtreeFmllrDiagGmmfmllr_xform_
 
const RegressionTreeregtree_
 
std::vector< Vector< BaseFloat > > xformed_data_
 
std::vector< Vector< BaseFloat > > xformed_data_squared_
 
Vector< BaseFloatlogdets_
 
bool valid_logdets_
 

Additional Inherited Members

- Protected Attributes inherited from DecodableAmDiagGmmUnmapped
const AmDiagGmmacoustic_model_
 
const Matrix< BaseFloat > & feature_matrix_
 
int32 previous_frame_
 
BaseFloat log_sum_exp_prune_
 
std::vector< LikelihoodCacheRecordlog_like_cache_
 

Detailed Description

Definition at line 38 of file decodable-am-diag-gmm-regtree.h.

Constructor & Destructor Documentation

◆ DecodableAmDiagGmmRegtreeFmllr()

DecodableAmDiagGmmRegtreeFmllr ( const AmDiagGmm am,
const TransitionModel tm,
const Matrix< BaseFloat > &  feats,
const RegtreeFmllrDiagGmm fmllr_xform,
const RegressionTree regtree,
BaseFloat  scale,
BaseFloat  log_sum_exp_prune = -1.0 
)
inline

Definition at line 40 of file decodable-am-diag-gmm-regtree.h.

47  : DecodableAmDiagGmmUnmapped(am, feats, log_sum_exp_prune), trans_model_(tm),
48  scale_(scale), fmllr_xform_(fmllr_xform), regtree_(regtree),
49  valid_logdets_(false) {}
DecodableAmDiagGmmUnmapped(const AmDiagGmm &am, const Matrix< BaseFloat > &feats, BaseFloat log_sum_exp_prune=-1.0)
If you set log_sum_exp_prune to a value greater than 0 it will prune in the LogSumExp operation (larg...

Member Function Documentation

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( DecodableAmDiagGmmRegtreeFmllr  )
private

◆ LogLikelihood()

virtual BaseFloat LogLikelihood ( int32  frame,
int32  index 
)
inlinevirtual

Returns the log likelihood, which will be negated in the decoder.

The "frame" starts from zero. You should verify that NumFramesReady() > frame before calling this.

Reimplemented from DecodableAmDiagGmmUnmapped.

Definition at line 52 of file decodable-am-diag-gmm-regtree.h.

References DecodableAmDiagGmmRegtreeFmllr::LogLikelihoodZeroBased(), DecodableAmDiagGmmRegtreeFmllr::scale_, DecodableAmDiagGmmRegtreeFmllr::trans_model_, and TransitionModel::TransitionIdToPdfFast().

52  {
53  return scale_*LogLikelihoodZeroBased(frame,
55  }
int32 TransitionIdToPdfFast(int32 trans_id) const
virtual BaseFloat LogLikelihoodZeroBased(int32 frame, int32 state_index)

◆ LogLikelihoodZeroBased()

BaseFloat LogLikelihoodZeroBased ( int32  frame,
int32  state_index 
)
protectedvirtual

Reimplemented from DecodableAmDiagGmmUnmapped.

Definition at line 29 of file decodable-am-diag-gmm-regtree.cc.

References DecodableAmDiagGmmUnmapped::acoustic_model_, RegtreeFmllrDiagGmm::Base2RegClass(), VectorBase< Real >::Dim(), DiagGmm::Dim(), DecodableAmDiagGmmUnmapped::feature_matrix_, DecodableAmDiagGmmRegtreeFmllr::fmllr_xform_, RegressionTree::Gauss2BaseclassId(), DiagGmm::gconsts(), RegtreeFmllrDiagGmm::GetLogDets(), AmDiagGmm::GetPdf(), DiagGmm::inv_vars(), KALDI_ASSERT, KALDI_ERR, KALDI_ISINF, KALDI_ISNAN, DecodableAmDiagGmmUnmapped::log_like_cache_, DecodableAmDiagGmmUnmapped::log_sum_exp_prune_, DecodableAmDiagGmmRegtreeFmllr::logdets_, DiagGmm::means_invvars(), DecodableAmDiagGmmRegtreeFmllr::NumFramesReady(), DiagGmm::NumGauss(), DecodableAmDiagGmmRegtreeFmllr::NumIndices(), RegtreeFmllrDiagGmm::NumRegClasses(), DecodableAmDiagGmmUnmapped::previous_frame_, DecodableAmDiagGmmRegtreeFmllr::regtree_, MatrixBase< Real >::Row(), RegtreeFmllrDiagGmm::TransformFeature(), DiagGmm::valid_gconsts(), DecodableAmDiagGmmRegtreeFmllr::valid_logdets_, kaldi::VecVec(), DecodableAmDiagGmmRegtreeFmllr::xformed_data_, and DecodableAmDiagGmmRegtreeFmllr::xformed_data_squared_.

Referenced by DecodableAmDiagGmmRegtreeFmllr::LogLikelihood(), DecodableAmDiagGmmRegtreeMllr::LogLikelihood(), DecodableAmDiagGmmRegtreeFmllr::NumIndices(), and DecodableAmDiagGmmRegtreeMllr::TransModel().

30  {
31  KALDI_ASSERT(frame < NumFramesReady() && frame >= 0);
32  KALDI_ASSERT(state < NumIndices() && state >= 0);
33 
34  if (!valid_logdets_) {
37  valid_logdets_ = true;
38  }
39 
40  if (log_like_cache_[state].hit_time == frame) {
41  return log_like_cache_[state].log_like; // return cached value, if found
42  }
43 
44  const DiagGmm &pdf = acoustic_model_.GetPdf(state);
45  const VectorBase<BaseFloat> &data = feature_matrix_.Row(frame);
46 
47  // check if everything is in order
48  if (pdf.Dim() != data.Dim()) {
49  KALDI_ERR << "Dim mismatch: data dim = " << data.Dim()
50  << " vs. model dim = " << pdf.Dim();
51  }
52  if (!pdf.valid_gconsts()) {
53  KALDI_ERR << "State " << (state) << ": Must call ComputeGconsts() "
54  "before computing likelihood.";
55  }
56 
57  if (frame != previous_frame_) { // cache the transformed & squared stats.
60  vector< Vector <BaseFloat> >::iterator it = xformed_data_squared_.begin(),
61  end = xformed_data_squared_.end();
62  for (; it != end; ++it) { it->ApplyPow(2.0); }
63  previous_frame_ = frame;
64  }
65 
66  Vector<BaseFloat> loglikes(pdf.gconsts()); // need to recreate for each pdf
67  int32 baseclass, regclass;
68  for (int32 comp_id = 0, num_comp = pdf.NumGauss(); comp_id < num_comp;
69  ++comp_id) {
70  baseclass = regtree_.Gauss2BaseclassId(state, comp_id);
71  regclass = fmllr_xform_.Base2RegClass(baseclass);
72  // loglikes += means * inv(vars) * data.
73  loglikes(comp_id) += VecVec(pdf.means_invvars().Row(comp_id),
74  xformed_data_[regclass]);
75  // loglikes += -0.5 * inv(vars) * data_sq.
76  loglikes(comp_id) -= 0.5 * VecVec(pdf.inv_vars().Row(comp_id),
77  xformed_data_squared_[regclass]);
78  loglikes(comp_id) += logdets_(regclass);
79  }
80 
81  BaseFloat log_sum = loglikes.LogSumExp(log_sum_exp_prune_);
82  if (KALDI_ISNAN(log_sum) || KALDI_ISINF(log_sum))
83  KALDI_ERR << "Invalid answer (overflow or invalid variances/features?)";
84 
85  log_like_cache_[state].log_like = log_sum;
86  log_like_cache_[state].hit_time = frame;
87 
88  return log_sum;
89 }
int32 Gauss2BaseclassId(size_t pdf_id, size_t gauss_id) const
std::vector< Vector< BaseFloat > > xformed_data_
#define KALDI_ISINF
Definition: kaldi-math.h:73
void GetLogDets(VectorBase< BaseFloat > *out) const
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
std::vector< Vector< BaseFloat > > xformed_data_squared_
virtual int32 NumIndices() const
Returns the number of states in the acoustic model (they will be indexed one-based, i.e.
void TransformFeature(const VectorBase< BaseFloat > &in, std::vector< Vector< BaseFloat > > *out) const
Get the transformed features for each of the transforms.
#define KALDI_ERR
Definition: kaldi-error.h:147
const Matrix< BaseFloat > & feature_matrix_
std::vector< LikelihoodCacheRecord > log_like_cache_
DiagGmm & GetPdf(int32 pdf_index)
Accessors.
Definition: am-diag-gmm.h:119
#define KALDI_ISNAN
Definition: kaldi-math.h:72
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
virtual int32 NumFramesReady() const
The call NumFramesReady() will return the number of frames currently available for this decodable obj...
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37
int32 Base2RegClass(int32 bclass) const

◆ NumFramesReady()

virtual int32 NumFramesReady ( ) const
inlinevirtual

The call NumFramesReady() will return the number of frames currently available for this decodable object.

This is for use in setups where you don't want the decoder to block while waiting for input. This is newly added as of Jan 2014, and I hope, going forward, to rely on this mechanism more than IsLastFrame to know when to stop decoding.

Reimplemented from DecodableAmDiagGmmUnmapped.

Definition at line 57 of file decodable-am-diag-gmm-regtree.h.

References DecodableAmDiagGmmUnmapped::feature_matrix_, and MatrixBase< Real >::NumRows().

Referenced by DecodableAmDiagGmmRegtreeFmllr::LogLikelihoodZeroBased(), DecodableAmDiagGmmRegtreeMllr::LogLikelihoodZeroBased(), and main().

57 { return feature_matrix_.NumRows(); }
const Matrix< BaseFloat > & feature_matrix_
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ NumIndices()

virtual int32 NumIndices ( ) const
inlinevirtual

Returns the number of states in the acoustic model (they will be indexed one-based, i.e.

from 1 to NumIndices(); this is for compatibility with OpenFst).

Reimplemented from DecodableAmDiagGmmUnmapped.

Definition at line 60 of file decodable-am-diag-gmm-regtree.h.

References DecodableAmDiagGmmRegtreeFmllr::LogLikelihoodZeroBased(), TransitionModel::NumTransitionIds(), and DecodableAmDiagGmmRegtreeFmllr::trans_model_.

Referenced by DecodableAmDiagGmmRegtreeFmllr::LogLikelihoodZeroBased(), and DecodableAmDiagGmmRegtreeMllr::LogLikelihoodZeroBased().

60 { return trans_model_.NumTransitionIds(); }
int32 NumTransitionIds() const
Returns the total number of transition-ids (note, these are one-based).

◆ TransModel()

const TransitionModel* TransModel ( )
inlineprotected

Member Data Documentation

◆ fmllr_xform_

const RegtreeFmllrDiagGmm& fmllr_xform_
private

◆ logdets_

◆ regtree_

◆ scale_

◆ trans_model_

◆ valid_logdets_

bool valid_logdets_
private

◆ xformed_data_

std::vector< Vector<BaseFloat> > xformed_data_
private

◆ xformed_data_squared_

std::vector< Vector<BaseFloat> > xformed_data_squared_
private

The documentation for this class was generated from the following files: