All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
OnlineCmvn Class Reference

This class does an online version of the cepstral mean and [optionally] variance, but note that this is not equivalent to the offline version. More...

#include <online-feature.h>

Inheritance diagram for OnlineCmvn:
Collaboration diagram for OnlineCmvn:

Public Member Functions

virtual int32 Dim () const
 
virtual bool IsLastFrame (int32 frame) const
 Returns true if this is the last frame. More...
 
virtual BaseFloat FrameShiftInSeconds () const
 
virtual int32 NumFramesReady () const
 returns the feature dimension. More...
 
virtual void GetFrame (int32 frame, VectorBase< BaseFloat > *feat)
 Gets the feature vector for this frame. More...
 
 OnlineCmvn (const OnlineCmvnOptions &opts, const OnlineCmvnState &cmvn_state, OnlineFeatureInterface *src)
 Initializer that sets the cmvn state. More...
 
 OnlineCmvn (const OnlineCmvnOptions &opts, OnlineFeatureInterface *src)
 Initializer that does not set the cmvn state: after calling this, you should call SetState(). More...
 
void GetState (int32 cur_frame, OnlineCmvnState *cmvn_state)
 
void SetState (const OnlineCmvnState &cmvn_state)
 
void Freeze (int32 cur_frame)
 
virtual ~OnlineCmvn ()
 
- Public Member Functions inherited from OnlineFeatureInterface
virtual ~OnlineFeatureInterface ()
 Virtual destructor. More...
 

Private Member Functions

void GetMostRecentCachedFrame (int32 frame, int32 *cached_frame, Matrix< double > *stats)
 Get the most recent cached frame of CMVN stats. More...
 
void CacheFrame (int32 frame, const Matrix< double > &stats)
 Cache this frame of stats. More...
 
void InitRingBufferIfNeeded ()
 Initialize ring buffer for caching stats. More...
 
void ComputeStatsForFrame (int32 frame, MatrixBase< double > *stats)
 Computes the raw CMVN stats for this frame, making use of (and updating if necessary) the cached statistics in raw_stats_. More...
 

Static Private Member Functions

static void SmoothOnlineCmvnStats (const MatrixBase< double > &speaker_stats, const MatrixBase< double > &global_stats, const OnlineCmvnOptions &opts, MatrixBase< double > *stats)
 Smooth the CMVN stats "stats" (which are stored in the normal format as a 2 x (dim+1) matrix), by possibly adding some stats from "global_stats" and/or "speaker_stats", controlled by the config. More...
 

Private Attributes

OnlineCmvnOptions opts_
 
std::vector< int32 > skip_dims_
 
OnlineCmvnState orig_state_
 
Matrix< double > frozen_state_
 
std::vector< Matrix< double > * > cached_stats_modulo_
 
std::vector< std::pair< int32,
Matrix< double > > > 
cached_stats_ring_
 
OnlineFeatureInterfacesrc_
 

Detailed Description

This class does an online version of the cepstral mean and [optionally] variance, but note that this is not equivalent to the offline version.

This is necessarily so, as the offline computation involves looking into the future. If you plan to use features normalized with this type of CMVN then you need to train in a `matched' way, i.e. with the same type of features. We normally only do so in the "online" GMM-based decoding, e.g. in online2bin/online2-wav-gmm-latgen-faster.cc; see also the script steps/online/prepare_online_decoding.sh and steps/online/decode.sh.

In the steady state (in the middle of a long utterance), this class accumulates CMVN statistics from the previous "cmn_window" frames (default 600 frames, or 6 seconds), and uses these to normalize the mean and possibly variance of the current frame.

The config variables "speaker_frames" and "global_frames" relate to what happens at the beginning of the utterance when we have seen fewer than "cmn_window" frames of context, and so might not have very good stats to normalize with. Basically, we first augment any existing stats with up to "speaker_frames" frames of stats from previous utterances of the current speaker, and if this doesn't take us up to the required "cmn_window" frame count, we further augment with up to "global_frames" frames of global stats. The global stats are CMVN stats accumulated from training or testing data, that give us a reasonable source of mean and variance for "typical" data.

Definition at line 291 of file online-feature.h.

Constructor & Destructor Documentation

OnlineCmvn ( const OnlineCmvnOptions opts,
const OnlineCmvnState cmvn_state,
OnlineFeatureInterface src 
)

Initializer that sets the cmvn state.

If you don't have previous utterances from the same speaker you are supposed to initialize the CMVN state from some global CMVN stats, which you can get from summing all cmvn stats you have in your training data using "sum-matrix". This just gives it a reasonable starting point at the start of the file. If you do have previous utterances from the same speaker or at least a similar environment, you are supposed to initialize it by calling GetState from the previous utterance

Definition at line 143 of file online-feature.cc.

References KALDI_ERR, OnlineCmvn::SetState(), OnlineCmvnOptions::skip_dims, OnlineCmvn::skip_dims_, and kaldi::SplitStringToIntegers().

145  :
146  opts_(opts), src_(src) {
147  SetState(cmvn_state);
148  if (!SplitStringToIntegers(opts.skip_dims, ":", false, &skip_dims_))
149  KALDI_ERR << "Bad --skip-dims option (should be colon-separated list of "
150  << "integers)";
151 }
bool SplitStringToIntegers(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
Split a string (e.g.
Definition: text-utils.h:64
OnlineFeatureInterface * src_
void SetState(const OnlineCmvnState &cmvn_state)
#define KALDI_ERR
Definition: kaldi-error.h:127
std::vector< int32 > skip_dims_
OnlineCmvnOptions opts_
OnlineCmvn ( const OnlineCmvnOptions opts,
OnlineFeatureInterface src 
)

Initializer that does not set the cmvn state: after calling this, you should call SetState().

Definition at line 153 of file online-feature.cc.

References KALDI_ERR, OnlineCmvnOptions::skip_dims, OnlineCmvn::skip_dims_, and kaldi::SplitStringToIntegers().

154  : opts_(opts), src_(src) {
155  if (!SplitStringToIntegers(opts.skip_dims, ":", false, &skip_dims_))
156  KALDI_ERR << "Bad --skip-dims option (should be colon-separated list of "
157  << "integers)";
158 }
bool SplitStringToIntegers(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
Split a string (e.g.
Definition: text-utils.h:64
OnlineFeatureInterface * src_
#define KALDI_ERR
Definition: kaldi-error.h:127
std::vector< int32 > skip_dims_
OnlineCmvnOptions opts_
~OnlineCmvn ( )
virtual

Definition at line 231 of file online-feature.cc.

References OnlineCmvn::cached_stats_modulo_, and rnnlm::i.

231  {
232  for (size_t i = 0; i < cached_stats_modulo_.size(); i++)
233  delete cached_stats_modulo_[i];
234  cached_stats_modulo_.clear();
235 }
std::vector< Matrix< double > * > cached_stats_modulo_

Member Function Documentation

void CacheFrame ( int32  frame,
const Matrix< double > &  stats 
)
private

Cache this frame of stats.

Definition at line 205 of file online-feature.cc.

References OnlineCmvn::cached_stats_modulo_, OnlineCmvn::cached_stats_ring_, OnlineCmvn::InitRingBufferIfNeeded(), KALDI_ASSERT, KALDI_WARN, OnlineCmvnOptions::modulus, rnnlm::n, and OnlineCmvn::opts_.

Referenced by OnlineCmvn::ComputeStatsForFrame().

205  {
206  KALDI_ASSERT(frame >= 0);
207  if (frame % opts_.modulus == 0) { // store in cached_stats_modulo_.
208  int32 n = frame / opts_.modulus;
209  if (n >= cached_stats_modulo_.size()) {
210  // The following assert is a limitation on in what order you can call
211  // CacheFrame. Fortunately the calling code always calls it in sequence,
212  // which it has to because you need a previous frame to compute the
213  // current one.
214  KALDI_ASSERT(n == cached_stats_modulo_.size());
215  cached_stats_modulo_.push_back(new Matrix<double>(stats));
216  } else {
217  KALDI_WARN << "Did not expect to reach this part of code.";
218  // do what seems right, but we shouldn't get here.
219  cached_stats_modulo_[n]->CopyFromMat(stats);
220  }
221  } else { // store in the ring buffer.
223  if (!cached_stats_ring_.empty()) {
224  int32 index = frame % cached_stats_ring_.size();
225  cached_stats_ring_[index].first = frame;
226  cached_stats_ring_[index].second.CopyFromMat(stats);
227  }
228  }
229 }
void InitRingBufferIfNeeded()
Initialize ring buffer for caching stats.
std::vector< std::pair< int32, Matrix< double > > > cached_stats_ring_
struct rnnlm::@11::@12 n
#define KALDI_WARN
Definition: kaldi-error.h:130
OnlineCmvnOptions opts_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
std::vector< Matrix< double > * > cached_stats_modulo_
void ComputeStatsForFrame ( int32  frame,
MatrixBase< double > *  stats 
)
private

Computes the raw CMVN stats for this frame, making use of (and updating if necessary) the cached statistics in raw_stats_.

This means the (x, x^2, count) stats for the last up to opts_.cmn_window frames.

Definition at line 237 of file online-feature.cc.

References OnlineCmvn::CacheFrame(), OnlineCmvnOptions::cmn_window, MatrixBase< Real >::CopyFromMat(), VectorBase< Real >::CopyFromVec(), OnlineCmvn::Dim(), OnlineFeatureInterface::GetFrame(), OnlineCmvn::GetMostRecentCachedFrame(), KALDI_ASSERT, OnlineCmvn::NumFramesReady(), OnlineCmvn::opts_, MatrixBase< Real >::Row(), and OnlineCmvn::src_.

Referenced by OnlineCmvn::Freeze(), and OnlineCmvn::GetFrame().

238  {
239  KALDI_ASSERT(frame >= 0 && frame < src_->NumFramesReady());
240 
241  int32 dim = this->Dim(), cur_frame;
242  Matrix<double> stats(2, dim + 1);
243  GetMostRecentCachedFrame(frame, &cur_frame, &stats);
244 
245  Vector<BaseFloat> feats(dim);
246  Vector<double> feats_dbl(dim);
247  while (cur_frame < frame) {
248  cur_frame++;
249  src_->GetFrame(cur_frame, &feats);
250  feats_dbl.CopyFromVec(feats);
251  stats.Row(0).Range(0, dim).AddVec(1.0, feats_dbl);
252  stats.Row(1).Range(0, dim).AddVec2(1.0, feats_dbl);
253  stats(0, dim) += 1.0;
254  // it's a sliding buffer; a frame at the back may be
255  // leaving the buffer so we have to subtract that.
256  int32 prev_frame = cur_frame - opts_.cmn_window;
257  if (prev_frame >= 0) {
258  // we need to subtract frame prev_f from the stats.
259  src_->GetFrame(prev_frame, &feats);
260  feats_dbl.CopyFromVec(feats);
261  stats.Row(0).Range(0, dim).AddVec(-1.0, feats_dbl);
262  stats.Row(1).Range(0, dim).AddVec2(-1.0, feats_dbl);
263  stats(0, dim) -= 1.0;
264  }
265  CacheFrame(cur_frame, stats);
266  }
267  stats_out->CopyFromMat(stats);
268 }
virtual int32 Dim() const
virtual void GetFrame(int32 frame, VectorBase< BaseFloat > *feat)=0
Gets the feature vector for this frame.
OnlineFeatureInterface * src_
void GetMostRecentCachedFrame(int32 frame, int32 *cached_frame, Matrix< double > *stats)
Get the most recent cached frame of CMVN stats.
OnlineCmvnOptions opts_
void CacheFrame(int32 frame, const Matrix< double > &stats)
Cache this frame of stats.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
virtual int32 NumFramesReady() const
returns the feature dimension.
virtual int32 Dim ( ) const
inlinevirtual
virtual BaseFloat FrameShiftInSeconds ( ) const
inlinevirtual

Implements OnlineFeatureInterface.

Definition at line 302 of file online-feature.h.

References OnlineFeatureInterface::FrameShiftInSeconds(), and OnlineCmvn::src_.

302  {
303  return src_->FrameShiftInSeconds();
304  }
OnlineFeatureInterface * src_
virtual BaseFloat FrameShiftInSeconds() const =0
void Freeze ( int32  cur_frame)

Definition at line 342 of file online-feature.cc.

References OnlineCmvn::ComputeStatsForFrame(), OnlineCmvn::Dim(), OnlineCmvn::frozen_state_, OnlineCmvnState::global_cmvn_stats, OnlineCmvn::opts_, OnlineCmvn::orig_state_, OnlineCmvn::SmoothOnlineCmvnStats(), and OnlineCmvnState::speaker_cmvn_stats.

342  {
343  int32 dim = this->Dim();
344  Matrix<double> stats(2, dim + 1);
345  // get the raw CMVN stats
346  this->ComputeStatsForFrame(cur_frame, &stats);
347  // now smooth them.
350  opts_,
351  &stats);
352  this->frozen_state_ = stats;
353 }
Matrix< double > speaker_cmvn_stats
virtual int32 Dim() const
Matrix< double > frozen_state_
OnlineCmvnState orig_state_
OnlineCmvnOptions opts_
void ComputeStatsForFrame(int32 frame, MatrixBase< double > *stats)
Computes the raw CMVN stats for this frame, making use of (and updating if necessary) the cached stat...
static void SmoothOnlineCmvnStats(const MatrixBase< double > &speaker_stats, const MatrixBase< double > &global_stats, const OnlineCmvnOptions &opts, MatrixBase< double > *stats)
Smooth the CMVN stats "stats" (which are stored in the normal format as a 2 x (dim+1) matrix)...
Matrix< double > global_cmvn_stats
void GetFrame ( int32  frame,
VectorBase< BaseFloat > *  feat 
)
virtual

Gets the feature vector for this frame.

Before calling this for a given frame, it is assumed that you called NumFramesReady() and it returned a number greater than "frame". Otherwise this call will likely crash with an assert failure. This function is not declared const, in case there is some kind of caching going on, but most of the time it shouldn't modify the class.

Implements OnlineFeatureInterface.

Definition at line 309 of file online-feature.cc.

References kaldi::ApplyCmvn(), OnlineCmvn::ComputeStatsForFrame(), MatrixBase< Real >::CopyFromMat(), VectorBase< Real >::CopyFromVec(), VectorBase< Real >::Dim(), OnlineCmvn::Dim(), kaldi::FakeStatsForSomeDims(), OnlineCmvn::frozen_state_, OnlineFeatureInterface::GetFrame(), OnlineCmvnState::global_cmvn_stats, KALDI_ASSERT, OnlineCmvnOptions::normalize_mean, OnlineCmvnOptions::normalize_variance, MatrixBase< Real >::NumRows(), OnlineCmvn::opts_, OnlineCmvn::orig_state_, MatrixBase< Real >::Row(), OnlineCmvn::skip_dims_, OnlineCmvn::SmoothOnlineCmvnStats(), OnlineCmvnState::speaker_cmvn_stats, and OnlineCmvn::src_.

310  {
311  src_->GetFrame(frame, feat);
312  KALDI_ASSERT(feat->Dim() == this->Dim());
313  int32 dim = feat->Dim();
314  Matrix<double> stats(2, dim + 1);
315  if (frozen_state_.NumRows() != 0) { // the CMVN state has been frozen.
316  stats.CopyFromMat(frozen_state_);
317  } else {
318  // first get the raw CMVN stats (this involves caching..)
319  this->ComputeStatsForFrame(frame, &stats);
320  // now smooth them.
323  opts_,
324  &stats);
325  }
326 
327  if (!skip_dims_.empty())
329 
330  // call the function ApplyCmvn declared in ../transform/cmvn.h, which
331  // requires a matrix.
332  Matrix<BaseFloat> feat_mat(1, dim);
333  feat_mat.Row(0).CopyFromVec(*feat);
334  // the function ApplyCmvn takes a matrix, so form a one-row matrix to give it.
335  if (opts_.normalize_mean)
336  ApplyCmvn(stats, opts_.normalize_variance, &feat_mat);
337  else
339  feat->CopyFromVec(feat_mat.Row(0));
340 }
Matrix< double > speaker_cmvn_stats
virtual int32 Dim() const
virtual void GetFrame(int32 frame, VectorBase< BaseFloat > *feat)=0
Gets the feature vector for this frame.
Matrix< double > frozen_state_
OnlineFeatureInterface * src_
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
std::vector< int32 > skip_dims_
OnlineCmvnState orig_state_
OnlineCmvnOptions opts_
MatrixIndexT NumRows() const
Returns number of rows (or zero for emtpy matrix).
Definition: kaldi-matrix.h:58
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void ComputeStatsForFrame(int32 frame, MatrixBase< double > *stats)
Computes the raw CMVN stats for this frame, making use of (and updating if necessary) the cached stat...
static void SmoothOnlineCmvnStats(const MatrixBase< double > &speaker_stats, const MatrixBase< double > &global_stats, const OnlineCmvnOptions &opts, MatrixBase< double > *stats)
Smooth the CMVN stats "stats" (which are stored in the normal format as a 2 x (dim+1) matrix)...
Matrix< double > global_cmvn_stats
void ApplyCmvn(const MatrixBase< double > &stats, bool var_norm, MatrixBase< BaseFloat > *feats)
Apply cepstral mean and variance normalization to a matrix of features.
Definition: cmvn.cc:64
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:62
void FakeStatsForSomeDims(const std::vector< int32 > &dims, MatrixBase< double > *stats)
Modify the stats so that for some dimensions (specified in "dims"), we replace them with "fake" stats...
Definition: cmvn.cc:166
void GetMostRecentCachedFrame ( int32  frame,
int32 *  cached_frame,
Matrix< double > *  stats 
)
private

Get the most recent cached frame of CMVN stats.

[If no frames were cached, sets up empty stats for frame zero and returns that].

Definition at line 161 of file online-feature.cc.

References OnlineCmvn::cached_stats_modulo_, OnlineCmvn::cached_stats_ring_, OnlineCmvn::Dim(), OnlineCmvn::InitRingBufferIfNeeded(), KALDI_ASSERT, OnlineCmvnOptions::modulus, rnnlm::n, OnlineCmvn::opts_, Matrix< Real >::Resize(), and OnlineCmvnOptions::ring_buffer_size.

Referenced by OnlineCmvn::ComputeStatsForFrame().

163  {
164  KALDI_ASSERT(frame >= 0);
166  // look for a cached frame on a previous frame as close as possible in time
167  // to "frame". Return if we get one.
168  for (int32 t = frame; t >= 0 && t >= frame - opts_.ring_buffer_size; t--) {
169  if (t % opts_.modulus == 0) {
170  // if this frame should be cached in cached_stats_modulo_, then
171  // we'll look there, and we won't go back any further in time.
172  break;
173  }
174  int32 index = t % opts_.ring_buffer_size;
175  if (cached_stats_ring_[index].first == t) {
176  *cached_frame = t;
177  *stats = cached_stats_ring_[index].second;
178  return;
179  }
180  }
181  int32 n = frame / opts_.modulus;
182  if (n >= cached_stats_modulo_.size()) {
183  if (cached_stats_modulo_.size() == 0) {
184  *cached_frame = -1;
185  stats->Resize(2, this->Dim() + 1);
186  return;
187  } else {
188  n = static_cast<int32>(cached_stats_modulo_.size() - 1);
189  }
190  }
191  *cached_frame = n * opts_.modulus;
193  *stats = *(cached_stats_modulo_[n]);
194 }
virtual int32 Dim() const
void InitRingBufferIfNeeded()
Initialize ring buffer for caching stats.
std::vector< std::pair< int32, Matrix< double > > > cached_stats_ring_
struct rnnlm::@11::@12 n
OnlineCmvnOptions opts_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
std::vector< Matrix< double > * > cached_stats_modulo_
void GetState ( int32  cur_frame,
OnlineCmvnState cmvn_state 
)

Definition at line 355 of file online-feature.cc.

References VectorBase< Real >::CopyFromVec(), OnlineCmvn::Dim(), OnlineCmvnState::frozen_state, OnlineCmvn::frozen_state_, OnlineFeatureInterface::GetFrame(), MatrixBase< Real >::NumRows(), OnlineCmvn::orig_state_, Matrix< Real >::Resize(), MatrixBase< Real >::Row(), OnlineCmvnState::speaker_cmvn_stats, and OnlineCmvn::src_.

356  {
357  *state_out = this->orig_state_;
358  { // This block updates state_out->speaker_cmvn_stats
359  int32 dim = this->Dim();
360  if (state_out->speaker_cmvn_stats.NumRows() == 0)
361  state_out->speaker_cmvn_stats.Resize(2, dim + 1);
362  Vector<BaseFloat> feat(dim);
363  Vector<double> feat_dbl(dim);
364  for (int32 t = 0; t <= cur_frame; t++) {
365  src_->GetFrame(t, &feat);
366  feat_dbl.CopyFromVec(feat);
367  state_out->speaker_cmvn_stats(0, dim) += 1.0;
368  state_out->speaker_cmvn_stats.Row(0).Range(0, dim).AddVec(1.0, feat_dbl);
369  state_out->speaker_cmvn_stats.Row(1).Range(0, dim).AddVec2(1.0, feat_dbl);
370  }
371  }
372  // Store any frozen state (the effect of the user possibly
373  // having called Freeze().
374  state_out->frozen_state = frozen_state_;
375 }
virtual int32 Dim() const
virtual void GetFrame(int32 frame, VectorBase< BaseFloat > *feat)=0
Gets the feature vector for this frame.
Matrix< double > frozen_state_
OnlineFeatureInterface * src_
OnlineCmvnState orig_state_
void InitRingBufferIfNeeded ( )
inlineprivate

Initialize ring buffer for caching stats.

Definition at line 197 of file online-feature.cc.

References OnlineCmvn::cached_stats_ring_, OnlineCmvn::Dim(), OnlineCmvn::opts_, and OnlineCmvnOptions::ring_buffer_size.

Referenced by OnlineCmvn::CacheFrame(), and OnlineCmvn::GetMostRecentCachedFrame().

197  {
198  if (cached_stats_ring_.empty() && opts_.ring_buffer_size > 0) {
199  Matrix<double> temp(2, this->Dim() + 1);
201  std::pair<int32, Matrix<double> >(-1, temp));
202  }
203 }
virtual int32 Dim() const
std::vector< std::pair< int32, Matrix< double > > > cached_stats_ring_
OnlineCmvnOptions opts_
virtual bool IsLastFrame ( int32  frame) const
inlinevirtual

Returns true if this is the last frame.

Frame indices 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). This function may return false for some frame if we haven't yet decided to terminate decoding, but later true if we decide to terminate decoding. This function exists mainly to correctly handle end effects in feature extraction, and is not a mechanism to determine how many frames are in the decodable object (as it used to be, and for backward compatibility, still is, in the Decodable interface).

Implements OnlineFeatureInterface.

Definition at line 299 of file online-feature.h.

References OnlineFeatureInterface::IsLastFrame(), and OnlineCmvn::src_.

299  {
300  return src_->IsLastFrame(frame);
301  }
OnlineFeatureInterface * src_
virtual bool IsLastFrame(int32 frame) const =0
Returns true if this is the last frame.
virtual int32 NumFramesReady ( ) const
inlinevirtual

returns the feature dimension.

Returns the total number of frames, since the start of the utterance, that are now available. In an online-decoding context, this will likely increase with time as more data becomes available.

Implements OnlineFeatureInterface.

Definition at line 307 of file online-feature.h.

References OnlineFeatureInterface::NumFramesReady(), and OnlineCmvn::src_.

Referenced by OnlineCmvn::ComputeStatsForFrame().

307 { return src_->NumFramesReady(); }
OnlineFeatureInterface * src_
virtual int32 NumFramesReady() const =0
returns the feature dimension.
void SetState ( const OnlineCmvnState cmvn_state)

Definition at line 377 of file online-feature.cc.

References OnlineCmvn::cached_stats_modulo_, OnlineCmvnState::frozen_state, OnlineCmvn::frozen_state_, KALDI_ASSERT, and OnlineCmvn::orig_state_.

Referenced by OnlineCmvn::OnlineCmvn().

377  {
379  "You cannot call SetState() after processing data.");
380  orig_state_ = cmvn_state;
381  frozen_state_ = cmvn_state.frozen_state;
382 }
Matrix< double > frozen_state_
OnlineCmvnState orig_state_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
std::vector< Matrix< double > * > cached_stats_modulo_
void SmoothOnlineCmvnStats ( const MatrixBase< double > &  speaker_stats,
const MatrixBase< double > &  global_stats,
const OnlineCmvnOptions opts,
MatrixBase< double > *  stats 
)
staticprivate

Smooth the CMVN stats "stats" (which are stored in the normal format as a 2 x (dim+1) matrix), by possibly adding some stats from "global_stats" and/or "speaker_stats", controlled by the config.

The best way to understand the smoothing rule we use is just to look at the code.

Definition at line 272 of file online-feature.cc.

References MatrixBase< Real >::AddMat(), OnlineCmvnOptions::cmn_window, OnlineCmvnOptions::global_frames, KALDI_ASSERT, KALDI_ERR, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and OnlineCmvnOptions::speaker_frames.

Referenced by OnlineCmvn::Freeze(), and OnlineCmvn::GetFrame().

275  {
276  int32 dim = stats->NumCols() - 1;
277  double cur_count = (*stats)(0, dim);
278  // If count exceeded cmn_window it would be an error in how "window_stats"
279  // was accumulated.
280  KALDI_ASSERT(cur_count <= 1.001 * opts.cmn_window);
281  if (cur_count >= opts.cmn_window) return;
282  if (speaker_stats.NumRows() != 0) { // if we have speaker stats..
283  double count_from_speaker = opts.cmn_window - cur_count,
284  speaker_count = speaker_stats(0, dim);
285  if (count_from_speaker > opts.speaker_frames)
286  count_from_speaker = opts.speaker_frames;
287  if (count_from_speaker > speaker_count)
288  count_from_speaker = speaker_count;
289  if (count_from_speaker > 0.0)
290  stats->AddMat(count_from_speaker / speaker_count,
291  speaker_stats);
292  cur_count = (*stats)(0, dim);
293  }
294  if (cur_count >= opts.cmn_window) return;
295  if (global_stats.NumRows() != 0) {
296  double count_from_global = opts.cmn_window - cur_count,
297  global_count = global_stats(0, dim);
298  KALDI_ASSERT(global_count > 0.0);
299  if (count_from_global > opts.global_frames)
300  count_from_global = opts.global_frames;
301  if (count_from_global > 0.0)
302  stats->AddMat(count_from_global / global_count,
303  global_stats);
304  } else {
305  KALDI_ERR << "Global CMN stats are required";
306  }
307 }
#define KALDI_ERR
Definition: kaldi-error.h:127
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169

Member Data Documentation

std::vector<Matrix<double>*> cached_stats_modulo_
private
std::vector<std::pair<int32, Matrix<double> > > cached_stats_ring_
private
Matrix<double> frozen_state_
private
std::vector<int32> skip_dims_
private

Definition at line 390 of file online-feature.h.

Referenced by OnlineCmvn::GetFrame(), and OnlineCmvn::OnlineCmvn().


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