ShiftedDeltaFeatures Class Reference

#include <feature-functions.h>

Collaboration diagram for ShiftedDeltaFeatures:

Public Member Functions

 ShiftedDeltaFeatures (const ShiftedDeltaFeaturesOptions &opts)
 
void Process (const MatrixBase< BaseFloat > &input_feats, int32 frame, SubVector< BaseFloat > *output_frame) const
 

Private Attributes

ShiftedDeltaFeaturesOptions opts_
 
Vector< BaseFloatscales_
 

Detailed Description

Definition at line 100 of file feature-functions.h.

Constructor & Destructor Documentation

◆ ShiftedDeltaFeatures()

Definition at line 113 of file feature-functions.cc.

References rnnlm::j, KALDI_ASSERT, ShiftedDeltaFeatures::scales_, and ShiftedDeltaFeaturesOptions::window.

114  : opts_(opts) {
115  KALDI_ASSERT(opts.window > 0 && opts.window < 1000);
116 
117  // Default window is 1.
118  int32 window = opts.window;
119  KALDI_ASSERT(window != 0);
120  scales_.Resize(1 + 2*window); // also zeros it.
121  BaseFloat normalizer = 0.0;
122  for (int32 j = -window; j <= window; j++) {
123  normalizer += j*j;
124  scales_(j + window) += static_cast<BaseFloat>(j);
125  }
126  scales_.Scale(1.0 / normalizer);
127 }
kaldi::int32 int32
ShiftedDeltaFeaturesOptions opts_
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

Member Function Documentation

◆ Process()

void Process ( const MatrixBase< BaseFloat > &  input_feats,
int32  frame,
SubVector< BaseFloat > *  output_frame 
) const

Definition at line 129 of file feature-functions.cc.

References VectorBase< Real >::AddVec(), ShiftedDeltaFeaturesOptions::block_shift, VectorBase< Real >::Dim(), rnnlm::i, rnnlm::j, KALDI_ASSERT, ShiftedDeltaFeaturesOptions::num_blocks, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), ShiftedDeltaFeatures::opts_, MatrixBase< Real >::Row(), ShiftedDeltaFeatures::scales_, and VectorBase< Real >::SetZero().

Referenced by kaldi::ComputeShiftedDeltas().

131  {
132  KALDI_ASSERT(frame < input_feats.NumRows());
133  int32 num_frames = input_feats.NumRows(),
134  feat_dim = input_feats.NumCols();
135  KALDI_ASSERT(static_cast<int32>(output_frame->Dim())
136  == feat_dim * (opts_.num_blocks + 1));
137  output_frame->SetZero();
138 
139  // The original features
140  SubVector<BaseFloat> output(*output_frame, 0, feat_dim);
141  output.AddVec(1.0, input_feats.Row(frame));
142 
143  // Concatenate the delta-blocks. Each block is block_shift
144  // (usually 3) frames apart.
145  for (int32 i = 0; i < opts_.num_blocks; i++) {
146  int32 max_offset = (scales_.Dim() - 1) / 2;
147  SubVector<BaseFloat> output(*output_frame, (i + 1) * feat_dim, feat_dim);
148  for (int32 j = -max_offset; j <= max_offset; j++) {
149  int32 offset_frame = frame + j + i * opts_.block_shift;
150  if (offset_frame < 0) offset_frame = 0;
151  else if (offset_frame >= num_frames)
152  offset_frame = num_frames - 1;
153  BaseFloat scale = scales_(j + max_offset);
154  if (scale != 0.0)
155  output.AddVec(scale, input_feats.Row(offset_frame));
156  }
157  }
158 }
kaldi::int32 int32
ShiftedDeltaFeaturesOptions opts_
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

Member Data Documentation

◆ opts_

Definition at line 114 of file feature-functions.h.

Referenced by ShiftedDeltaFeatures::Process().

◆ scales_


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