23 using namespace kaldi;
29 std::cout <<
"Testing I/O, binary = " << binary <<
'\n';
31 regtree.
Write(
Output(
"tmp_regtree", binary).Stream(),
37 Input ki(
"tmp_regtree", &binary_in);
41 std::ostringstream s1, s2;
42 regtree.
Write(s1,
false);
43 regtree2.
Write(s2,
false);
46 unlink(
"tmp_regtree");
66 for (
size_t m = 0; m < num_comp; m++) {
68 for (
size_t d= 0;
d < dim;
d++) {
72 tot_weight += weights(m);
74 weights.
Scale(1.0/tot_weight);
93 std::cout <<
"Running test with " << num_comp <<
" components and " 94 << dim <<
" dimensional vectors" <<
'\n';
98 gmm1.
Resize(num_comp, dim);
105 for (
int32 c = 0; c < static_cast<int32>(num_comp); c++) {
108 tmp_vec.
Set(0.001 * means2.
Row(c).Max());
109 means2.
Row(c).AddVec(1.0, tmp_vec);
124 for (
int32 i = 0; i < static_cast<int32>(num_pdfs);
i++) {
125 occs(
i) = 1.0/
static_cast<BaseFloat>(num_pdfs*num_comp);
130 tmp_vec.
Write(std::cout,
false);
132 tmp_vec.
Write(std::cout,
false);
136 std::vector<int32> sil_pdfs;
138 sil_pdfs.push_back(
Rand() % 2);
139 regtree.
BuildTree(occs, sil_pdfs, acmodel, 2);
142 test_io(regtree, acmodel,
false);
149 for (
int i = 0;
i < 4;
i++)
151 std::cout <<
"Test OK.\n";
void Read(std::istream &in, bool binary, const AmDiagGmm &am)
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.
void CopyFromDiagGmm(const DiagGmm &diaggmm)
Copies from given DiagGmm.
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 Write(std::ostream &Out, bool binary) const
Writes to C++ stream (option to write in binary).
void rand_diag_gmm(size_t num_comp, size_t dim, DiagGmm *gmm)
void GetComponentMean(int32 gauss, VectorBase< Real > *out) const
Accessor for single component mean.
void Resize(int32 nMix, int32 dim)
Resizes arrays to this dim. Does not initialize data.
int32 ComputeGconsts()
Sets the gconsts.
float RandGauss(struct RandomState *state=NULL)
void SetMeans(const MatrixBase< Real > &m)
Use SetMeans to update only the Gaussian means (and not variances)
void Write(std::ostream &out, bool binary) const
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
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 test_io(const RegressionTree ®tree, const AmDiagGmm &acmodel, bool binary)
void GetMeans(Matrix< Real > *m) const
Accessor for means.
int32 NumGauss() const
Returns the number of mixture components in the GMM.
void Scale(Real alpha)
Multiplies all elements by this constant.
int Rand(struct RandomState *state)
void InvertElements()
Inverts all the elements of the matrix.
A class representing a vector.
#define KALDI_ASSERT(cond)
void Set(Real f)
Set all members of a vector to a specified value.
Definition for Gaussian Mixture Model with diagonal covariances.
void SetWeights(const VectorBase< Real > &w)
Mutators for both float or double.
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
void UnitTestRegressionTree()