27 size_t dim = 1 +
Rand() % 20;
28 size_t nGauss = 1 +
Rand() % 10;
29 std::vector< GaussClusterable * > v(nGauss);
30 for (
size_t i = 0;
i < nGauss;
i++) {
33 for (
size_t i = 0;
i < nGauss;
i++) {
34 size_t nPoints = 1 +
Rand() % 30;
35 for (
size_t j = 0;
j < nPoints;
j++) {
38 for (
size_t k = 0;k < dim;k++) vec(k) =
RandGauss();
39 v[
i]->AddStats(vec, post);
42 for (
size_t i = 0;
i+1 < nGauss;
i++) {
43 BaseFloat like_before = (v[
i]->Objf() + v[
i+1]->Objf()) / (v[
i]->Normalizer() + v[
i+1]->Normalizer());
47 std::cout <<
"Like_before = " << like_before <<
", after = "<<like_after <<
" over "<<tmp->
Normalizer()<<
" frames.\n";
52 for (
size_t i = 0;
i < nGauss;
i++)
57 std::set<int32> phones_set;
58 for (
size_t i = 1;
i <= 20;
i++) phones_set.insert(1 +
Rand() % 30);
59 std::vector<int32> phones;
61 std::vector<int32> phone2num_classes(1 + *std::max_element(phones.begin(), phones.end()));
62 for (
size_t i = 0;
i < phones.size();
i++)
63 phone2num_classes[phones[
i]] = 3;
67 std::vector<std::vector<std::pair<int32, int32> > > pdf_info;
68 cd->
GetPdfInfo(phones, phone2num_classes, &pdf_info);
70 pdf_info[
Rand() % pdf_info.size()].size() == 1);
75 bool binary = (
Rand()%2 == 0);
76 size_t num_phones = 1 +
Rand() % 10;
77 std::set<int32> phones_set;
78 while (phones_set.size() < num_phones) phones_set.insert(
Rand() % (num_phones + 5));
79 std::vector<int32> phones;
81 bool ensure_all_covered = (
Rand() % 2 == 0);
82 std::vector<int32> phone2num_pdf_classes;
85 &phone2num_pdf_classes);
87 const char *filename =
"tmpf";
89 Output ko(filename, binary);
90 std::ostream &outfile = ko.
Stream();
92 std::vector<std::vector<std::pair<int32, int32> > > pdf_info;
93 dep->
GetPdfInfo(phones, phone2num_pdf_classes, &pdf_info);
94 std::vector<bool> all_phones(phones.back()+1,
false);
95 for (
size_t i = 0;
i < pdf_info.size();
i++) {
97 for (
size_t j = 0;
j < pdf_info[
i].size();
j++) {
98 int32 idx = pdf_info[
i][
j].first;
99 KALDI_ASSERT(static_cast<size_t>(idx) < all_phones.size());
100 all_phones[pdf_info[
i][
j].first] =
true;
103 if (ensure_all_covered)
104 for (
size_t k = 0; k < phones.size(); k++)
KALDI_ASSERT(all_phones[phones[k]]);
107 dep->
Write(outfile, binary);
112 Input ki(filename, &binary_in);
113 std::istream &infile = ki.
Stream();
115 dep2.
Read(infile, binary_in);
117 std::ostringstream ostr1, ostr2;
118 dep->
Write(ostr1,
false);
119 dep2.
Write(ostr2,
false);
127 std::cout <<
"Note: any \"serious error\" warnings preceding this line are OK.\n";
133 for (
size_t i = 0;
i < 10;
i++) {
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
virtual void GetPdfInfo(const std::vector< int32 > &phones, const std::vector< int32 > &num_pdf_classes, std::vector< std::vector< std::pair< int32, int32 > > > *pdf_info) const
GetPdfInfo returns a vector indexed by pdf-id, saying for each pdf which pairs of (phone...
void CopySetToVector(const std::set< T > &s, std::vector< T > *v)
Copies the elements of a set to a vector.
virtual void Add(const Clusterable &other)=0
Add other stats.
virtual BaseFloat Objf() const =0
Return the objective function associated with the stats [assuming ML estimation]. ...
ContextDependency * MonophoneContextDependency(const std::vector< int32 > &phones, const std::vector< int32 > &phone2num_pdf_classes)
float RandGauss(struct RandomState *state=NULL)
virtual Clusterable * Copy() const =0
Return a copy of this object.
void Write(std::ostream &os, bool binary) const
void TestMonophoneContextDependency()
int Rand(struct RandomState *state)
virtual BaseFloat Normalizer() const =0
Return the normalizer (typically, count) associated with the stats.
A class representing a vector.
void Read(std::istream &is, bool binary)
Read context-dependency object from disk; throws on error.
#define KALDI_ASSERT(cond)
ContextDependency * GenRandContextDependency(const std::vector< int32 > &phone_ids, bool ensure_all_covered, std::vector< int32 > *hmm_lengths)
GenRandContextDependency is mainly of use for debugging.
GaussClusterable wraps Gaussian statistics in a form accessible to generic clustering algorithms...
void TestGenRandContextDependency()