34 GetStats(&total_covar, &between_covar, &total_mean, &count);
57 wc_covar.
AddSp(-1.0, between_covar);
67 KALDI_LOG <<
"Cholesky failed (possibly not +ve definite), so adding " << smooth
68 <<
" to diagonal and trying again.\n";
70 wc_covar(
i,
i) += smooth;
74 wc_covar_sqrt_mat.
Invert();
81 tmp_mat.
Svd(&svd_d, &svd_u, &svd_vt);
84 KALDI_LOG <<
"LDA singular values are " << svd_d;
86 KALDI_LOG <<
"Sum of all singular values is " << svd_d.Sum();
87 KALDI_LOG <<
"Sum of selected singular values is " <<
94 M->
Resize(target_dim, dim);
98 for (
int32 i = 0;
i < svd_d.Dim();
i++) {
101 scale = sqrt(new_var / old_var);
102 if (i < M->NumRows())
103 M->
Row(
i).Scale(scale);
109 min_dim = std::min(rows, cols);
117 KALDI_LOG <<
"Applied ceiling to " << n <<
" out of " << s.
Dim()
118 <<
" singular values of transform using ceiling " 132 const std::vector<int32> &indexes,
138 int32 full_dim =
Dim(), proj_dim = indexes.size();
140 for (
int32 i = 0;
i < proj_dim;
i++)
141 transform(
i, indexes[
i]) = 1.0;
145 total_covar_proj.AddMat2Sp(1.0, transform,
kNoTrans, total_covar, 0.0);
151 opts_tmp.
dim = proj_dim;
154 if (M_proj.
NumCols() == proj_dim + 1) {
157 transform(proj_dim, full_dim) = 1.0;
167 const std::vector<std::vector<int32> > &indexes,
170 int32 input_dim =
Dim(), output_dim = 0, num_transforms = indexes.size();
171 for (
int32 i = 0;
i < num_transforms;
i++) {
173 std::vector<int32> this_indexes(indexes[
i]);
174 std::sort(this_indexes.begin(), this_indexes.end());
178 output_dim += this_indexes.size();
182 M->
Resize(output_dim, input_dim_ext);
187 GetStats(&total_covar, &between_covar, &total_mean, &count);
189 int32 cur_output_index = 0;
190 for (
int32 i = 0;
i < num_transforms;
i++) {
192 EstimateTransformPart(opts, indexes[
i], total_covar, between_covar,
194 int32 this_output_dim = indexes[
i].size();
195 M->
Range(cur_output_index, this_output_dim, 0, M->
NumCols()).
197 cur_output_index += this_output_dim;
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).
int32 Dim() const
Returns the dimensionality of the feature vectors.
void ApplyCeiling(Real ceil_val, MatrixIndexT *ceiled_count=nullptr)
Applies ceiling to all elements.
void Resize(MatrixIndexT nRows, MatrixResizeType resize_type=kSetZero)
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
MatrixIndexT NumRows() const
void Cholesky(const SpMatrix< Real > &orig)
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
void AddSp(const Real alpha, const SpMatrix< Real > &Ma)
static void AddMeanOffset(const VectorBase< double > &total_mean, Matrix< BaseFloat > *projection)
This function modifies the LDA matrix so that it also subtracts the mean feature value.
void AddMatMat(const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta)
Real Max() const
Returns the maximum value of any element, or -infinity for the empty vector.
Packed symetric matrix class.
MatrixIndexT Dim() const
Returns the dimension of the vector.
void AddMatVec(const Real alpha, const MatrixBase< Real > &M, const MatrixTransposeType trans, const VectorBase< Real > &v, const Real beta)
Add matrix times vector : this <– beta*this + alpha*M*v.
void GetStats(SpMatrix< double > *total_covar, SpMatrix< double > *between_covar, Vector< double > *total_mean, double *sum) const
Extract a more processed form of the stats.
void MulRowsVec(const VectorBase< Real > &scale)
Equivalent to (*this) = diag(scale) * (*this).
void CopyFromTp(const TpMatrix< Real > &other)
CopyFromTp copies another triangular matrix into this one.
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void AddMat2Sp(const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transM, const SpMatrix< Real > &A, const Real beta=0.0)
Extension of rank-N update: this <– beta*this + alpha * M * A * M^T.
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 Svd(VectorBase< Real > *s, MatrixBase< Real > *U, MatrixBase< Real > *Vt) const
Compute SVD (*this) = U diag(s) Vt.
void Invert(Real *log_det=NULL, Real *det_sign=NULL, bool inverse_needed=true)
matrix inverse.
bool IsSortedAndUniq(const std::vector< T > &vec)
Returns true if the vector is sorted and contains each element only once.
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
void SortSvd(VectorBase< Real > *s, MatrixBase< Real > *U, MatrixBase< Real > *Vt, bool sort_on_absolute_value)
Function to ensure that SVD is sorted.