41 int32 half_dim = dim/2;
42 BaseFloat first_energy = (*waveform)(0) * (*waveform)(0),
43 last_energy = (*waveform)(1) * (*waveform)(1);
44 for (
int32 i = 1;
i < half_dim;
i++) {
46 (*waveform)(
i) = real*real + im*im;
48 (*waveform)(0) = first_energy;
49 (*waveform)(half_dim) = last_energy;
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);
77 for (
int32 j = -window;
j <= window;
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);
84 cur_scales.
Scale(1.0 / normalizer);
93 feat_dim = input_feats.
NumCols();
98 int32 max_offset = (scales.
Dim() - 1) / 2;
100 for (
int32 j = -max_offset;
j <= max_offset;
j++) {
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);
108 output.
AddVec(scale, input_feats.
Row(offset_frame));
122 for (
int32 j = -window;
j <= window;
j++) {
126 scales_.Scale(1.0 / normalizer);
134 feat_dim = input_feats.
NumCols();
141 output.
AddVec(1.0, input_feats.
Row(frame));
148 for (
int32 j = -max_offset;
j <= max_offset;
j++) {
150 if (offset_frame < 0) offset_frame = 0;
151 else if (offset_frame >= num_frames)
152 offset_frame = num_frames - 1;
155 output.
AddVec(scale, input_feats.
Row(offset_frame));
165 *(delta_opts.
order + 1));
167 for (
int32 r = 0; r < static_cast<int32>(input_features.
NumRows()); r++) {
169 delta.
Process(input_features, r, &row);
181 for (
int32 r = 0; r < static_cast<int32>(input_features.
NumRows()); r++) {
183 delta.
Process(input_features, r, &row);
191 mat_out->
Resize(n_bases, dimension);
192 for (
int32 i = 0;
i < n_bases;
i++) {
193 (*mat_out)(
i, 0) = 1.0 * scale;
195 for (
int32 j = 1;
j < dimension - 1;
j++) {
197 (*mat_out)(
i,
j) = 2.0 * scale * cos(angle * i_fl * j_fl);
200 (*mat_out)(
i, dimension -1)
201 = scale * cos(angle * i_fl * static_cast<BaseFloat>(dimension-1));
210 if (T == 0 || D == 0)
211 KALDI_ERR <<
"SpliceFrames: empty input";
213 int32 N = 1 + left_context + right_context;
214 output_features->
Resize(T, D*N);
215 for (
int32 t = 0; t < T; t++) {
218 int32 t2 = t +
j - left_context;
220 if (t2 >= T) t2 = T-1;
222 src(input_features, t2);
223 dst.CopyFromVec(src);
231 if (T == 0 || D == 0)
232 KALDI_ERR <<
"ReverseFrames: empty input";
233 output_features->
Resize(T, D);
234 for (
int32 t = 0; t < T; t++) {
245 KALDI_ASSERT(min_window > 0 && min_window <= cmn_window);
255 last_window_start = -1, last_window_end = -1,
259 for (
int32 t = 0; t < num_frames; t++) {
260 int32 window_start, window_end;
269 if (window_start < 0) {
270 window_end -= window_start;
275 window_end = std::max(t + 1, opts.
min_window);
277 if (window_end > num_frames) {
278 window_start -= (window_end - num_frames);
279 window_end = num_frames;
280 if (window_start < 0) window_start = 0;
282 if (last_window_start == -1) {
284 window_start, window_end - window_start,
286 cur_sum.AddRowSumMat(1.0, input_part , 0.0);
290 if (window_start > last_window_start) {
293 cur_sum.AddVec(-1.0, frame_to_remove);
295 cur_sumsq.
AddVec2(-1.0, frame_to_remove);
297 if (window_end > last_window_end) {
300 cur_sum.AddVec(1.0, frame_to_add);
302 cur_sumsq.
AddVec2(1.0, frame_to_add);
305 int32 window_frames = window_end - window_start;
306 last_window_start = window_start;
307 last_window_end = window_end;
311 output_frame(*output, t);
313 output_frame.
AddVec(-1.0 / window_frames, cur_sum);
316 if (window_frames == 1) {
317 output_frame.
Set(0.0);
320 variance.
Scale(1.0 / window_frames);
321 variance.
AddVec2(-1.0 / (window_frames * window_frames), cur_sum);
326 if (num_floored > 0 && num_frames > 1) {
328 KALDI_WARN <<
"Suppressing the remaining variance flooring " 329 <<
"warnings. Run program with --max-warnings=-1 to " 330 <<
"see all warnings.";
336 KALDI_WARN <<
"Flooring when normalizing variance, floored " 337 << num_floored <<
" elements; num-frames was " This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Base class which provides matrix operations not involving resizing or allocation. ...
void AddDiagMat2(Real alpha, const MatrixBase< Real > &M, MatrixTransposeType trans=kNoTrans, Real beta=1.0)
Add the diagonal of a matrix times itself: *this = diag(M M^T) + beta * *this (if trans == kNoTrans)...
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
void ReverseFrames(const MatrixBase< BaseFloat > &input_features, Matrix< BaseFloat > *output_features)
Vector< BaseFloat > scales_
bool SameDim(const MatrixBase< Real > &M, const MatrixBase< Real > &N)
void AddVec2(const Real alpha, const VectorBase< Real > &v)
Add vector : *this = *this + alpha * rv^2 [element-wise squaring].
void ApplyFloor(Real floor_val, MatrixIndexT *floored_count=nullptr)
Applies floor to all elements.
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
ShiftedDeltaFeaturesOptions opts_
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
void MulElements(const VectorBase< Real > &v)
Multiply element-by-element by another vector.
void SlidingWindowCmnInternal(const SlidingWindowCmnOptions &opts, const MatrixBase< double > &input, MatrixBase< double > *output)
DeltaFeaturesOptions opts_
void Process(const MatrixBase< BaseFloat > &input_feats, int32 frame, VectorBase< BaseFloat > *output_frame) const
void ComputeShiftedDeltas(const ShiftedDeltaFeaturesOptions &delta_opts, const MatrixBase< BaseFloat > &input_features, Matrix< BaseFloat > *output_features)
MatrixIndexT Dim() const
Returns the dimension of the vector.
void InitIdftBases(int32 n_bases, int32 dimension, Matrix< BaseFloat > *mat_out)
void Scale(Real alpha)
Multiplies all elements by this constant.
DeltaFeatures(const DeltaFeaturesOptions &opts)
void ComputePowerSpectrum(VectorBase< BaseFloat > *waveform)
A class representing a vector.
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void ComputeDeltas(const DeltaFeaturesOptions &delta_opts, const MatrixBase< BaseFloat > &input_features, Matrix< BaseFloat > *output_features)
void Set(Real f)
Set all members of a vector to a specified value.
void SpliceFrames(const MatrixBase< BaseFloat > &input_features, int32 left_context, int32 right_context, Matrix< BaseFloat > *output_features)
void ApplyPow(Real power)
Take all elements of vector to a power.
std::vector< Vector< BaseFloat > > scales_
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).
Provides a vector abstraction class.
void SetZero()
Set vector to all zeros.
void Process(const MatrixBase< BaseFloat > &input_feats, int32 frame, SubVector< BaseFloat > *output_frame) const
void AddVec(const Real alpha, const VectorBase< OtherReal > &v)
Add vector : *this = *this + alpha * rv (with casting between floats and doubles) ...
Sub-matrix representation.
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
void SlidingWindowCmn(const SlidingWindowCmnOptions &opts, const MatrixBase< BaseFloat > &input, MatrixBase< BaseFloat > *output)
Applies sliding-window cepstral mean and/or variance normalization.
ShiftedDeltaFeatures(const ShiftedDeltaFeaturesOptions &opts)