DiagGmmNormal Class Reference

Definition for Gaussian Mixture Model with diagonal covariances in normal mode: where the parameters are stored as means and variances (instead of the exponential form that the DiagGmm class is stored as). More...

#include <diag-gmm-normal.h>

Collaboration diagram for DiagGmmNormal:

Public Member Functions

 DiagGmmNormal ()
 Empty constructor. More...
 
 DiagGmmNormal (const DiagGmm &gmm)
 
void Resize (int32 nMix, int32 dim)
 Resizes arrays to this dim. Does not initialize data. More...
 
void CopyFromDiagGmm (const DiagGmm &diaggmm)
 Copies from given DiagGmm. More...
 
void CopyToDiagGmm (DiagGmm *diaggmm, GmmFlagsType flags=kGmmAll) const
 Copies to DiagGmm the requested parameters. More...
 
int32 NumGauss ()
 
int32 Dim ()
 
 KALDI_DISALLOW_COPY_AND_ASSIGN (DiagGmmNormal)
 

Public Attributes

Vector< double > weights_
 weights (not log). More...
 
Matrix< double > means_
 Means. More...
 
Matrix< double > vars_
 diagonal variance More...
 

Detailed Description

Definition for Gaussian Mixture Model with diagonal covariances in normal mode: where the parameters are stored as means and variances (instead of the exponential form that the DiagGmm class is stored as).

This class will be used in the update (since the update formulas are for the standard parameterization) and then copied to the exponential form of the DiagGmm class. The DiagGmmNormal class will not be used anywhere else, and should not have any extra methods that are not needed.

Definition at line 45 of file diag-gmm-normal.h.

Constructor & Destructor Documentation

◆ DiagGmmNormal() [1/2]

DiagGmmNormal ( )
inline

Empty constructor.

Definition at line 48 of file diag-gmm-normal.h.

48 { }

◆ DiagGmmNormal() [2/2]

DiagGmmNormal ( const DiagGmm gmm)
inlineexplicit

Definition at line 50 of file diag-gmm-normal.h.

References DiagGmmNormal::CopyFromDiagGmm(), DiagGmmNormal::CopyToDiagGmm(), kaldi::kGmmAll, and DiagGmmNormal::Resize().

50  {
51  CopyFromDiagGmm(gmm);
52  }
void CopyFromDiagGmm(const DiagGmm &diaggmm)
Copies from given DiagGmm.

Member Function Documentation

◆ CopyFromDiagGmm()

void CopyFromDiagGmm ( const DiagGmm diaggmm)

Copies from given DiagGmm.

Definition at line 46 of file diag-gmm-normal.cc.

References MatrixBase< Real >::CopyFromMat(), VectorBase< Real >::CopyFromVec(), DiagGmm::Dim(), DiagGmm::inv_vars_, MatrixBase< Real >::InvertElements(), DiagGmmNormal::means_, DiagGmm::means_invvars_, MatrixBase< Real >::MulElements(), DiagGmmNormal::Resize(), DiagGmmNormal::vars_, DiagGmmNormal::weights_, and DiagGmm::weights_.

Referenced by DiagGmmNormal::DiagGmmNormal(), kaldi::UpdateEbwDiagGmm(), and kaldi::UpdateEbwWeightsDiagGmm().

46  {
47  int32 num_comp = diaggmm.weights_.Dim(), dim = diaggmm.Dim();
48  Resize(num_comp, dim);
49 
50  weights_.CopyFromVec(diaggmm.weights_);
51  vars_.CopyFromMat(diaggmm.inv_vars_);
53  means_.CopyFromMat(diaggmm.means_invvars_);
55 }
void Resize(int32 nMix, int32 dim)
Resizes arrays to this dim. Does not initialize data.
kaldi::int32 int32
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
Matrix< double > vars_
diagonal variance
void MulElements(const MatrixBase< Real > &A)
Element by element multiplication with a given matrix.
Matrix< double > means_
Means.
void InvertElements()
Inverts all the elements of the matrix.
Vector< double > weights_
weights (not log).

◆ CopyToDiagGmm()

void CopyToDiagGmm ( DiagGmm diaggmm,
GmmFlagsType  flags = kGmmAll 
) const

Copies to DiagGmm the requested parameters.

Definition at line 57 of file diag-gmm-normal.cc.

References MatrixBase< Real >::CopyFromMat(), VectorBase< Real >::Dim(), DiagGmm::Dim(), DiagGmm::inv_vars_, MatrixBase< Real >::InvertElements(), KALDI_ASSERT, kaldi::kGmmMeans, kaldi::kGmmVariances, kaldi::kGmmWeights, DiagGmmNormal::means_, DiagGmm::means_invvars_, MatrixBase< Real >::MulElements(), MatrixBase< Real >::NumCols(), DiagGmm::valid_gconsts_, DiagGmmNormal::vars_, DiagGmmNormal::weights_, and DiagGmm::weights_.

Referenced by DiagGmm::CopyFromNormal(), DiagGmmNormal::DiagGmmNormal(), kaldi::DoRescalingUpdate(), kaldi::MapDiagGmmUpdate(), kaldi::MleDiagGmmUpdate(), UnitTestEstimateDiagGmm(), kaldi::UpdateEbwDiagGmm(), and kaldi::UpdateEbwWeightsDiagGmm().

57  {
58  KALDI_ASSERT((static_cast<int32>(diaggmm->Dim()) == means_.NumCols())
59  && (static_cast<int32>(diaggmm->weights_.Dim()) == weights_.Dim()));
60 
61  DiagGmmNormal oldg(*diaggmm);
62 
63  if (flags & kGmmWeights)
64  diaggmm->weights_.CopyFromVec(weights_);
65 
66  if (flags & kGmmVariances) {
67  diaggmm->inv_vars_.CopyFromMat(vars_);
68  diaggmm->inv_vars_.InvertElements();
69 
70  // update the mean related natural part with the old mean, if necessary
71  if (!(flags & kGmmMeans)) {
72  diaggmm->means_invvars_.CopyFromMat(oldg.means_);
73  diaggmm->means_invvars_.MulElements(diaggmm->inv_vars_);
74  }
75  }
76 
77  if (flags & kGmmMeans) {
78  diaggmm->means_invvars_.CopyFromMat(means_);
79  diaggmm->means_invvars_.MulElements(diaggmm->inv_vars_);
80  }
81 
82  diaggmm->valid_gconsts_ = false;
83 }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
Matrix< double > vars_
diagonal variance
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
Matrix< double > means_
Means.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Vector< double > weights_
weights (not log).
DiagGmmNormal()
Empty constructor.

◆ Dim()

int32 Dim ( )
inline

Definition at line 64 of file diag-gmm-normal.h.

References DiagGmmNormal::means_, and MatrixBase< Real >::NumCols().

64 { return means_.NumCols(); }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
Matrix< double > means_
Means.

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( DiagGmmNormal  )

◆ NumGauss()

int32 NumGauss ( )
inline

Definition at line 63 of file diag-gmm-normal.h.

References VectorBase< Real >::Dim(), and DiagGmmNormal::weights_.

Referenced by Fmpe::ComputeC().

63 { return weights_.Dim(); }
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
Vector< double > weights_
weights (not log).

◆ Resize()

void Resize ( int32  nMix,
int32  dim 
)

Resizes arrays to this dim. Does not initialize data.

Definition at line 31 of file diag-gmm-normal.cc.

References VectorBase< Real >::Dim(), KALDI_ASSERT, DiagGmmNormal::means_, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), Vector< Real >::Resize(), Matrix< Real >::Resize(), DiagGmmNormal::vars_, and DiagGmmNormal::weights_.

Referenced by DiagGmmNormal::CopyFromDiagGmm(), and DiagGmmNormal::DiagGmmNormal().

31  {
32  KALDI_ASSERT(nmix > 0 && dim > 0);
33 
34  if (weights_.Dim() != nmix)
35  weights_.Resize(nmix);
36 
37  if (vars_.NumRows() != nmix ||
38  vars_.NumCols() != dim)
39  vars_.Resize(nmix, dim);
40 
41  if (means_.NumRows() != nmix ||
42  means_.NumCols() != dim)
43  means_.Resize(nmix, dim);
44 }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
Matrix< double > vars_
diagonal variance
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
Matrix< double > means_
Means.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
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).
Vector< double > weights_
weights (not log).

Member Data Documentation

◆ means_

◆ vars_

◆ weights_


The documentation for this class was generated from the following files: