📄 hmodel.h
字号:
/* ----------------------------------------------------------- *//* *//* ___ *//* |_| | |_/ SPEECH *//* | | | | \ RECOGNITION *//* ========= SOFTWARE */ /* *//* *//* ----------------------------------------------------------- *//* developed at: *//* *//* Speech Vision and Robotics group *//* Cambridge University Engineering Department *//* http://svr-www.eng.cam.ac.uk/ *//* *//* Entropic Cambridge Research Laboratory *//* (now part of Microsoft) *//* *//* ----------------------------------------------------------- *//* Copyright: Microsoft Corporation *//* 1995-2000 Redmond, Washington USA *//* http://www.microsoft.com *//* *//* 2002 Cambridge University *//* Engineering Department *//* *//* Use of this software is governed by a License Agreement *//* ** See the file License for the Conditions of Use ** *//* ** This banner notice must not be removed ** *//* *//* ----------------------------------------------------------- *//* File: HModel.h HMM Model Definition Data Type *//* ----------------------------------------------------------- *//* !HVER!HModel: 3.3 [CUED 28/04/05] */#ifndef _HMODEL_H_#define _HMODEL_H_#ifdef __cplusplusextern "C" {#endif/* The following types define the in-memory representation of a HMM. All HMM's belong to a HMMSet which includes a macro table for rapidly mapping macro/hmm names into structures. */#define MACHASHSIZE 250007 /* Size of each HMM Set macro hash table */#define PTRHASHSIZE 513 /* Size of each HMM Set ptr map hash table */#define MINMIX 1.0E-5 /* Min usable mixture weight */#define LMINMIX -11.5129254649702 /* log(MINMIX) */#define MINDLOGP 0.000001 /* prob = exp(shortform/DLOGSCALE) */#define DLOGSCALE -2371.8 /* = 32767/ln(MINDLOGP) */#define DLOGZERO 32767 #define MixFloor(hset) ( MINMIX )#ifdef WIN32#define XFORM HTK_XFORM#endif/* ------------------ Master Model File Info ----------------- */typedef struct _MMFInfo *MILink;typedef struct _MMFInfo{ Boolean isLoaded; /* true if contents are loaded */ char *fName; /* MMF file name */ int fidx; /* MMF file index */ MILink next; /* next external file name in list */} MMFInfo;/* -------------------- HMM Definition ----------------------- */enum _DurKind {NULLD, POISSOND, GAMMAD, RELD, GEND};typedef enum _DurKind DurKind;enum _HSetKind {PLAINHS, SHAREDHS, TIEDHS, DISCRETEHS};/*值从0开始*/typedef enum _HSetKind HSetKind;typedef struct { SVector mean; /* mean vector */ CovKind ckind; /* kind of covariance */ Covariance cov; /* covariance matrix or vector */ float gConst; /* Precomputed component of b(x) */ int mIdx; /* MixPDF index */ int nUse; /* usage counter */ Ptr info; /* hook to hang information from */ Ptr hook; /* general hook */} MixPDF;typedef struct { /* 1 of these per mixture per stream */ float weight; /* mixture weight */ MixPDF *mpdf; /* -> mixture pdf */} MixtureElem;typedef union { /* array[1..numMixtures] of Mixture */ MixtureElem *cpdf; /* PLAINHS or SHAREDHS */ Vector tpdf; /* TIEDHS */ ShortVec dpdf; /* DISCRETE */} MixtureVector; typedef struct{ /* used for tied mixture prob calculations */ short index; /* mixture index */ float prob; /* mixture prob scaled by maxP */}TMProb;typedef struct { /* A Tied Mixture "Codebook" */ LabId mixId; /* id of macro base name */ short nMix; /* num mixtures M in set */ short topM; /* num TMProbs actually used */ MixPDF ** mixes; /* array[1..M] of MixPDF */ LogFloat maxP; /* max log mixture prob */ TMProb *probs; /* array[1..M] of TMProb */} TMixRec;typedef struct { /* 1 of these per stream */ int nMix; /* num mixtures in this stream */ MixtureVector spdf; /* Mixture Vector */ Ptr hook; /* general hook */}StreamElem;typedef struct { SVector weights; /* vector of stream weights */ StreamElem *pdf; /* array[1..numStreams] of StreamElem */ SVector dur; /* vector of state duration params, if any */ int sIdx; /* State index */ int nUse; /* usage counter */ Ptr hook; /* general hook */ int stateCounter; /* # of state occurrences */} StateInfo;typedef struct { /* 1 of these per state */ StateInfo *info; /* information for this state */} StateElem;typedef struct { struct _HMMSet *owner; /* owner of this model */ short numStates; /* includes entry and exit states */ StateElem *svec; /* array[2..numStates-1] of StateElem */ SVector dur; /* vector of model duration params, if any */ SMatrix transP; /* transition matrix (logs) */ int tIdx; /* Transition matrix index */ int nUse; /* num logical hmm's sharing this def */ Ptr hook; /* general hook */} HMMDef;typedef HMMDef * HLink;/* --------------------- Enumerated Types -------------------- */enum _XFormKind {MLLRMEAN, MLLRCOV, MLLRVAR, CMLLR};typedef enum _XFormKind XFormKind;enum _AdaptKind {TREE, BASE};typedef enum _AdaptKind AdaptKind;enum _BaseClassKind {MIXBASE, MEANBASE, COVBASE};typedef enum _BaseClassKind BaseClassKind;/* -------------- Regression Tree Definition ----------------- */typedef struct _ItemRec *ILink;typedef struct _ItemRec { HLink owner; /* HMM owning this item */ Ptr item; /* -> to a HMM structure */ ILink next;}ItemRec;typedef struct { char* mmfIdMask; /* mask of model sets that appropriate for */ BaseClassKind bkind; /* type of parameters applicable to */ IntVec swidth; /* stream width size */ int numClasses; /* number of baseclasses */ ILink *ilist; /* 1..numClasses of ilists */ int nUse; /* usage counter */ char *fname; /* filename of where the baseclass was loaded */} BaseClass;typedef struct _RegNode { float nodeOcc; /* occupancy for this node */ int vsize; /* vector size associated with the baseclasses of this node */ int nodeIndex; /* index number of node */ int numChild; /* number of children - 0 if terminal */ struct _RegNode **child; /* children of this node NULL if terminal */ IntVec baseClasses; /* if a terminal node the set of baseclasses else NULL */ Ptr info; /* hook to hang information from */} RegNode ;typedef struct RegTree { int numNodes; /* number of non-terminal nodes in tree */ int numTNodes; /* number of terminal nodes in tree */ BaseClass *bclass; /* baseclass associated with this regression tree */ RegNode *root; /* pointer to the root node of the tree */ Boolean valid; /* is it valid to generate a transform at the root node */ /* handles multiple stream adaptation issues */ float thresh; /* split threshold to determine stopping in tree */ char *fname; /* filename of where the regTree was loaded */} RegTree; /* ----------------- Transform Definition -------------------- */typedef struct { /* occupancy is always used */ Boolean accSum; /* accumulate the sum of the observations */ Boolean accSumSq; /* accumulate sum-squared (diag) of the observations */ Boolean accBTriMat; /* accumulate weighted outer-product of observations */ RegTree regTree; /* the regression tree used for transform */} XFormAccInfo;typedef union { Matrix wgt; /* for interpolated transforms */ IntVec assign; /* for hard assignments */} AdaptWgt; typedef struct { int vecSize; /* must be matched to a stream width! */ IntVec blockSize; /* block sizes in the linear transform */ SMatrix* xform; /* 1..numBlocks matrix transforms */ SVector bias; /* bias vector, if no bias equals NULL */ float det; /* determinant of linxform */ int nUse; /* usage counter */} LinXForm;typedef struct { int numXForms; /* number of transforms in this xformset */ XFormKind xkind; /* transform kind (MLLRMEAN, CMLLR etc */ LinXForm **xforms; /* 1..numTrans linear transforms */ int nUse; /* usage counter */} XFormSet;typedef struct _AdaptXForm { char* xformName; /* name of the transform (macroname) */ char *fname; /* filename of where the xform was loaded */ struct _AdaptXForm *swapXForm; /* has this transform been swapped with parent */ MemHeap *mem; /* heap used for storing transform */ AdaptKind akind; /* adaptation kind */ BaseClass *bclass; /* base class for which transform applicable */ RegTree *rtree; /* regression tree to be used for adaptation */ int nUse; /* usage counter */ XFormAccInfo *info; /* information abbout the accumulates for this transform */ struct _AdaptXForm *parentXForm; /* parent transform, NULL if no parent parenttransform */ XFormSet *xformSet; /* set of linear transforms */ AdaptWgt xformWgts; /* set of weights for all the base classes */ struct _HMMSet *hset; /* transform is linked with a model set */} AdaptXForm;typedef struct { char* xformName; /* name of the transform (macroname) */ char* mmfIdMask; /* mask of model sets that appropriate for */ char *fname; /* filename of where the input xform was loaded */ ParmKind pkind; /* parameter kind for xform to be applied to */ Boolean preQual; /* is this applied prior to qualifiers? */ LinXForm *xform; /* actual transform to be applied */ int nUse; /* usage counter */} InputXForm;/* ---------------------- Macros/HMM Hashing ------------------- *//* Every macro, logical HMM defn and physical HMM defn has an entry in a macro table. The macro types are: l logHMM u mean v variance i invcovar p pdf h phyHMM d duration t transP m mixpdf s state x xform w strm wts o options c lltcovar * deleted r regtree a HMMDef will have exactly 1 phyHMM macro referencing it but it can have 0 or more logHMM macros referencing it.*/typedef struct _MacroDef *MLink;typedef struct _MacroDef{ MLink next; /* next cell in hash table */ char type; /* type of macro [hluvixdtmps*] */ short fidx; /* idx of MMF file (0 = SMF) */ LabId id; /* name of macro */ Ptr structure; /* -> shared structure or HMM Def */} MacroDef;typedef struct _PtrMap { /* used for finding macros via ptr's */ struct _PtrMap *next; /* next cell in hash table */ Ptr ptr; /* the structure */ MLink m; /* macro def for this structure */} PtrMap;/* ---------------------- HMM Sets ----------------------------- */typedef struct _HMMSet{ MemHeap *hmem; /* memory heap for this HMM Set */ Boolean *firstElem; /* first element added to hmem during MakeHMMSet*/ char *hmmSetId; /* identifier for the hmm set */ MILink mmfNames; /* List of external file names */ int numLogHMM; /* Num of logical HMM's */ int numPhyHMM; /* Num of distinct physical HMM's */ int numFiles; /* total number of ext files */ int numMacros; /* num macros used in this set */ MLink * mtab; /* Array[0..MACHASHSIZE-1]OF MLink */ PtrMap ** pmap; /* Array[0..PTRHASHSIZE-1]OF PtrMap* */ Boolean allowTMods; /* true if HMMs can have Tee Models */ Boolean optSet; /* true if global options have been set */ short vecSize; /* dimension of observation vectors */ short swidth[SMAX]; /* [0]=num streams,[i]=width of stream i */ ParmKind pkind; /* kind of obs vector components */ DurKind dkind; /* kind of duration model (model or state) */ CovKind ckind; /* cov kind - only global in V1.X */ HSetKind hsKind; /* kind of HMM set */ TMixRec tmRecs[SMAX]; /* array[1..S]of tied mixture record */ int numStates; /* Number of states in HMMSet */ int numSharedStates; /* Number of shared states in HMMSet */ int numMix; /* Number of mixture components in HMMSet */ int numSharedMix; /* Number of shared mixtures in HMMSet */ int numTransP; /* Number of distinct transition matrices */ int ckUsage[NUMCKIND]; /* Number of components using given ckind */ InputXForm *xf; /* Input transform of HMMSet */ /* Adaptation information accumulates */ Boolean attRegAccs; /* have the set of accumulates been attached */ Boolean attXFormInfo; /* have the set of adapt info been attached */ Boolean attMInfo; /* have the set of adapt info been attached */ AdaptXForm *curXForm; AdaptXForm *parentXForm; /* Added to support LogWgts */ Boolean logWt; /* Component weights are stored as Logs */} HMMSet;/* --------------------------- Initialisation ---------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -