29 std::ostringstream ostr;
30 bool binary = (
Rand() % 2 == 0);
31 extractor.
Write(ostr, binary);
32 std::istringstream istr(ostr.str());
34 extractor2.
Read(istr, binary);
35 std::ostringstream ostr2;
36 extractor2.Write(ostr2, binary);
40 std::ostringstream ostr;
41 bool binary = (
Rand() % 2 == 0);
42 stats.
Write(ostr, binary);
43 std::istringstream istr(ostr.str());
45 stats2.
Read(istr, binary);
46 std::ostringstream ostr2;
47 stats2.Write(ostr2, binary);
58 std::ostringstream ostr;
60 stats.
Write(ostr, binary);
63 std::istringstream istr(ostr.str());
64 stats2.
Read(istr, binary);
67 std::istringstream istr(ostr.str());
68 stats2.
Read(istr, binary,
true);
73 std::ostringstream ostr2;
74 stats2.
Write(ostr2,
false);
76 std::ostringstream ostr3;
77 stats3.
Write(ostr3,
false);
97 double tot_log_like = 0.0;
98 for (
int32 t = 0; t < num_frames; t++) {
102 for (
int32 i = 0;
i < posterior.Dim();
i++)
103 post[t].push_back(std::make_pair(
i, posterior(
i)));
115 for (
int32 t = 0; t < num_frames; t++) {
116 online_stats.
AccStats(extractor, feats.
Row(t), post[t]);
123 int32 num_cg_iters = -1;
124 online_stats.
GetIvector(num_cg_iters, &ivector2);
131 double objf_change2 = online_stats.
ObjfChange(ivector2) *
136 double objf_change1 = extractor.
GetAuxf(utt_stats, ivector1) -
137 extractor.
GetAuxf(utt_stats, ivector_baseline);
138 KALDI_LOG <<
"objf_change1 = " << objf_change1
139 <<
", objf_change2 = " << objf_change2;
156 <<
", ivector dim is " << ivector_opts.
ivector_dim;
167 std::vector<Matrix<BaseFloat> > all_feats(num_utts);
168 for (
int32 utt = 0; utt < num_utts; utt++) {
170 if (
Rand() % 2 == 0) num_frames *= 10;
171 if (
Rand() % 2 == 0) num_frames /= 1.0;
173 fgmm_normal.
Rand(&feats);
174 feats.
Swap(&all_feats[utt]);
178 double last_auxf_impr = 0.0, last_auxf = 0.0;
179 for (
int32 iter = 0; iter < num_iters; iter++) {
182 for (
int32 utt = 0; utt < num_utts; utt++) {
192 auxf_impr = stats.
Update(estimation_opts, &extractor);
194 KALDI_LOG <<
"Iter " << iter <<
", auxf per frame was " << auxf
195 <<
", improvement in this update " 196 <<
"phase was " << auxf_impr;
198 double auxf_change = auxf - last_auxf;
199 KALDI_LOG <<
"Predicted auxf change from last update phase was " 200 << last_auxf_impr <<
" versus observed change " 202 double wiggle_room = (ivector_opts.
use_weights ? 5.0e-05 : 1.0e-08);
206 KALDI_ASSERT(auxf_change >= last_auxf_impr - wiggle_room);
208 last_auxf_impr = auxf_impr;
211 std::cout <<
"********************************************************************************************\n";
217 using namespace kaldi;
219 for (
int i = 0;
i < 10;
i++)
221 std::cout <<
"Test OK.\n";
void TestIvectorExtractorIO(const IvectorExtractor &extractor)
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
double ObjfChange(const VectorBase< double > &ivector) const
ObjfChange returns the change in objective function *per frame* from using the default value [ prior_...
BaseFloat ComponentPosteriors(const VectorBase< BaseFloat > &data, VectorBase< BaseFloat > *posterior) const
Computes the posterior probabilities of all Gaussian components given a data point.
Definition for Gaussian Mixture Model with full covariances in normal mode: where the parameters are ...
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Base class which provides matrix operations not involving resizing or allocation. ...
void AccStats(const IvectorExtractor &extractor, const VectorBase< BaseFloat > &feature, const std::vector< std::pair< int32, BaseFloat > > &gauss_post)
Definition for Gaussian Mixture Model with full covariances.
This class helps us to efficiently estimate iVectors in situations where the data is coming in frame ...
void Swap(Matrix< Real > *other)
Swaps the contents of *this and *other. Shallow swap.
void SetVerboseLevel(int32 i)
This should be rarely used, except by programs using Kaldi as library; command-line programs set the ...
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
void GetIvector(int32 num_cg_iters, VectorBase< double > *ivector) const
This function gets the current estimate of the iVector.
void UnitTestIvectorExtractor()
void Rand(MatrixBase< BaseFloat > *feats)
Generates random features from the model.
int32 NumGauss() const
Returns the number of mixture components in the GMM.
int Rand(struct RandomState *state)
void InitRandFullGmm(int32 dim, int32 num_comp, FullGmm *gmm)
A class representing a vector.
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void TestIvectorExtractorStatsIO(IvectorExtractorStats &stats)
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
void TestIvectorExtraction(const IvectorExtractor &extractor, const MatrixBase< BaseFloat > &feats, const FullGmm &fgmm)