00001 00002 // $Id: gmm_util.H,v 1.12 2009/10/02 00:31:58 stanchen Exp $ 00003 00004 /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** 00005 * @file gmm_util.H 00006 * @brief Miscellaneous routines for manipulating GmmSet's. 00007 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00008 00009 #ifndef _GMM_UTIL_H 00010 #define _GMM_UTIL_H 00011 00012 00013 #include "util.H" 00014 00015 00016 /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** 00017 * GMM statistics for reestimating a GmmSet. 00018 * 00019 * This object stores and updates the statistics required for reestimating 00020 * a set of GMM's. The method #reestimate() reestimates the 00021 * associated GmmSet. 00022 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00023 class GmmStats 00024 { 00025 public: 00026 /** Ctor; @p gmmSet is the object to reestimate and @p params 00027 * holds parameters controlling how reestimation is done. 00028 **/ 00029 GmmStats(GmmSet& gmmSet, const map<string, string>& params = 00030 ParamsType()); 00031 00032 /** Resets all counts to 0. **/ 00033 void clear(); 00034 00035 /** Updates stats for the @p gmmIdx-th GMM. 00036 * The value @p posterior should be the posterior prob/count 00037 * of this GMM, and @p feats should be the acoustic 00038 * feature vector for the current frame. 00039 * Returns log prob base e of GMM for that feature vector. 00040 * GMM's are numbered starting from 0. 00041 **/ 00042 double add_gmm_count(unsigned gmmIdx, double posterior, 00043 const vector<double>& feats); 00044 00045 /** Update stats for all GMM counts in @p gmmCountList given 00046 * that @p feats holds the feature vectors for the whole utterance. 00047 * Returns the sum of the log probs base e of each GMM in the 00048 * list for its corresponding frame; this value will only be 00049 * meaningful in a Viterbi-style update. 00050 **/ 00051 double update(const vector<GmmCount>& gmmCountList, 00052 const matrix<double>& feats); 00053 00054 /** Reestimates GmmSet provided in ctor using current stats. **/ 00055 void reestimate() const; 00056 00057 private: 00058 /** Updates stats for the @p compIdx-th component of the 00059 * @p gmmIdx-th GMM. 00060 * The value @p posterior should be the posterior prob/count 00061 * of this component, and @p feats should be the acoustic 00062 * feature vector for the current frame. 00063 * GMM's and components are numbered starting from 0. 00064 **/ 00065 void add_component_count(unsigned gmmIdx, unsigned compIdx, 00066 double posterior, const vector<double>& feats); 00067 00068 private: 00069 /** Stores copy of input parameters. **/ 00070 map<string, string> m_params; 00071 00072 /** Reference to associated GmmSet. **/ 00073 GmmSet& m_gmmSet; 00074 00075 /** For each GMM, index of first component in m_compCounts. **/ 00076 vector<unsigned> m_gmmMap; 00077 00078 /** Total counts of each mixture component. **/ 00079 vector<double> m_compCounts; 00080 00081 /** Total counts of each Gaussian. **/ 00082 vector<double> m_gaussCounts; 00083 00084 /** First and second-order stats for each dim of each Gaussian. **/ 00085 matrix<double> m_gaussStats; 00086 }; 00087 00088 00089 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00090 * 00091 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00092 00093 /** Initializes @p gmmSet to contain @p gmmCnt GMM's of dimension @p dimCnt. 00094 * Each GMM is taken to have a single component Gaussian 00095 * with mean 0 and variance 1 for each dimension. 00096 **/ 00097 void init_simple_gmms(GmmSet& gmmSet, unsigned gmmCnt, unsigned dimCnt); 00098 00099 /** Splits each Gaussian in each GMM in @p srcGmmSet in two along the 00100 * direction of the variance, and places result in @p dstGmmSet. 00101 * Divides mixture weight of each Gaussian component in two as well. 00102 * Number of standard 00103 * deviations to perturb the mean in each dimension is determined 00104 * by @p perturb parameter in @p params. The @p min_perturb parameter 00105 * in @p params controls the minimum distance to perturb each mean. 00106 * Handles case where Gaussians are shared between GMM's correctly. 00107 **/ 00108 void split_gmms(const GmmSet& srcGmmSet, GmmSet& dstGmmSet, 00109 const map<string, string>& params = ParamsType()); 00110 00111 /** Duplicates each (context-independent) GMM in @p srcGmmSet for each of its 00112 * (context-dependent) variants and places result in @p dstGmmSet. 00113 * The vector @p phoneGmmCounts holds 00114 * the number of times to duplicate each source GMM. 00115 * If Gaussians are shared between GMM's in input, will no longer be 00116 * shared in output. 00117 **/ 00118 void expand_gmms_ci_to_cd(const GmmSet& srcGmmSet, GmmSet& dstGmmSet, 00119 const vector<int>& phoneGmmCounts); 00120 00121 00122 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00123 * 00124 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00125 00126 #endif 00127 00128