36 double *__restrict__ mean_ptr = stats->
RowData(0),
37 *__restrict__ var_ptr = stats->
RowData(1),
38 *__restrict__ count_ptr = mean_ptr + dim;
43 for (; mean_ptr < count_ptr; mean_ptr++, var_ptr++, feats_ptr++) {
44 *mean_ptr += *feats_ptr * weight;
45 *var_ptr += *feats_ptr * *feats_ptr * weight;
53 if (weights != NULL) {
56 for (
int32 i = 0;
i < num_frames;
i++) {
58 BaseFloat weight = (weights == NULL ? 1.0 : (*weights)(
i));
74 if (stats.
NumRows() == 1 && var_norm)
75 KALDI_ERR <<
"You requested variance normalization but no variance stats " 78 double count = stats(0, dim);
82 KALDI_ERR <<
"Insufficient stats for cepstral mean and variance normalization: " 83 <<
"count = " <<
count;
88 offset.
AddVec(-1.0 / count, mean_stats);
96 double mean, offset, scale;
98 double var = (stats(1,
d)/
count) - mean*mean,
101 KALDI_WARN <<
"Flooring cepstral variance from " << var <<
" to " 105 scale = 1.0 / sqrt(var);
106 if (scale != scale || 1/scale == 0.0)
107 KALDI_ERR <<
"NaN or infinity in cepstral mean/variance computation";
108 offset = -(mean*scale);
127 if (stats.
NumRows() == 1 && var_norm)
128 KALDI_ERR <<
"You requested variance normalization but no variance stats " 131 double count = stats(0, dim);
135 KALDI_ERR <<
"Insufficient stats for cepstral mean and variance normalization: " 136 <<
"count = " <<
count;
141 double mean, offset, scale;
142 mean = stats(0,
d) /
count;
147 double var = (stats(1,
d)/
count) - mean*mean,
150 KALDI_WARN <<
"Flooring cepstral variance from " << var <<
" to " 172 double count = (*stats)(0, dim);
173 for (
size_t i = 0;
i < dims.size();
i++) {
176 (*stats)(0,
d) = 0.0;
177 (*stats)(1,
d) = count;
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. ...
Real * RowData(MatrixIndexT i)
Returns pointer to data for one row (non-const)
void ApplyCmvnReverse(const MatrixBase< double > &stats, bool var_norm, MatrixBase< BaseFloat > *feats)
This is as ApplyCmvn, but does so in the reverse sense, i.e.
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
void AddVecToRows(const Real alpha, const VectorBase< OtherReal > &v)
[each row of *this] += alpha * v
void InitCmvnStats(int32 dim, Matrix< double > *stats)
This function initializes the matrix to dimension 2 by (dim+1); 1st "dim" elements of 1st row are mea...
Real * Data()
Returns a pointer to the start of the vector's data.
MatrixIndexT Dim() const
Returns the dimension of the vector.
void AccCmvnStats(const VectorBase< BaseFloat > &feats, BaseFloat weight, MatrixBase< double > *stats)
Accumulation from a single frame (weighted).
void MulColsVec(const VectorBase< Real > &scale)
Equivalent to (*this) = (*this) * diag(scale).
A class representing a vector.
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty 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).
Provides a vector abstraction class.
void AddVec(const Real alpha, const VectorBase< OtherReal > &v)
Add vector : *this = *this + alpha * rv (with casting between floats and doubles) ...
void ApplyCmvn(const MatrixBase< double > &stats, bool var_norm, MatrixBase< BaseFloat > *feats)
Apply cepstral mean and variance normalization to a matrix of features.
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
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...