DeltaFeatures Class Reference

#include <feature-functions.h>

Collaboration diagram for DeltaFeatures:

Public Member Functions

 DeltaFeatures (const DeltaFeaturesOptions &opts)
 
void Process (const MatrixBase< BaseFloat > &input_feats, int32 frame, VectorBase< BaseFloat > *output_frame) const
 

Private Attributes

DeltaFeaturesOptions opts_
 
std::vector< Vector< BaseFloat > > scales_
 

Detailed Description

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

Constructor & Destructor Documentation

◆ DeltaFeatures()

DeltaFeatures ( const DeltaFeaturesOptions opts)
explicit

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

References VectorBase< Real >::Dim(), rnnlm::i, rnnlm::j, KALDI_ASSERT, DeltaFeaturesOptions::order, VectorBase< Real >::Scale(), DeltaFeatures::scales_, and DeltaFeaturesOptions::window.

54  : opts_(opts) {
55  KALDI_ASSERT(opts.order >= 0 && opts.order < 1000); // just make sure we don't get binary junk.
56  // opts will normally be 2 or 3.
57  KALDI_ASSERT(opts.window > 0 && opts.window < 1000); // again, basic sanity check.
58  // normally the window size will be two.
59 
60  scales_.resize(opts.order+1);
61  scales_[0].Resize(1);
62  scales_[0](0) = 1.0; // trivial window for 0th order delta [i.e. baseline feats]
63 
64  for (int32 i = 1; i <= opts.order; i++) {
65  Vector<BaseFloat> &prev_scales = scales_[i-1],
66  &cur_scales = scales_[i];
67  int32 window = opts.window; // this code is designed to still
68  // work if instead we later make it an array and do opts.window[i-1],
69  // or something like that. "window" is a parameter specifying delta-window
70  // width which is actually 2*window + 1.
71  KALDI_ASSERT(window != 0);
72  int32 prev_offset = (static_cast<int32>(prev_scales.Dim()-1))/2,
73  cur_offset = prev_offset + window;
74  cur_scales.Resize(prev_scales.Dim() + 2*window); // also zeros it.
75 
76  BaseFloat normalizer = 0.0;
77  for (int32 j = -window; j <= window; j++) {
78  normalizer += j*j;
79  for (int32 k = -prev_offset; k <= prev_offset; k++) {
80  cur_scales(j+k+cur_offset) +=
81  static_cast<BaseFloat>(j) * prev_scales(k+prev_offset);
82  }
83  }
84  cur_scales.Scale(1.0 / normalizer);
85  }
86 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
DeltaFeaturesOptions opts_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
std::vector< Vector< BaseFloat > > scales_

Member Function Documentation

◆ Process()

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

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

References VectorBase< Real >::AddVec(), VectorBase< Real >::Dim(), rnnlm::i, rnnlm::j, KALDI_ASSERT, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), DeltaFeatures::opts_, DeltaFeaturesOptions::order, MatrixBase< Real >::Row(), DeltaFeatures::scales_, and VectorBase< Real >::SetZero().

Referenced by kaldi::ComputeDeltas(), and OnlineDeltaInput::DeltaComputation().

90  {
91  KALDI_ASSERT(frame < input_feats.NumRows());
92  int32 num_frames = input_feats.NumRows(),
93  feat_dim = input_feats.NumCols();
94  KALDI_ASSERT(static_cast<int32>(output_frame->Dim()) == feat_dim * (opts_.order+1));
95  output_frame->SetZero();
96  for (int32 i = 0; i <= opts_.order; i++) {
97  const Vector<BaseFloat> &scales = scales_[i];
98  int32 max_offset = (scales.Dim() - 1) / 2;
99  SubVector<BaseFloat> output(*output_frame, i*feat_dim, feat_dim);
100  for (int32 j = -max_offset; j <= max_offset; j++) {
101  // if asked to read
102  int32 offset_frame = frame + j;
103  if (offset_frame < 0) offset_frame = 0;
104  else if (offset_frame >= num_frames)
105  offset_frame = num_frames - 1;
106  BaseFloat scale = scales(j + max_offset);
107  if (scale != 0.0)
108  output.AddVec(scale, input_feats.Row(offset_frame));
109  }
110  }
111 }
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
DeltaFeaturesOptions opts_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
std::vector< Vector< BaseFloat > > scales_

Member Data Documentation

◆ opts_

DeltaFeaturesOptions opts_
private

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

Referenced by DeltaFeatures::Process().

◆ scales_

std::vector<Vector<BaseFloat> > scales_
private

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

Referenced by DeltaFeatures::DeltaFeatures(), and DeltaFeatures::Process().


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