51 int32 num_frames_return = std::min((
Rand() % 5), num_frames_left);
52 if (num_frames_return == 0) {
75 KALDI_ASSERT(std::abs(A(
i,
j)-B(
i,
j)) < tol*std::max(1.0, (
double) (std::abs(A(
i,
j))+std::abs(B(
i,
j)))));
88 garbage.
Resize(batch_size, dim);
122 for (
int32 frame = 0; frame < num_frames; frame++) {
135 bool have_offset = (
Rand() % 2 == 0);
136 int32 lda_input_dim = (dim * (left_context + 1 + right_context)),
137 lda_output_dim = 1 +
Rand() % 5;
141 (have_offset ? 1 : 0));
147 OnlineLdaInput lda_input(&matrix_input, transform, left_context, right_context);
152 SpliceFrames(input_feats, left_context, right_context, &temp_feats);
162 output_feats2.AddVecToRows(1.0, offset);
178 input_feats.SetRandn();
202 int32 min_window = 1 +
Rand() % (cmn_window - 1);
203 if (
Rand() % 3 == 0) min_window = cmn_window;
215 if (
i == 0 && min_window == 0) this_row.
SetZero();
216 else if (
i < min_window) {
217 int32 window_nframes = std::min(min_window, input_feats.
NumRows());
221 this_sum.AddRowSumMat(1.0, this_block, 0.0);
222 this_row.
AddVec(-1.0 / window_nframes, this_sum);
224 int32 window_nframes = std::min(
i, cmn_window);
229 this_row.
AddVec(-1.0 / window_nframes, this_sum);
234 if (!output_feats1.
Row(
i).ApproxEqual(output_feats2.
Row(
i))) {
235 KALDI_ERR <<
"Rows differ " <<
i <<
", " << input_feats.
Row(
i) << output_feats1.
Row(
i)
236 << output_feats2.
Row(
i);
250 using namespace kaldi;
251 for (
int i = 0;
i < 40;
i++) {
259 std::cout <<
"Test OK.\n";
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void AddRowSumMat(Real alpha, const MatrixBase< Real > &M, Real beta=1.0)
Does *this = alpha * (sum of rows of M) + beta * *this.
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
void TestOnlineDeltaInput()
void GetOutput(OnlineFeatureInterface *a, Matrix< BaseFloat > *output)
bool ApproxEqual(const MatrixBase< Real > &other, float tol=0.01) const
Returns true if ((*this)-other).FrobeniusNorm() <= tol * (*this).FrobeniusNorm(). ...
void TestOnlineFeatureMatrix()
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
void SetRandn()
Sets to random values of a normal distribution.
void AddMatMat(const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta)
void TestOnlineCmnInput()
int Rand(struct RandomState *state)
void CopyColFromMat(const MatrixBase< OtherReal > &M, MatrixIndexT col)
Extracts a column of the matrix M.
A class representing a vector.
SubVector< BaseFloat > GetFrame(int32 frame)
#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 SpliceFrames(const MatrixBase< BaseFloat > &input_features, int32 left_context, int32 right_context, Matrix< BaseFloat > *output_features)
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
SubMatrix< Real > Range(const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Return a sub-part of matrix.
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).
void TestOnlineLdaInput()
void TestOnlineMatrixInput()
void SetZero()
Set vector to all zeros.
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...
bool IsValidFrame(int32 frame)