DecodableDiagGmmScaledOnline Class Reference

#include <online-gmm-decodable.h>

Inheritance diagram for DecodableDiagGmmScaledOnline:
Collaboration diagram for DecodableDiagGmmScaledOnline:

Public Member Functions

 DecodableDiagGmmScaledOnline (const AmDiagGmm &am, const TransitionModel &trans_model, const BaseFloat scale, OnlineFeatureInterface *input_feats)
 
virtual BaseFloat LogLikelihood (int32 frame, int32 index)
 Returns the scaled log likelihood. More...
 
virtual bool IsLastFrame (int32 frame) const
 Returns true if this is the last frame. 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
 Indices are one-based! This is for compatibility with OpenFst. More...
 
- Public Member Functions inherited from DecodableInterface
virtual ~DecodableInterface ()
 

Private Member Functions

void CacheFrame (int32 frame)
 
 KALDI_DISALLOW_COPY_AND_ASSIGN (DecodableDiagGmmScaledOnline)
 

Private Attributes

OnlineFeatureInterfacefeatures_
 
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-gmm-decodable.h.

Constructor & Destructor Documentation

◆ DecodableDiagGmmScaledOnline()

DecodableDiagGmmScaledOnline ( const AmDiagGmm am,
const TransitionModel trans_model,
const BaseFloat  scale,
OnlineFeatureInterface input_feats 
)

Definition at line 26 of file online-gmm-decodable.cc.

References DecodableDiagGmmScaledOnline::cache_, TransitionModel::NumPdfs(), and DecodableDiagGmmScaledOnline::trans_model_.

28  :
29  features_(input_feats), ac_model_(am),
30  ac_scale_(scale), trans_model_(trans_model),
31  feat_dim_(input_feats->Dim()), cur_feats_(feat_dim_),
32  cur_frame_(-1) {
33  int32 num_pdfs = trans_model_.NumPdfs();
34  cache_.resize(num_pdfs, std::pair<int32,BaseFloat>(-1, 0.0f));
35 }
kaldi::int32 int32
std::vector< std::pair< int32, BaseFloat > > cache_

Member Function Documentation

◆ CacheFrame()

void CacheFrame ( int32  frame)
private

Definition at line 37 of file online-gmm-decodable.cc.

References DecodableDiagGmmScaledOnline::cur_feats_, DecodableDiagGmmScaledOnline::cur_frame_, DecodableDiagGmmScaledOnline::features_, and OnlineFeatureInterface::GetFrame().

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

37  {
38  // The call below will fail if "frame" is an invalid index, i.e. <0
39  // or >= features_->NumFramesReady(), so there
40  // is no need to check again.
41  features_->GetFrame(frame, &cur_feats_);
42  cur_frame_ = frame;
43 }
virtual void GetFrame(int32 frame, VectorBase< BaseFloat > *feat)=0
Gets the feature vector for this frame.

◆ 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 58 of file online-gmm-decodable.cc.

References DecodableDiagGmmScaledOnline::features_, and OnlineFeatureInterface::IsLastFrame().

58  {
59  return features_->IsLastFrame(frame);
60 }
virtual bool IsLastFrame(int32 frame) const =0
Returns true if this is the last frame.

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( DecodableDiagGmmScaledOnline  )
private

◆ LogLikelihood()

BaseFloat LogLikelihood ( int32  frame,
int32  index 
)
virtual

Returns the scaled log likelihood.

Implements DecodableInterface.

Definition at line 45 of file online-gmm-decodable.cc.

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

45  {
46  if (frame != cur_frame_)
47  CacheFrame(frame);
48  int32 pdf_id = trans_model_.TransitionIdToPdf(index);
49  if (cache_[pdf_id].first == frame)
50  return cache_[pdf_id].second;
52  cache_[pdf_id].first = frame;
53  cache_[pdf_id].second = ans;
54  return ans;
55 }
kaldi::int32 int32
int32 TransitionIdToPdf(int32 trans_id) const
float BaseFloat
Definition: kaldi-types.h:29
BaseFloat LogLikelihood(const int32 pdf_index, const VectorBase< BaseFloat > &data) const
Definition: am-diag-gmm.h:108
std::vector< std::pair< int32, BaseFloat > > cache_

◆ NumFramesReady()

int32 NumFramesReady ( ) const
virtual

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 DecodableInterface.

Definition at line 62 of file online-gmm-decodable.cc.

References DecodableDiagGmmScaledOnline::features_, and OnlineFeatureInterface::NumFramesReady().

62  {
63  return features_->NumFramesReady();
64 }
virtual int32 NumFramesReady() const =0
returns the feature dimension.

◆ NumIndices()

virtual int32 NumIndices ( ) const
inlinevirtual

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

Implements DecodableInterface.

Definition at line 51 of file online-gmm-decodable.h.

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

51 { return trans_model_.NumTransitionIds(); }
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 57 of file online-gmm-decodable.h.

Referenced by DecodableDiagGmmScaledOnline::LogLikelihood().

◆ ac_scale_

BaseFloat ac_scale_
private

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

Referenced by DecodableDiagGmmScaledOnline::LogLikelihood().

◆ cache_

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

◆ cur_feats_

◆ cur_frame_

◆ feat_dim_

const int32 feat_dim_
private

Definition at line 60 of file online-gmm-decodable.h.

◆ features_

◆ trans_model_


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