📄 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.2 [CUED 09/12/02] */#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 1277 /* 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.5 /* log(MINMIX) */#define MINDLOGP 0.000001 /* prob = exp(shortform/DLOGSCALE) */#define DLOGSCALE -2371.8 /* = 32767/ln(MINDLOGP) */#define DLOGZERO 32767 #define MixWeight(hset,weight) (weight)#define MixLogWeight(hset,weight) (weight<MINMIX ? LZERO : log(weight))#define MixFloor(hset) ( MINMIX )/* ------------------ 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};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) */ short rClass; /* regression base class number (zero if unused) */ int mIdx; /* MixPDF index */ int nUse; /* usage counter */ 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;/* ---------------------- Input Transform ------------------- */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 { 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 */} HMMSet;/* --------------------------- Initialisation ---------------------- */void InitModel(void);/* Initialise the module*//* ---------------- Macro Related Manipulations -------------------- */void QuantiseObservation(HMMSet *hset, Observation *obs, int frame);MLink NewMacro(HMMSet *hset, short fidx, char type, LabId id, Ptr structure);/* Create a new macro definition for given HMM set with given values and insert it into the associated macro table. Return a pointer to it.*/void DeleteMacro(HMMSet *hset, MLink p);void DeleteMacroStruct(HMMSet *hset, char type, Ptr structure);/* Mark macro definition [for given structure] as deleted (ie type='*')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -