OnlineDecodableDiagGmmScaled Class Reference

#include <online-decodable.h>

Inheritance diagram for OnlineDecodableDiagGmmScaled:
Collaboration diagram for OnlineDecodableDiagGmmScaled:

Public Member Functions

 OnlineDecodableDiagGmmScaled (const AmDiagGmm &am, const TransitionModel &trans_model, const BaseFloat scale, OnlineFeatureMatrix *input_feats)
 
virtual BaseFloat LogLikelihood (int32 frame, int32 index)
 Returns the log likelihood, which will be negated in the decoder. More...
 
virtual bool IsLastFrame (int32 frame) const
 Returns true if this is the last frame. More...
 
virtual int32 NumIndices () const
 Indices are one-based! This is for compatibility with OpenFst. More...
 
- Public Member Functions inherited from DecodableInterface
virtual int32 NumFramesReady () const
 The call NumFramesReady() will return the number of frames currently available for this decodable object. More...
 
virtual ~DecodableInterface ()
 

Private Member Functions

void CacheFrame (int32 frame)
 
 KALDI_DISALLOW_COPY_AND_ASSIGN (OnlineDecodableDiagGmmScaled)
 

Private Attributes

OnlineFeatureMatrixfeatures_
 
const AmDiagGmmac_model_
 
BaseFloat ac_scale_
 
const TransitionModeltrans_model_
 
const int32 feat_dim_
 
Vector< BaseFloatcur_feats_
 
int32 cur_frame_
 
std::vector< std::pair< int32, BaseFloat > > cache_
 

Detailed Description

Definition at line 35 of file online-decodable.h.

Constructor & Destructor Documentation

◆ OnlineDecodableDiagGmmScaled()

OnlineDecodableDiagGmmScaled ( const AmDiagGmm am,
const TransitionModel trans_model,
const BaseFloat  scale,
OnlineFeatureMatrix input_feats 
)

Definition at line 27 of file online-decodable.cc.

References OnlineDecodableDiagGmmScaled::cache_, OnlineFeatureMatrix::IsValidFrame(), KALDI_ERR, TransitionModel::NumPdfs(), and OnlineDecodableDiagGmmScaled::trans_model_.

29  :
30  features_(input_feats), ac_model_(am),
31  ac_scale_(scale), trans_model_(trans_model),
32  feat_dim_(input_feats->Dim()), cur_frame_(-1) {
33  if (!input_feats->IsValidFrame(0)) {
34  // It's not safe to throw from a constructor, so please check
35  // this condition yourself before reaching this point in the code.
36  KALDI_ERR << "Attempt to initialize decodable object with empty "
37  << "input: please check this before the initializer!";
38  }
39  int32 num_pdfs = trans_model_.NumPdfs();
40  cache_.resize(num_pdfs, std::pair<int32,BaseFloat>(-1, 0.0));
41 }
std::vector< std::pair< int32, BaseFloat > > cache_
kaldi::int32 int32
const TransitionModel & trans_model_
#define KALDI_ERR
Definition: kaldi-error.h:147

Member Function Documentation

◆ CacheFrame()

void CacheFrame ( int32  frame)
private

Definition at line 43 of file online-decodable.cc.

References OnlineDecodableDiagGmmScaled::cur_feats_, OnlineDecodableDiagGmmScaled::cur_frame_, OnlineDecodableDiagGmmScaled::feat_dim_, OnlineDecodableDiagGmmScaled::features_, OnlineFeatureMatrix::GetFrame(), OnlineFeatureMatrix::IsValidFrame(), KALDI_ASSERT, and KALDI_ERR.

Referenced by OnlineDecodableDiagGmmScaled::LogLikelihood(), and OnlineDecodableDiagGmmScaled::NumIndices().

43  {
44  KALDI_ASSERT(frame >= 0);
45  cur_feats_.Resize(feat_dim_);
46  if (!features_->IsValidFrame(frame))
47  KALDI_ERR << "Request for invalid frame (you need to check IsLastFrame, or, "
48  << "for frame zero, check that the input is valid.";
49  cur_feats_.CopyFromVec(features_->GetFrame(frame));
50  cur_frame_ = frame;
51 }
#define KALDI_ERR
Definition: kaldi-error.h:147
SubVector< BaseFloat > GetFrame(int32 frame)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ IsLastFrame()

bool IsLastFrame ( int32  frame) const
virtual

Returns true if this is the last frame.

Frames are zero-based, so the first frame is zero. IsLastFrame(-1) will return false, unless the file is empty (which is a case that I'm not sure all the code will handle, so be careful). Caution: the behavior of this function in an online setting is being changed somewhat. In future it may return false in cases where we haven't yet decided to terminate decoding, but later true if we decide to terminate decoding. The plan in future is to rely more on NumFramesReady(), and in future, IsLastFrame() would always return false in an online-decoding setting, and would only return true in a decoding-from-matrix setting where we want to allow the last delta or LDA features to be flushed out for compatibility with the baseline setup.

Implements DecodableInterface.

Definition at line 66 of file online-decodable.cc.

References OnlineDecodableDiagGmmScaled::features_, and OnlineFeatureMatrix::IsValidFrame().

66  {
67  return !features_->IsValidFrame(frame+1);
68 }

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( OnlineDecodableDiagGmmScaled  )
private

◆ LogLikelihood()

BaseFloat LogLikelihood ( int32  frame,
int32  index 
)
virtual

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

Implements DecodableInterface.

Definition at line 53 of file online-decodable.cc.

References OnlineDecodableDiagGmmScaled::ac_model_, OnlineDecodableDiagGmmScaled::ac_scale_, OnlineDecodableDiagGmmScaled::cache_, OnlineDecodableDiagGmmScaled::CacheFrame(), OnlineDecodableDiagGmmScaled::cur_feats_, OnlineDecodableDiagGmmScaled::cur_frame_, AmDiagGmm::LogLikelihood(), OnlineDecodableDiagGmmScaled::trans_model_, and TransitionModel::TransitionIdToPdf().

53  {
54  if (frame != cur_frame_)
55  CacheFrame(frame);
56  int32 pdf_id = trans_model_.TransitionIdToPdf(index);
57  if (cache_[pdf_id].first == frame)
58  return cache_[pdf_id].second;
60  cache_[pdf_id].first = frame;
61  cache_[pdf_id].second = ans;
62  return ans;
63 }
std::vector< std::pair< int32, BaseFloat > > cache_
kaldi::int32 int32
int32 TransitionIdToPdf(int32 trans_id) const
const TransitionModel & trans_model_
float BaseFloat
Definition: kaldi-types.h:29
BaseFloat LogLikelihood(const int32 pdf_index, const VectorBase< BaseFloat > &data) const
Definition: am-diag-gmm.h:108

◆ NumIndices()

virtual int32 NumIndices ( ) const
inlinevirtual

Indices are one-based! This is for compatibility with OpenFst.

Implements DecodableInterface.

Definition at line 49 of file online-decodable.h.

References OnlineDecodableDiagGmmScaled::CacheFrame(), TransitionModel::NumTransitionIds(), and OnlineDecodableDiagGmmScaled::trans_model_.

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

Member Data Documentation

◆ ac_model_

const AmDiagGmm& ac_model_
private

Definition at line 55 of file online-decodable.h.

Referenced by OnlineDecodableDiagGmmScaled::LogLikelihood().

◆ ac_scale_

BaseFloat ac_scale_
private

Definition at line 56 of file online-decodable.h.

Referenced by OnlineDecodableDiagGmmScaled::LogLikelihood().

◆ cache_

std::vector<std::pair<int32, BaseFloat> > cache_
private

◆ cur_feats_

◆ cur_frame_

◆ feat_dim_

const int32 feat_dim_
private

Definition at line 58 of file online-decodable.h.

Referenced by OnlineDecodableDiagGmmScaled::CacheFrame().

◆ features_

◆ trans_model_


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