35 size_t max_iter = 10000;
40 while (iter < max_iter) {
42 if (tmp.
Cond() < 100)
break;
45 if (iter >= max_iter) {
46 KALDI_ERR <<
"Internal error: found no random covariance matrix.";
68 size_t frames_per_gaussian,
79 untransformed_means.
Scale(10);
89 size_t train_counter = 0;
96 for (
size_t j = 0;
j < n_gaussians;
j++) {
97 if (covariance_type ==
diag) {
100 for (
size_t d = 0;
d < dim;
d++) {
104 if (covariance_type ==
full) {
113 for (
size_t i = 0;
i < frames_per_gaussian;
i++) {
127 for (
size_t d = 0;
d < dim;
d++) {
130 train_feats[train_counter]->AddMatVec(1.0, Sj,
kNoTrans,
142 size_t dim = 5 +
Rand() % 3;
145 size_t n_gaussians = 8;
148 size_t frames_per_gaussian = 100;
155 if (trans_mat.
Cond() < 100)
break;
158 std::cout <<
"Condition of original Trans_Mat: " << trans_mat.
Cond() <<
'\n';
161 std::vector<Vector<BaseFloat>*>
162 train_feats(n_gaussians * frames_per_gaussian);
163 std::vector<Vector<BaseFloat>*>
164 adapt_feats(n_gaussians * frames_per_gaussian);
177 for (
size_t d= 0;
d < dim;
d++) {
199 size_t iteration = 0;
200 size_t maxiterations = 10;
201 int32 maxcomponents = n_gaussians;
203 while (iteration < maxiterations) {
204 est_am->
Init(*am, flags);
207 for (
size_t j = 0;
j < train_feats.size();
j++) {
212 std::cout <<
"Loglikelihood before iteration " << iteration <<
" : " 213 << std::scientific << loglike <<
" number of components: " 216 if ((iteration % 3 == 1) &&
235 for (
int32 i = 0; i < static_cast<int32>(num_pdfs); i++) {
236 occs(i) = 1.0/
static_cast<BaseFloat>(num_pdfs);
238 std::vector<int32> silphones;
239 regtree.
BuildTree(occs, silphones, *am, max_bclass);
241 std::vector<Vector<BaseFloat>*> logdet(adapt_feats.size());
242 for (
size_t j = 0;
j < adapt_feats.size();
j++) {
244 logdet[
j]->operator()(0) = 0.0;
246 while (iteration < maxiterations) {
251 for (
size_t j = 0;
j < adapt_feats.size();
j++) {
253 loglike += logdet[
j]->operator()(0);
255 std::cout <<
"FMLLR: Loglikelihood before iteration " << iteration <<
" : " 256 << std::scientific << loglike <<
'\n';
258 fmllr_accs->
Update(regtree, xform_opts, new_fmllr, NULL, NULL);
259 std::cout <<
"Got " << new_fmllr->
NumBaseClasses() <<
" baseclasses\n";
261 std::cout <<
"Writing the transform to disk.\n";
262 new_fmllr->
Write(
Output(
"tmpf", binary).Stream(), binary);
265 Input ki(
"tmpf", &binary_in);
266 std::cout <<
"Reading the transform from disk.\n";
271 std::vector<Vector<BaseFloat> > trans_feats(1);
276 for (
size_t j = 0;
j < adapt_feats.size();
j++) {
278 logdet[
j]->operator()(0) += trans_logdet(0);
309 for (
int i = 0;
i <= 8;
i+=2) {
310 std::cout <<
"--------------------------------------" <<
'\n';
311 std::cout <<
"Test number " <<
i <<
'\n';
312 std::cout <<
"--\nfeatures = full\n";
314 std::cout <<
"--\nfeatures = diag\n";
316 std::cout <<
"--------------------------------------" <<
'\n';
318 std::cout <<
"Test OK.\n";
cova_type
Generate features for a certain covariance type covariance_type == 0: full covariance covariance_type...
void MleAmDiagGmmUpdate(const MleDiagGmmOptions &config, const AccumAmDiagGmm &am_diag_gmm_acc, GmmFlagsType flags, AmDiagGmm *am_gmm, BaseFloat *obj_change_out, BaseFloat *count_out)
for computing the maximum-likelihood estimates of the parameters of an acoustic model that uses diago...
void AddMat2(const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transM, const Real beta)
rank-N update: if (transM == kNoTrans) (*this) = beta*(*this) + alpha * M * M^T, or (if transM == kTr...
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void AddPdf(const DiagGmm &gmm)
Adds a GMM to the model, and increments the total number of PDFs.
Packed symetric matrix class.
void DeletePointers(std::vector< A *> *v)
Deletes any non-NULL pointers in the vector v, and sets the corresponding entries of v to NULL...
void SetInvVarsAndMeans(const MatrixBase< Real > &invvars, const MatrixBase< Real > &means)
Use SetInvVarsAndMeans if updating both means and (inverse) variances.
float RandUniform(struct RandomState *state=NULL)
Returns a random number strictly between 0 and 1.
void Read(std::istream &in_stream, bool binary)
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Real Cond() const
Returns condition number by computing Svd.
BaseFloat AccumulateForGmm(const AmDiagGmm &model, const VectorBase< BaseFloat > &data, int32 gmm_index, BaseFloat weight)
Accumulate stats for a single GMM in the model; returns log likelihood.
void Resize(int32 nMix, int32 dim)
Resizes arrays to this dim. Does not initialize data.
int32 ComputeGconsts()
Sets the gconsts.
void GetLogDets(VectorBase< BaseFloat > *out) const
float RandGauss(struct RandomState *state=NULL)
static void generate_features(cova_type covariance_type, size_t n_gaussians, size_t dim, Matrix< BaseFloat > &trans_mat, size_t frames_per_gaussian, std::vector< Vector< BaseFloat > *> &train_feats, std::vector< Vector< BaseFloat > *> &adapt_feats)
uint16 GmmFlagsType
Bitwise OR of the above flags.
static void RandFullCova(Matrix< BaseFloat > *matrix)
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
int32 NumGaussInPdf(int32 pdf_index) const
void CopyFromSp(const SpMatrix< OtherReal > &M)
Copy given spmatrix. (no resize is done).
An FMLLR (feature-space MLLR) transformation, also called CMLLR (constrained MLLR) is an affine trans...
int32 NumRegClasses() const
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
int32 NumBaseclasses() const
Accessors (const)
Configuration variables for FMLLR transforms.
void Scale(Real alpha)
Multiply each element with a scalar value.
void BuildTree(const Vector< BaseFloat > &state_occs, const std::vector< int32 > &sil_indices, const AmDiagGmm &am, int32 max_clusters)
Top-down clustering of the Gaussians in a model based on their means.
A regression tree is a clustering of Gaussian densities in an acoustic model, such that the group of ...
void SetRandn()
Sets to random values of a normal distribution.
void TransformFeature(const VectorBase< BaseFloat > &in, std::vector< Vector< BaseFloat > > *out) const
Get the transformed features for each of the transforms.
void AddMatMat(const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta)
void Validate()
Checks whether the various parameters are consistent.
BaseFloat min_count
Minimum occupancy for computing a transform.
void SetZero()
Sets matrix to zero.
Configuration variables like variance floor, minimum occupancy, etc.
bool use_regtree
If 'true', find transforms to generate using regression tree.
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.
int Rand(struct RandomState *state)
int32 NumBaseClasses() const
void InvertElements()
Inverts all the elements of the matrix.
void CopyColFromMat(const MatrixBase< OtherReal > &M, MatrixIndexT col)
Extracts a column of the matrix M.
A class representing a vector.
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Class for computing the accumulators needed for the maximum-likelihood estimate of FMLLR transforms f...
Definition for Gaussian Mixture Model with diagonal covariances.
void SplitPdf(int32 idx, int32 target_components, float perturb_factor)
void SetWeights(const VectorBase< Real > &w)
Mutators for both float or double.
void UnitTestRegtreeFmllrDiagGmm(cova_type feature_type, size_t max_bclass)
BaseFloat AccumulateForGmm(const RegressionTree ®tree, const AmDiagGmm &am, const VectorBase< BaseFloat > &data, size_t pdf_index, BaseFloat weight)
Accumulate stats for a single GMM in the model; returns log likelihood.
void Invert(Real *log_det=NULL, Real *det_sign=NULL, bool inverse_needed=true)
matrix inverse.
void Update(const RegressionTree ®tree, const RegtreeFmllrOptions &opts, RegtreeFmllrDiagGmm *out_fmllr, BaseFloat *auxf_impr, BaseFloat *tot_t) const
void Write(std::ostream &out_stream, bool binary) const
void Init(size_t num_bclass, size_t dim)
void Init(const AmDiagGmm &model, GmmFlagsType flags)
Initializes accumulators for each GMM based on the number of components and dimension.