DecodableAmSgmm2 Class Reference

#include <decodable-am-sgmm2.h>

Inheritance diagram for DecodableAmSgmm2:
Collaboration diagram for DecodableAmSgmm2:

Public Member Functions

 DecodableAmSgmm2 (const AmSgmm2 &sgmm, const TransitionModel &tm, const Matrix< BaseFloat > &feats, const std::vector< std::vector< int32 > > &gselect, BaseFloat log_prune, Sgmm2PerSpkDerivedVars *spk)
 
 DecodableAmSgmm2 (const AmSgmm2 &sgmm, const TransitionModel &tm, const Matrix< BaseFloat > *feats, const std::vector< std::vector< int32 > > *gselect, Sgmm2PerSpkDerivedVars *spk, BaseFloat log_prune)
 This version of the constructor takes ownership of the pointers "feats", "gselect" and "spk", and will delete them when it is destroyed. More...
 
virtual BaseFloat LogLikelihood (int32 frame, int32 tid)
 Returns the log likelihood, which will be negated in the decoder. More...
 
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...
 
virtual bool IsLastFrame (int32 frame) const
 Returns true if this is the last frame. More...
 
virtual ~DecodableAmSgmm2 ()
 
- Public Member Functions inherited from DecodableInterface
virtual ~DecodableInterface ()
 

Protected Member Functions

virtual BaseFloat LogLikelihoodForPdf (int32 frame, int32 pdf_id)
 

Protected Attributes

const AmSgmm2sgmm_
 
Sgmm2PerSpkDerivedVarsspk_
 
const TransitionModeltrans_model_
 for tid to pdf mapping More...
 
const Matrix< BaseFloat > * feature_matrix_
 
const std::vector< std::vector< int32 > > * gselect_
 
BaseFloat log_prune_
 
int32 cur_frame_
 
Sgmm2PerFrameDerivedVars per_frame_vars_
 
Sgmm2LikelihoodCache sgmm_cache_
 
bool delete_vars_
 

Private Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (DecodableAmSgmm2)
 

Detailed Description

Definition at line 33 of file decodable-am-sgmm2.h.

Constructor & Destructor Documentation

◆ DecodableAmSgmm2() [1/2]

DecodableAmSgmm2 ( const AmSgmm2 sgmm,
const TransitionModel tm,
const Matrix< BaseFloat > &  feats,
const std::vector< std::vector< int32 > > &  gselect,
BaseFloat  log_prune,
Sgmm2PerSpkDerivedVars spk 
)
inline

Definition at line 35 of file decodable-am-sgmm2.h.

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

40  :
41  sgmm_(sgmm), spk_(spk),
42  trans_model_(tm), feature_matrix_(&feats),
43  gselect_(&gselect), log_prune_(log_prune), cur_frame_(-1),
44  sgmm_cache_(sgmm.NumGroups(), sgmm.NumPdfs()), delete_vars_(false) {
45  KALDI_ASSERT(gselect.size() == static_cast<size_t>(feats.NumRows()));
46  }
const std::vector< std::vector< int32 > > * gselect_
Sgmm2PerSpkDerivedVars * spk_
Sgmm2LikelihoodCache sgmm_cache_
const TransitionModel & trans_model_
for tid to pdf mapping
const Matrix< BaseFloat > * feature_matrix_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ DecodableAmSgmm2() [2/2]

DecodableAmSgmm2 ( const AmSgmm2 sgmm,
const TransitionModel tm,
const Matrix< BaseFloat > *  feats,
const std::vector< std::vector< int32 > > *  gselect,
Sgmm2PerSpkDerivedVars spk,
BaseFloat  log_prune 
)
inline

This version of the constructor takes ownership of the pointers "feats", "gselect" and "spk", and will delete them when it is destroyed.

Definition at line 50 of file decodable-am-sgmm2.h.

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

55  :
56  sgmm_(sgmm), spk_(spk),
57  trans_model_(tm), feature_matrix_(feats),
58  gselect_(gselect), log_prune_(log_prune), cur_frame_(-1),
59  sgmm_cache_(sgmm.NumGroups(), sgmm.NumPdfs()), delete_vars_(true) {
60  KALDI_ASSERT(gselect->size() == static_cast<size_t>(feats->NumRows()));
61  }
const std::vector< std::vector< int32 > > * gselect_
Sgmm2PerSpkDerivedVars * spk_
Sgmm2LikelihoodCache sgmm_cache_
const TransitionModel & trans_model_
for tid to pdf mapping
const Matrix< BaseFloat > * feature_matrix_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ ~DecodableAmSgmm2()

~DecodableAmSgmm2 ( )
virtual

Definition at line 29 of file decodable-am-sgmm2.cc.

References DecodableAmSgmm2::delete_vars_, DecodableAmSgmm2::feature_matrix_, DecodableAmSgmm2::gselect_, and DecodableAmSgmm2::spk_.

Referenced by DecodableAmSgmm2::IsLastFrame().

29  {
30  if (delete_vars_) {
31  delete gselect_;
32  delete feature_matrix_;
33  delete spk_;
34  }
35 }
const std::vector< std::vector< int32 > > * gselect_
Sgmm2PerSpkDerivedVars * spk_
const Matrix< BaseFloat > * feature_matrix_

Member Function Documentation

◆ IsLastFrame()

virtual bool IsLastFrame ( int32  frame) const
inlinevirtual

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 71 of file decodable-am-sgmm2.h.

References KALDI_ASSERT, DecodableAmSgmm2::LogLikelihoodForPdf(), DecodableAmSgmm2::NumFramesReady(), and DecodableAmSgmm2::~DecodableAmSgmm2().

71  {
72  KALDI_ASSERT(frame < NumFramesReady());
73  return (frame == NumFramesReady() - 1);
74  }
int32 NumFramesReady() const
The call NumFramesReady() will return the number of frames currently available for this decodable obj...
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( DecodableAmSgmm2  )
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.

Implements DecodableInterface.

Reimplemented in DecodableAmSgmm2Scaled.

Definition at line 65 of file decodable-am-sgmm2.h.

References DecodableAmSgmm2::LogLikelihoodForPdf(), DecodableAmSgmm2::trans_model_, and TransitionModel::TransitionIdToPdfFast().

65  {
67  }
int32 TransitionIdToPdfFast(int32 trans_id) const
const TransitionModel & trans_model_
for tid to pdf mapping
virtual BaseFloat LogLikelihoodForPdf(int32 frame, int32 pdf_id)

◆ LogLikelihoodForPdf()

BaseFloat LogLikelihoodForPdf ( int32  frame,
int32  pdf_id 
)
protectedvirtual

Definition at line 37 of file decodable-am-sgmm2.cc.

References AmSgmm2::ComputePerFrameVars(), DecodableAmSgmm2::cur_frame_, DecodableAmSgmm2::feature_matrix_, DecodableAmSgmm2::gselect_, DecodableAmSgmm2::log_prune_, AmSgmm2::LogLikelihood(), Sgmm2LikelihoodCache::NextFrame(), DecodableAmSgmm2::per_frame_vars_, DecodableAmSgmm2::sgmm_, DecodableAmSgmm2::sgmm_cache_, and DecodableAmSgmm2::spk_.

Referenced by DecodableAmSgmm2::IsLastFrame(), DecodableAmSgmm2::LogLikelihood(), and DecodableAmSgmm2Scaled::LogLikelihood().

37  {
38  if (frame != cur_frame_) {
39  cur_frame_ = frame;
40  sgmm_cache_.NextFrame(); // it has a frame-index internally but it doesn't
41  // have to match up with our index here, it just needs to be unique.
42 
43 
44  SubVector<BaseFloat> data(*feature_matrix_, frame);
45 
46  sgmm_.ComputePerFrameVars(data, (*gselect_)[frame], *spk_,
48  }
50  log_prune_);
51 }
const std::vector< std::vector< int32 > > * gselect_
Sgmm2PerSpkDerivedVars * spk_
Sgmm2LikelihoodCache sgmm_cache_
BaseFloat LogLikelihood(const Sgmm2PerFrameDerivedVars &per_frame_vars, int32 j2, Sgmm2LikelihoodCache *cache, Sgmm2PerSpkDerivedVars *spk_vars, BaseFloat log_prune=0.0) const
This does a likelihood computation for a given state using the pre-selected Gaussian components (in p...
Definition: am-sgmm2.cc:517
Sgmm2PerFrameDerivedVars per_frame_vars_
const Matrix< BaseFloat > * feature_matrix_
void ComputePerFrameVars(const VectorBase< BaseFloat > &data, const std::vector< int32 > &gselect, const Sgmm2PerSpkDerivedVars &spk_vars, Sgmm2PerFrameDerivedVars *per_frame_vars) const
This needs to be called with each new frame of data, prior to accumulation or likelihood evaluation: ...
Definition: am-sgmm2.cc:442

◆ NumFramesReady()

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

Definition at line 68 of file decodable-am-sgmm2.h.

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

Referenced by DecodableAmSgmm2::IsLastFrame().

68 { 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).

Implements DecodableInterface.

Definition at line 69 of file decodable-am-sgmm2.h.

References TransitionModel::NumTransitionIds(), and DecodableAmSgmm2::trans_model_.

69 { return trans_model_.NumTransitionIds(); }
const TransitionModel & trans_model_
for tid to pdf mapping
int32 NumTransitionIds() const
Returns the total number of transition-ids (note, these are one-based).

Member Data Documentation

◆ cur_frame_

int32 cur_frame_
protected

Definition at line 88 of file decodable-am-sgmm2.h.

Referenced by DecodableAmSgmm2::LogLikelihoodForPdf().

◆ delete_vars_

bool delete_vars_
protected

Definition at line 92 of file decodable-am-sgmm2.h.

Referenced by DecodableAmSgmm2::~DecodableAmSgmm2().

◆ feature_matrix_

◆ gselect_

const std::vector<std::vector<int32> >* gselect_
protected

◆ log_prune_

BaseFloat log_prune_
protected

Definition at line 86 of file decodable-am-sgmm2.h.

Referenced by DecodableAmSgmm2::LogLikelihoodForPdf().

◆ per_frame_vars_

Sgmm2PerFrameDerivedVars per_frame_vars_
protected

Definition at line 89 of file decodable-am-sgmm2.h.

Referenced by DecodableAmSgmm2::LogLikelihoodForPdf().

◆ sgmm_

const AmSgmm2& sgmm_
protected

Definition at line 80 of file decodable-am-sgmm2.h.

Referenced by DecodableAmSgmm2::LogLikelihoodForPdf().

◆ sgmm_cache_

Sgmm2LikelihoodCache sgmm_cache_
protected

Definition at line 90 of file decodable-am-sgmm2.h.

Referenced by DecodableAmSgmm2::LogLikelihoodForPdf().

◆ spk_

◆ trans_model_

const TransitionModel& trans_model_
protected

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